安装nginx(当前版本 1.0.6)
brew install nginx
安装目录 /usr/local/Cellar/nginx/1.0.6
编译安装PHP(当前版本 5.3.8)
主要配置参数来源于Lion自带的php,本处做了部分修改,主要包括:
- 移除 –with-icu-dir=/usr –enable-suhosin
- 移除 –with-apxs2=/usr/sbin/apxs
- 新增 –enable-fpm –enable-force-cgi-redirect
- 修正libpng和freetype库文件目录错误
- 移除其他无用参数
For fastcgi usage
./configure –prefix=/opt/php –with-config-file-path=/opt/php/etc –enable-fpm –enable-cgi –enable-cli –with-libxml-dir=/usr –with-openssl=/usr –with-kerberos=/usr –with-zlib=/usr –enable-bcmath –with-bz2=/usr –enable-calendar –with-curl=/usr –enable-dba –with-ndbm=/usr –enable-exif –enable-ftp –with-gd –with-freetype-dir=/usr/X11 –with-jpeg-dir=/usr/local –with-png-dir=/usr/X11 –enable-gd-native-ttf –with-iodbc=/usr –with-ldap=/usr –with-ldap-sasl=/usr –with-libedit=/usr –enable-mbstring –enable-mbregex –with-mysql=mysqlnd –with-mysqli=mysqlnd –without-pear –with-pdo-mysql=mysqlnd –with-mysql-sock=/tmp/mysql.sock –with-readline=/usr –enable-shmop –with-snmp=/usr –enable-soap –enable-sockets –enable-sqlite-utf8 –enable-sysvmsg –enable-sysvsem –enable-sysvshm –with-tidy –enable-wddx –with-xmlrpc –with-iconv-dir=/usr –with-xsl=/usr –enable-zend-multibyte –enable-zip –with-pcre-regex=/usr –with-pgsql=/usr –with-pdo-pgsql=/usr
For apache usage
./configure –prefix=/opt/php –disable-fpm –enable-cgi –with-apxs2=/usr/sbin/apxs –enable-cli…
sudo make
sudo make install
sudo cp php.ini-development /opt/php/etc/php.ini
cd /opt/php
sudo cp etc/php-fpm.conf.default etc/php-fpm.conf
配置PHP
sudo vim etc/php.ini
更新时区配置:
date.timezone = PRC
配置PHP-FPM
sudo vim etc/php-fpm.conf
去除如下选项的注释:
pid = run/php-fpm.pid
error_log = log/php-fpm.log
noticelog_level = notice
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
sudo ln bin/php.dSYM bin/php
sudo ln sbin/php-fpm.dSYM sbin/php-fpm
配置nginx
vim /usr/local/etc/nginx/nginx.conf
更新内容:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
vim /usr/local/etc/nginx/fastcgi_params
新增行:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
启动环境
sudo /opt/php/sbin/php-fpm
sudo nginx
结束环境
sudo kill `cat /opt/php/var/run/php-fpm.pid`
sudo nginx -s stop
关键备忘
1、配置PHP编译选项时候提示
configure: error: png.h not found.
configure: error: freetype.h not found.
表明 –with-freetype-dir 和 –with-png-dir 指向的目录不正确,应当修改为/usr/X11
2、提示 –enable-ndbm 参数无效
修正为 –enable-ndbm=/usr 即可
3、Lion下killall php-fpm 无法终止进程,必须按上文所述方法终止
4、如果与 Apache 搭配,使用上文提供的编译参数重编译后 sudo apachectl restart 即可。
5、如若想恢复自带 PHP 版本 5.3.6 ,找个朋友 Copy 份原始的 /usr/libexec/apache2/libphp5.so 覆盖回去即可。
6、php.dSYM 的后缀含义为 Apple Xcode debug symbols file,应该是编译环境导致的
UPDATE@2011.10.25
去除无用参数–enable-force-cgi-redirect
修正mysql sock文件的路径
TODO
配置 launchctl 使服务开机启动