最新のPHPを使えるようになったので[2014-02-09-1]
、nginxもセットアッ
プしてみました。
これでようやくOSX MavericksのApache&PHPとオサラバできます。
php-fpmの設定と起動
~/.phpenv/versions/5.5.9/etc/php-fpm.conf.defaultを以下のように修正し、
同ディレクトリにphp-fpm.confとして保存しました。
userとgroupをコメントアウトしているのは、今回のNgnixはユーザ権限で
動かす適当なものだからです。
listenはnginxとの橋渡しです。今回は同一マシンなのでUNIXドメインソケッ
トを使用しました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/etc/php-fpm.conf b/etc/php-fpm.conf | |
index 00d3c1b..de7639a 100644 | |
--- a/etc/php-fpm.conf | |
+++ b/etc/php-fpm.conf | |
@@ -145,8 +145,8 @@ | |
; Unix user/group of processes | |
; Note: The user is mandatory. If the group is not set, the default user's group | |
; will be used. | |
-user = nobody | |
-group = nobody | |
+;user = nobody | |
+;group = nobody | |
; The address on which to accept FastCGI requests. | |
; Valid syntaxes are: | |
@@ -156,7 +156,7 @@ group = nobody | |
; specific port; | |
; '/path/to/unix/socket' - to listen on a unix socket. | |
; Note: This value is mandatory. | |
-listen = 127.0.0.1:9000 | |
+listen = /usr/local/var/run/php5-fpm.sock | |
; Set listen(2) backlog. | |
; Default Value: 65535 (-1 on FreeBSD and OpenBSD) |
自動起動スクリプトを作成しました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>org.php.php-fpm</string> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>KeepAlive</key> | |
<false/> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/Users/masutaka/.phpenv/versions/5.5.9/sbin/php-fpm</string> | |
<string>--fpm-config</string> | |
<string>/Users/masutaka/.phpenv/versions/5.5.9/etc/php-fpm.conf</string> | |
</array> | |
<key>UserName</key> | |
<string>masutaka</string> | |
<key>Debug</key> | |
<false/> | |
</dict> | |
</plist> |
上記自動起動用のファイルを設置しました。
$ ln -sfv <path to org.php.php-fpm.plist> ~/Library/LaunchAgents
自動起動ON&起動しました。
$ launchctl load -w ~/Library/LaunchAgents/org.php.php-fpm.plist
nginxのインストールと設定、起動
Apacheを自動起動する設定にしていたので削除しました。
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Ngnixはbrewコマンドでインストールしました。
(実際はbrew bundle[2014-01-25-1]
でインストールしてます。)
$ brew install nginx
==> Downloading http://nginx.org/download/nginx-1.4.4.tar.gz
Already downloaded: /Library/Caches/Homebrew/nginx-1.4.4.tar.gz
==> ./configure --prefix=/usr/local/Cellar/nginx/1.4.4 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx/1.4.4/bin/nginx --with-cc-opt=-I/usr
==> make
==> make install
==> Caveats
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
To have launchd start nginx at login:
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
Then to load nginx now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Or, if you don't want/need launchctl, you can just run:
nginx
==> Summary
� /usr/local/Cellar/nginx/1.4.4: 7 files, 876K, built in 61 seconds
上の説明を参考に以下を実行しました。
/usr/local/etc/nginx/nginx.confを以下のように修正しました。
自分しか使わないのでrootも適当です。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /usr/local/etc/nginx/nginx.conf.default 2014-05-06 17:15:02.000000000 +0900 | |
+++ /usr/local/etc/nginx/nginx.conf 2014-06-20 11:33:03.000000000 +0900 | |
@@ -33,7 +33,7 @@ | |
#gzip on; | |
server { | |
- listen 8080; | |
+ listen 80; | |
server_name localhost; | |
#charset koi8-r; | |
@@ -41,8 +41,17 @@ | |
#access_log logs/host.access.log main; | |
location / { | |
- root html; | |
+ root /Users/masutaka/Sites; | |
index index.html index.htm; | |
+ autoindex on; | |
+ | |
+ location ~ \.php$ { | |
+ fastcgi_pass unix:/usr/local/var/run/php5-fpm.sock; | |
+ fastcgi_index index.php; | |
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
+ include fastcgi_params; | |
+ fastcgi_param SERVER_NAME $host; | |
+ } | |
} | |
#error_page 404 /404.html; |
上記自動起動用のファイルを設置しました。
$ sudo cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist /Library/LaunchAgents
自動起動ON&起動しました。
$ sudo launchctl load -w /Library/LaunchAgents/homebrew.mxcl.nginx.plist
http://localhost にアクセス出来ると思います。
追記(2014-06-22):
ポート8080をから80に、権限もユーザからrootに変更しました。