Apache を停止・無効化
sudo systemctl stop apache2sudo systemctl disable apache2sudo systemctl status apache2nginx インストール
sudo apt updatesudo apt install nginx -yバージョン確認
nginx -vnginx 起動・有効化
sudo systemctl start nginxsudo systemctl enable nginxsudo systemctl status nginxブラウザで確認
権限確認(重要)
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 -tsudo systemctl restart nginxLaravel 用権限調整
sudo chown -R moheno:www-data /home/moheno/family-albumsudo chmod -R 755 /home/moheno/family-albumsudo chmod -R 775 /home/moheno/family-album/storage /home/moheno/family-album/bootstrap/cache