LoginSignup
8
9

More than 5 years have passed since last update.

MacでNingx、PHP7.1、php-fpmで環境構築(メモ)

Last updated at Posted at 2017-06-11

Macで環境構築

HomebrewでNginx、PHP7.1、php-fpmをインストール

Nginxをインストール

  • インストール
$ brew install nginx

PHP7.1をインストール(php-fpmもついてくる)

  • インストール
$ brew install php71
  • 使用しているシェルによるが、自分はzshなので~/.zshrcにphpのパスが通るにように設定を記載
export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
  • 読み込みなおす
$ source ~/.zshrc

php-fpmの起動設定

  • phpが自動で起動するように設定する
//-pで指定したディレクトリをサブディレクトリごと作成している
$ mkdir -p ~/Library/LaunchAgents
//ファイルのコピー
$ cp /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
//php-fpmを起動している
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
  • 下のようになれば起動確認OK
$ ps ax | grep php-fpm
 1317   ??  S      0:00.14 /usr/local/opt/php71/sbin/php-fpm --fpm-config /usr/local/etc/php/7.1/php-fpm.conf
 1324   ??  S      0:00.01 /usr/local/opt/php71/sbin/php-fpm --fpm-config /usr/local/etc/php/7.1/php-fpm.conf
 1325   ??  S      0:00.00 /usr/local/opt/php71/sbin/php-fpm --fpm-config /usr/local/etc/php/7.1/php-fpm.conf
 1420 s001  S+     0:00.00 grep php-fpm

Nginxのバーチャルホスト、php-fpmの設定

  • ファイルの/usr/local/etc/nginx/nginx.confを編集
# another virtual host using mix of IP-, name-, and port-based configuration
//バーチャルホストの設定
server {
    listen       80;
    server_name  framework.local;

    location / {
        root   プロジェクトまでのファイルパス;
        index  index.php index.html index.htm;
    }

    //php-fpmの設定
    location ~ \.php$ {
        root           プロジェクトまでのファイルパス;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
  • nginx起動
//Macでは1024番ポート以前のポート番号は、開放時にroot権限が必要です
$ sudo nginx  //起動

hosts設定

ファイルの/etc/hostsを編集

127.0.0.1    framework.local

ブラウザ確認

参考URL

https://utano.jp/entry/2016/07/nginx-and-php-fpm-download-php-file/
https://utano.jp/entry/2016/07/mac-homebrew-php-fpm-56-installation/
http://qiita.com/kotarella1110/items/634f6fafeb33ae0f51dc
http://qiita.com/megurock/items/c40200039f6838f51d94

8
9
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
8
9