在Mac OS上自行编译安装Apache服务器和PHP解释器
Apache2.2.27和PHP5.5.12在MacOSX10.8.5编译安装过程:
在开始之前首先升级Xcode的组件:preferences=>Downloads=>下载CommandLineTools包
然后进入Apache的源码包,对于大部分的源码包都可以使用下面这个指令来查看编译选项:
./configure--help
配置编译选项:
./configure--prefix=/Users/levin/dev/apache2.2.27--enable-modules=most--enable-mods-shared=all
报错:
checkingforAPR-util...yes checkingforgcc.../Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc checkingwhethertheCcompilerworks...no configure:error:in`/Users/levin/Downloads/httpd-2.2.27': configure:error:Ccompilercannotcreateexecutables See`config.log'formoredetails
上面的报错是指路径:
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
不存在
解决方法:
cd/Applications/Xcode.app/Contents/Developer/Toolchains sudoln-sXcodeDefault.xctoolchainOSX10.8.xctoolchain
接着编译并安装:
make makeinstall
编辑配置文件httpd.conf,一般修改监听端口、运行Apache的用户和组、服务器名称、开启gzip等配置。
进入安装好的目录启动Apache:
./bin/apachectlstart
安装PHP
关于PHP编译选项可以参考:PHP:Listofcoreconfigureoptions-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分钟,视硬件配置而定,可以先去弄杯牛奶喝
发生错误:
Undefinedsymbolsforarchitecturex86_64: "_res_9_init",referencedfrom: _zif_dns_get_mxindns.o _zif_dns_get_recordindns.o _zif_dns_check_recordindns.o "_res_9_search",referencedfrom: _zif_dns_get_mxindns.o _zif_dns_get_recordindns.o _zif_dns_check_recordindns.o "_res_9_dn_skipname",referencedfrom: _zif_dns_get_mxindns.o _zif_dns_get_recordindns.o "_res_9_dn_expand",referencedfrom: _zif_dns_get_mxindns.o _php_parserrindns.o ld:symbol(s)notfoundforarchitecturex86_64 collect2:ldreturned1exitstatus make:***[libs/libphp5.bundle]Error1
解决:
exportLDFLAGS=-lresolv
错误:
dyld:Librarynotloaded:libmysqlclient.18.dylib Referencedfrom:/Users/levin/Downloads/php-5.5.12/sapi/cli/php Reason:imagenotfound ... make:***[ext/phar/phar.php]Error133
解决:
cd/usr/lib ln-s/usr/local/mysql-5.6.12-osx10.7-x86_64/lib/libmysqlclient.18.dyliblibmysqlclient.18.dylib
重新编译并安装:
makeclean&&make makeinstall
安装完成,此时需要从PHP的源码目录copy一份配置文件到安装目录的etc文件夹下面并改名为php.ini,需要更改PHP的配置时就使用该文件即可。