在Mac OS上自行编译安装Apache服务器和PHP解释器


Posted in PHP onDecember 24, 2015

Apache 2.2.27和PHP 5.5.12在Mac OS X 10.8.5编译安装过程:
在开始之前首先升级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的源码目录copy一份配置文件到安装目录的etc文件夹下面并改名为php.ini,需要更改PHP的配置时就使用该文件即可。

PHP 相关文章推荐
PHP文本操作类
Nov 25 PHP
php之字符串变相相减的代码
Mar 19 PHP
php 生成随机验证码图片代码
Feb 08 PHP
比较好用的PHP防注入漏洞过滤函数代码
Apr 11 PHP
php中的注释、变量、数组、常量、函数应用介绍
Nov 16 PHP
解析如何在PHP下载文件名中解决乱码的问题
Jun 20 PHP
从PHP的源码中深入了解stdClass类
Apr 18 PHP
PHP实现统计在线人数功能示例
Oct 15 PHP
php利用imagemagick实现复古老照片效果实例
Feb 16 PHP
利用laravel搭建一个迷你博客实战教程
Aug 13 PHP
Laravel框架运行出错提示RuntimeException No application encryption key has been specified.解决方法
Apr 02 PHP
关于PHP求解三数之和问题详析
Nov 09 PHP
PHP实现文件上传和多文件上传
Dec 24 #PHP
纯PHP代码实现支付宝批量付款
Dec 24 #PHP
PHP文件上传问题汇总(文件大小检测、大文件上传处理)
Dec 24 #PHP
4种PHP异步执行的常用方式
Dec 24 #PHP
php实现异步数据调用的方法
Dec 24 #PHP
PHP下SSL加密解密、验证、签名方法(很简单)
Jun 28 #PHP
深入浅析php json 格式控制
Dec 24 #PHP
You might like
对盗链说再见...
2006/10/09 PHP
php 获取本机外网/公网IP的代码
2010/05/09 PHP
PHP小技巧之函数重载
2014/06/02 PHP
PHP实现生成透明背景的PNG缩略图函数分享
2014/07/08 PHP
Js中sort()方法的用法
2006/11/04 Javascript
Web层改进II-用xmlhttp 无声息提交复杂表单
2007/01/22 Javascript
firefox 和 ie 事件处理的细节,研究,再研究 书写同时兼容ie和ff的事件处理代码
2007/04/12 Javascript
JS.GetAllChild(element,deep,condition)使用介绍
2013/09/21 Javascript
js window.open弹出新的网页窗口
2014/01/16 Javascript
jquery 操作两个select实现值之间的互相传递
2014/03/07 Javascript
JS获取当前网页大小以及屏幕分辨率等
2014/09/05 Javascript
HTML5 canvas 9绘制图片实例详解
2016/09/06 Javascript
jQuery中Chosen三级联动功能实例代码
2017/03/07 Javascript
thinkjs 文件上传功能实例代码
2017/11/08 Javascript
node基于puppeteer模拟登录抓取页面的实现
2018/05/09 Javascript
Angular6新特性之Angular Material
2018/12/28 Javascript
IntelliJ IDEA编辑器配置vue高亮显示
2019/09/26 Javascript
使用django-crontab实现定时任务的示例
2018/02/26 Python
python使用RNN实现文本分类
2018/05/24 Python
python matplotlib.pyplot.plot()参数用法
2020/04/14 Python
python 获取字典特定值对应的键的实现
2020/09/29 Python
python反编译教程之2048小游戏实例
2021/03/03 Python
HTML5新特性 多线程(Worker SharedWorker)
2017/04/24 HTML / CSS
日本运动品牌美津浓官方购物网站:MIZUNO SHOP
2016/08/21 全球购物
西班牙英格列斯百货法国官网:El Corte Inglés法国
2017/07/09 全球购物
介绍一下Make? 为什么使用make
2013/12/08 面试题
J2EE面试题大全
2016/08/06 面试题
幼师自我鉴定范文
2013/10/01 职场文书
医大实习自我鉴定
2013/12/07 职场文书
幼儿园开学寄语
2014/04/03 职场文书
经济贸易专业自荐信
2014/06/11 职场文书
工作失职检讨书范文
2015/05/05 职场文书
步步惊心观后感
2015/06/12 职场文书
资深HR教你写好简历中的自我评价
2019/05/07 职场文书
QT与javascript交互数据的实现
2021/05/26 Javascript
关于Vue中的options选项
2022/03/22 Vue.js