LoginSignup
23
26

More than 5 years have passed since last update.

macにnginx + php-fpmを導入する際の手順

Last updated at Posted at 2015-02-09

nginxのインストール

brew install nginx

nginxのアップグレード

brew upgrade nginx

nginxの自動起動設定

ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents

nginxを起動する

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

php-fpmのインストール

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/php
brew install php56 --with-fpm
※過去のバージョンがインストールされている場合はphp56へリンク変更しておく
brew unlink php55
brew link php56

phpの自動起動設定

ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

nginxの設定

nginx.confのserverディレクティブに下記を追加する

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

PHPスクリプトの格納ディレクトリを作成

sudo mkdir /var/www
chmod 777 /var/www

適当なPHPスクリプトを作成

/var/www/index.php
<?php
   phpinfo();

nginxを再起動

設定を反映する為にnginxを再起動する。

nginx -s reload

ブラウザで動作確認

http://localhost:8080/index.php にアクセスするとPHPスクリプトが動作していることを確認できます。

23
26
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
23
26