1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mac、Nginx、php-fpm7.2 の環境で Laravel 5.8を動かす

Last updated at Posted at 2019-07-27

経緯

上記環境でLaravelアプリケーションが動かなかった
(トップページは表示されたものの、ログインページが 404 Not Found となった)
ので、設定ファイルを変更したときのメモ。

Mac、Nginx、php-fpm7.2構築方法はこちら
macにbrewでnginxとPHP7.2をインストールした
https://qiita.com/uneri/items/46bfeeabf77d76abb3ba

概要

Nginxのデフォルトの設定ファイルをコピーして、以下2箇所を書き換える。

詳細

デフォルトの設定ファイルをコピー

cd /usr/local/etc/nginx/
cp nginx.conf.default nginx.conf
vim nginx.conf

1箇所目

変更前

nginx.conf
      location / {
            root   html;
            index  index.html index.htm;
        }

変更後(xxxxはアプリケーションのパス)

nginx.conf
      location / {
            root /usr/local/var/www/xxxx/public;
            index index.php index.html
            try_files $uri $uri/ /index.php;
        }

2箇所目

変更前

nginx.conf
       #location ~ \.php$ {
       #    root           html;
       #    fastcgi_pass   127.0.0.1:9000;
       #    fastcgi_index  index.php;;
       #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
       #    include        fastcgi_params;
       #}

変更後(xxxxはアプリケーションのパス)

nginx.conf
        location ~ \.php$ {
            root /usr/local/var/www/xxxx/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

Nginxを再起動する

brew services restart nginx

ブラウザでアプリケーションにアクセスする

参考にした情報

All Laravel routes "not found" on nginx
https://www.digitalocean.com/community/questions/all-laravel-routes-not-found-on-nginx

MacでNingx、PHP7.1、php-fpmで環境構築(メモ)
https://qiita.com/nogizaka46/items/42a6ea1c634985f98564

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?