linux mint 22 に nginx

(2026-01-14)

Apache を停止・無効化

sudo systemctl stop apache2
sudo systemctl disable apache2
sudo systemctl status apache2

nginx インストール

sudo apt update
sudo apt install nginx -y

バージョン確認

nginx -v

nginx 起動・有効化

sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx

ブラウザで確認

http://localhost

権限確認(重要)

sudo chmod 755 /home/自分のユーザー名

サイト設定ファイルの作成

sudo nano /etc/nginx/sites-available/family-album

以下のように編集。

server {
listen 80;
server_name localhost;
root /home/moheno/family-album/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}

サイト有効化

sudo ln -s /etc/nginx/sites-available/family-album /etc/nginx/sites-enabled/

デフォルトサイトを無効化して競合を避ける場合:

sudo rm /etc/nginx/sites-enabled/default

設定テスト & nginx 再起動

sudo nginx -t
sudo systemctl restart nginx

Laravel 用権限調整

sudo chown -R moheno:www-data /home/moheno/family-album
sudo chmod -R 755 /home/moheno/family-album
sudo chmod -R 775 /home/moheno/family-album/storage /home/moheno/family-album/bootstrap/cache