ubuntu 18.04環境にLaravel 6 をインストールします。
nginx
過去記事を参照してください。
PHP
$ sudo apt-add-repository ppa:ondrej/php
$ sudo apt update
$ sudo apt install php7.4 \
php7.4-bcmath \
php7.4-common \
php7.4-curl \
php7.4-dev \
php7.4-fpm \
php7.4-json \
php7.4-mbstring \
php7.4-mysql \
php7.4-xml \
php7.4-zip
PHP-FPM
nginxの実行ユーザーに合わせて。ユーザー、グループを www-data
→ nginx
に変更します。
/etc/php/7.4/fpm/pool.d/www.conf
user = nginx
group = nginx
# 中略
listen.owner = nginx
listen.group = nginx
confを変更したら、サービスを再起動します。
$ sudo systemctl restart php7.4-fpm
composer インストール
過去記事を参照してください。
Laravel インストール
アプリケーション名は my-app
としています。
$ composer create-project --prefer-dist laravel/laravel my-app "6.*"
ディレクトリ権限
my-app/storage
下と my-app/bootstrap/cache
ディレクトリを nginx
グループにします。
$ cd my-app
$ find storage/ -type d | xargs sudo chgrp nginx
$ find storage/ -type d | xargs sudo chmod g+s
$ find storage/ -type d | xargs setfacl -d -m g::rwx
$ sudo chgrp nginx bootstrap/cache
$ sudo chmod g+s bootstrap/cache
$ setfacl -d -m g::rwx bootstrap/cache
ディレクトリのみを対象に処理させたいので、 再帰的に変更するオプション(-R)は使ってません。なお、ユーザーを nginx
グループに追加していない場合は追加しておきます。
$ sudo usermod -aG nginx $USER
nginxのconf
/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name local.tdomy.com;
charset UTF-8;
access_log /var/log/nginx/tdomy.access.log main;
location / {
root /var/www/my-app/public;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /var/www/my-app/public;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
confを編集したら、nginxを再起動して確認します。
$ sudo systemctl restart nginx

画面が表示されたら完了です!