Mac OS X(Lion)下源码安装Nginx + PHP + MySQL

想要在Mac下源码方式安装软件,前提是:去苹果官方下载安装XCode,安装好后打开preference,安装Command Line Tools,里面包含gcc,make等所有工具。

[color=darkred][size=medium][b]I. 安装MYSQL[/b][/size][/color]
从官方下载 mysql-5.5.25a-osx10.6-x86_64.dmg二进制包,安装到/usrl/local/mysql
使用:sudo /usr/local/bin/msyqld_safe & 启动之.

OS X 系统安装的mysql默认是不用my.cnf配置文件的,仅是使用默认的数据库配置值。
如要进行数据库定制,可到'/usr/local/mysql/support-files/'文件夹底下,把里面的任一个.cnf配置文件复制到/etc/目录底下并修改文件名称为my.cnf。
把Mysql加入到launchd服务,使开机自动启动Mysql
在/Library/LaunchDaemons/目录创建文件com.mysql.mysql.plist(文件名任意):

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key>
<string>com.mysql.mysql</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mysql/bin/mysqld_safe</string>
</array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><false/>
</dict>
</plist>

[color=darkred][size=medium][b]II. 安装PHP[/b][/size][/color]
[color=darkred][b]1. 安装PHP扩展准备[/b][/color]
[b][color=green]1).安装GD库[/color][/b]
为了安装GD库到yum安装必要的包(libpng,libjpeg,freetype等)还要安装 : jpegsrc.v8d.tar.gz,libpng-1.2.50.tar.gz,freetype-2.4.10.tar.bz2
[b]a. 安装jpegsrc.v8d.tar.gz[/b]
下载http://www.ijg.org/files/jpegsrc.v8d.tar.gz
进入jpeg-8d的源码目录,然后执行以下步骤:

./configure --enable-shared --enable-static
make
sudo make install

[b]b. 安装libpng-1.2.50.tar.gz[/b]
下载http://nchc.dl.sourceforge.net/project/libpng/libpng12/1.2.50/libpng-1.2.50.tar.gz

./configure
make
make install

[b]c. 安装freetype-2.4.10.tar.gz[/b]
下载http://www.freetype.org/download.html

./configure
make
make install


[color=green][b]2).安装mcrypt及扩展[/b][/color]
请参考[url]http://koda.iteye.com/blog/420991[/url]

[color=darkred][b]2. 编译PHP[/b][/color]

sudo ./configure --prefix=/usr/local/php --with-iconv=/opt/local --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-zlib --enable-mbstring --with-gd --with-curl --with-freetype-dir=/usr --with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --enable-fpm --enable-zip --with-mcrypt --with-mhash --enable-intl --with-openssl --enable-exif --enable-soap
sudo make
sudo make install


参数补充说明:
--with-mcrypt --with-mhash
如果未安装mcrypt扩展,删除该configure参数:
--with-iconv=/opt/local
如果没有该参数,安装时候报错可能:

Undefined symbols for architecture x86_64:
"_iconv_close", referenced from:
_cconv_close in cconv-cconv.o
"_iconv", referenced from:
_cconv in cconv-cconv.o
"_iconv_open", referenced from:
_cconv_open in cconv-cconv.o
ld: symbol(s) not found for architecture x86_64

原因是iconv版本低,要么手工下载iconv编译升级;要么如果你安装了MacPort(如果iconv版本更高), 可以用在php configure运行时增加参数--with-iconv=/opt/local

[color=darkred][b]3. 配置php-fpm并运行[/b][/color]
PHP5.4内置了fastcgi支持。
1). 生成配置文件
复制$PHP_DIR/etc/php-fpm.conf.default 到$PHP_DIR/etc/php-fpm.conf
打开一下两行注释:
pid = run/php-fpm.pid
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_children=50

2). 启动php-fpm
sudo $PHP_DIR/sbin/php-fpm
3). 停止php-fpm
sudo killall -9 php-fpm

4). 加入到服务中去并每次开机自动启动
使用launchctl来把php-fpm加入启动服务。建立/Library/LaunchDaemons/net.php.php-fpm.plist,内容如下:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key>
<string>net.php.php-fpm</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/php/sbin/php-fpm</string>
<string>--fpm-config</string>
<string>/usr/local/php/etc/php-fpm.conf</string>
</array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><false/>
</dict>
</plist>

启动之: sudo launchctl load -w /Library/LaunchDaemons/net.php.php-fpm.plist
停止之: sudo launchctl unload /Library/LaunchDaemons/net.php.php-fpm.plist
下次重新启动php-fpm就被启动了

[color=darkred][size=medium][b]III. 安装nginx[/b][/size][/color]
Nginx依赖PCRE,不过这个你在安装XCode时应该就默认安装好了。下载Nginix[url]http://nginx.org/download/nginx-1.2.2.tar.gz[/url]

tar -xzvf nginx-1.2.2.tar.gz
cd nginx-1.2.2
./configure --prefix=/usr/local/nginx
make
make install

参考 [url]http://kevinworthington.com/nginx-for-mac-os-x-lion-in-2-minutes/[/url]

启动: sbin/nginx (默认使用conf/nginx.conf作为配置文件)
停止: kill `cat /usr/local/nginx/logs/nginx.pid`
加入launchd: 创建/Library/LaunchDaemons/org.ngnix.nginx.plist

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key>
<string>org.nginx.nginx</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/nginx/sbin/nginx</string>
<string>-c</string>
<string>/usr/local/nginx/conf/nginx.conf</string>
</array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><false/>
</dict>
</plist>

启动之:sudo launchctl load -w /Library/LaunchDaemons/org.ngnix.nginx.plist
停止之:sudo launchctl unload /Library/LaunchDaemons/org.ngnix.nginx.plist
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值