はじめに
とりあえずやってみた。
Mac多すぎ問題。
Ubuntuいいよね。
ちなワイ氏、MacBook ProにUbuntu入れてる勢。
Macは見た目かっこいいから買っただけ(5年目)。
Surface Book2ほしい。
15分でできるLaravel環境構築やっていくで。
qiita.com
docker入れる
まずはそもそものところから。
上記の環境構築はすでにdocker等のインストールが終わってる前提になってるのでまずはdocker入れておく。
入れないでやっていくと以下のエラーで怒られる。
ERROR: Couldn't connect to Docker daemon. You might need to install Docker:
基本は以下の記事を参考にやっていく。
qiita.com
sudo apt-get update
Hit:1 https://deb.nodesource.com/node_10.x xenial InRelease
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease [23.9 kB]
Hit:4 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:5 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Ign:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease
Hit:6 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
Fetched 23.9 kB in 1s (16.1 kB/s)
Reading package lists... Done
W: GPG error: http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4F4EA0AAE5267A6C
W: The repository 'http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
こんなん言われたら以下やっとく。
co.bsnws.net
docker-compose入れる
docs.docker.com
まずこれ入れる。
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
laradock入れる
次にこれ入れる。
git clone https://github.com/laradock/laradock.git
warning: unable to access '/home/vagrant/.config/git/attributes': Permission denied
こうやって怒られたら以下を実行する。
多分ワイだけだと思うけど。
sudo chown -R $(whoami) ~/.config
実行権限を与える。
sudo chmod +x /usr/local/bin/docker-compose
nginxを起動する
続いてこれやる。
docker-compose up -d nginx
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
これでたらsudoつけて実行する。
Recreating laradock_nginx_1 ... error
ERROR: for laradock_nginx_1 Cannot start service nginx: driver failed programming external connectivity on endpoint laradock_nginx_1 (da38cc5608cf47384f0fd9a8c42b78b34eb8113cae80e05c1e783e8e2fc37ad9): Error starting userland proxy: listen tcp 0.0.0.0:443: bind: address already in use
↑こうなったらローカルでインストールしているnginxが起動中で同じポート使おうとしているから衝突しないよう以下を実行する。
sudo systemctl stop nginx
くっそ起動長い。
5分は優にやってたと思われる(ネットワークの問題もあるかもしれないけどw)。
Laravelの環境を起動する
composer create-project laravel/laravel app01
swapファイルが云々言われる。
akamist.com
この辺頑張ったが無理だったので、そもそも仮想環境へのメモリの割り当てが少ないのかと自力で考え抜く(一通りググってもダメだったので(ここまで15分))。
config.vm.provider "virtualbox" do |vb|
# vb.cpus = 1
vb.memory = 2048
end
これでうまくいった。
vagrantのUbuntu環境なので config.vm.network "private_network", ip: "192.168.33.10"
の部分がゲストのURLとなる。
Railsのプロジェクトのデフォルトポートは3000だけど、この環境は80番。
localhostのところを 192.168.33.10
にすればOK。
あとは docker-compose exec workspace bash
でdocker環境にログインしてプロジェクトをクローンすれば環境構築完了。
docker-compose exec workspace bash
composer install
最後の最後で以下のエラーに出くわした。
katsu-tech.hatenablog.com
Vagrantfileのディスク容量をdefaultの10GBから100GBに変更したらうまくいった。
これで1時間も調べたわ。
こんなエラー出た。
vagrant@ubuntu-xenial:~/tmp/laradock$ sudo docker-compose up -d nginx mysql phpmyadmin redis workspace
laradock_docker-in-docker_1 is up-to-date
laradock_redis_1 is up-to-date
Starting laradock_mysql_1 ...
laradock_workspace_1 is up-to-date
laradock_php-fpm_1 is up-to-date
Starting laradock_mysql_1 ... error
ERROR: for laradock_mysql_1 Cannot start service mysql: driver failed programming external connectivity on endpoint laradock_mysql_1 (e1e80cbae0f0fd49e14d75830a0e58845c073bee261c7b0dcacae845c4da1581): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use
ERROR: for mysql Cannot start service mysql: driver failed programming external connectivity on endpoint laradock_mysql_1 (e1e80cbae0f0fd49e14d75830a0e58845c073bee261c7b0dcacae845c4da1581): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use
ERROR: Encountered errors while bringing up the project.
stackoverflow.com
dockerのmysqlとローカルにインストールしてるmysqlで同じポート使用しようとしていたのでローカルのmysqlのデーモン(プロセス)を停止した。
root@eedbed7757b6:/var/www/project_name# php artisan migrate
In Connection.php line 664:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = project_name_dev and table_name = migrations)
In Connector.php line 67:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
In Connector.php line 67:
PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]
上記のエラーになったら以下を実行。
blog.janjan.net
No application encryption key has been specified.エラー
qiita.com
npm install --no-optionalでLaravel Mixをインストール
以下のエラーが出る。
⚠ The `/var/www/project_name/node_modules/mozjpeg/vendor/cjpeg` binary doesn't seem to work correctly
⚠ mozjpeg pre-build test failed
ℹ compiling from source
✖ Error: autoreconf -fiv && ./configure --disable-shared --disable-dependency-tracking --with-jpeg8 --prefix="/var/www/project_name/node_modules/mozjpeg/vendor" --bindir="/var/www/project_name/node_modules/mozjpeg/vendor" --libdir="/var/www/project_name/node_modules/mozjpeg/vendor" && make -j2 && make install -j2
Command failed: ./configure --disable-shared --disable-dependency-tracking --with-jpeg8 --prefix="/var/www/project_name/node_modules/mozjpeg/vendor" --bindir="/var/www/project_name/node_modules/mozjpeg/vendor" --libdir="/var/www/project_name/node_modules/mozjpeg/vendor"
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
cat: -: No such file or directory
configure: error: in `/var/www/project_name/node_modules/mozjpeg/50dc72fd-d56a-4687-b290-d92490e310cf':
configure: error: C compiler cannot create executables
See `config.log' for more details
at ChildProcess.exithandler (child_process.js:297:12)
at ChildProcess.emit (events.js:193:13)
at maybeClose (internal/child_process.js:1001:16)
at Socket.stream.socket.on (internal/child_process.js:405:11)
at Socket.emit (events.js:193:13)
at Pipe._handle.close (net.js:614:12)
以下のエントリーを参考にする。
github.com
sudo apt-get install libpng16-dev
自分の環境だと sudo
は不要だった。
以下のエラーが出た。
以下のエントリーを参考にする。
teratail.com
npm install --save-dev cross-env
補足
dockerコマンドに毎回sudoを使わなくてもよくする方法。
sudo usermod -aG docker your-user
まとめ
余裕で2時間とかかかったわ。
多分Vagrantのメモリ設定をはじめから4Gとかにすればもっと早く終わったと思う。
あと超低速のレンタルWi-Fiのせい。
でも割と苦戦せず環境構築できた。
これからPHPやLaravelも頑張ります。
参考にした
laradock.io
qiita.com
qiita.com
追記
bladeってなに?
HTMLのテンプレートエンジン。
laraweb.net
.bladeファイルではphp(Laravel)のコードが実行できるようになる。
Railsで言うところのslimやhamlのようにより楽にhtmlを記述するにはpugを利用する?
時間操作について
PHP標準のDateTimeクラスを拡張して時間を楽に操作できるようにしてくれるCarbonクラスがある。