memo.xight.org

日々のメモ

カテゴリ : Nginx

1ページ目 / 全1ページ

Homebrew で nginx + PHP + PHP-FPM

Summary

Homebrew を使って、ユーザ権限で nginx, PHP-FPM を動かしたい。

Install

brew tap josegonzalez/php
brew install nginx
brew install php54 --with-mysql --with-fpm --with-intl --with-readline

/usr/local/etc/nginx/nginx.conf

http {
...
	include /usr/local/etc/nginx/conf.d/*.conf;
	include /usr/local/etc/nginx/sites-enabled/*;
}

/usr/local/etc/nginx/sites-available/localhost

server {
	listen       8000;
	server_name  localhost;

	root   /Users/yoshiki/Sites/localhost;
	index index.php index.html index.htm;

	access_log /usr/local/var/log/nginx/localhost/access_log;
	error_log  /usr/local/var/log/nginx/localhost/error_log;

	location / {
		try_files $uri $uri/ $uri.php;
	}

	location ~ \.php$ {
		fastcgi_pass   127.0.0.1:9000;
		fastcgi_index  index.php;
		fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include        fastcgi_params;
	}
}

ディレクトリとシンボリックリンクを作成

mkdir -p /usr/local/var/run/nginx
mkdir -p /usr/local/var/log/nginx/localhost

mkdir -p /usr/local/etc/nginx/conf.d
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
ln -s /usr/local/etc/nginx/sites-available/localhost /usr/local/etc/nginx/sites-enabled/localhost

php-fpm.conf

listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1

nginx, PHP-FPMの起動

nginx
/usr/local/sbin/php54-fpm start

nginx, PHP-FPMの停止

nginx -s stop
/usr/local/sbin/php54-fpm stop