Mac OS X 10.8.5 编译安装 Apache 2.2.27 与 PHP 5.5.12 流程
以下是在 Mac OS X 10.8.5 系统中编译安装 Apache 2.2.27 和 PHP 5.5.12 的具体流程: 首先,需要升级 Xcode 的相关组件,操作路径为 preferences => Downloads => 下载 Command Line Tools 包。
随后进入 Apache 的源码目录,对于大多数源码包,均可使用如下指令来查看可用的编译选项:
./configure --help
执行配置命令以设置编译参数:
./configure --prefix=/Users/levin/dev/apache2.2.27 --enable-modules=most --enable-mods-shared=all
编译过程中出现报错信息:
checking for APR-util... yes
checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
checking whether the C compiler works... no
configure: error: in `/Users/levin/Downloads/httpd-2.2.27':
configure: error: C compiler cannot create executables
See `config.log' for more details
上述报错指向的路径为:
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
该路径不存在。
解决方法如下:
cd /Applications/Xcode.app/Contents/Developer/Toolchains
sudo ln -s XcodeDefault.xctoolchain OSX10.8.xctoolchain
接着执行编译并安装操作:
make
make install
编辑配置文件 httpd.conf,通常需修改监听端口、运行 Apache 的用户和组、服务器名称以及开启 gzip 压缩等配置项。
进入已安装的目录启动 Apache 服务:
./bin/apachectl start
接下来进行 PHP 的安装。
关于 PHP 的编译选项参考文档:PHP: List of core configure options - Manual。
./configure --prefix=/Users/levin/dev/php5.5.12 --with-apxs2=/Users/levin/dev/apache2.2.27/bin/apxs --with-config-file-path=/Users/levin/dev/php5.5.12/etc --with-openssl --with-zlib --enable-bcmath --with-bz2 --with-curl --enable-ftp --with-gd --enable-gd-native-ttf --with-mhash --enable-mbstring --enable-soap --enable-zip --enable-sockets --with-mysql=/usr/local/mysql-5.6.12-osx10.7-x86_64 --with-mysqli=/usr/local/mysql-5.6.12-osx10.7-x86_64/bin/mysql_config --with-iconv --with-pear --enable-opcache
make
整个编译过程耗时约 5-10 分钟,具体取决于硬件配置,期间可以先去弄杯牛奶喝。
编译时发生错误:
Undefined symbols for architecture x86_64:
"_res_9_init", referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_get_record in dns.o
_zif_dns_check_record in dns.o
"_res_9_search", referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_get_record in dns.o
_zif_dns_check_record in dns.o
"_res_9_dn_skipname", referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_get_record in dns.o
"_res_9_dn_expand", referenced from:
_zif_dns_get_mx in dns.o
_php_parserr in dns.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1
解决方案:
export LDFLAGS=-lresolv
出现另一错误:
dyld: Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/levin/Downloads/php-5.5.12/sapi/cli/php
Reason: image not found
...
make: *** [ext/phar/phar.php] Error 133
解决方法:
cd /usr/lib
ln -s /usr/local/mysql-5.6.12-osx10.7-x86_64/lib/libmysqlclient.18.dylib libmysqlclient.18.dylib
重新执行编译并安装:
make clean && make
make install
安装完成后,需要从 PHP 的源码目录复制一份配置文件到安装目录的 etc 文件夹下,并重命名为 php.ini,后续更改 PHP 配置时即使用该文件。