macbook pro 编译安装apache、php

故事要从php不能用了说起。。。

dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib

mac本来安装的是[email protected] 毫无预兆的运行时候出现了上面的提示,从此就进入了怎么都解决不了的悲催世界里,全部网上能找的办法都找遍了,愣是解决不了。于是卸载了php5.6,想重装却发现brew 没有7之前的版本,好吧,开始我的编译安装之旅吧

1、到官网下载apache2.4

http://httpd.apache.org/download.cgi#apache24

2、解压

tar -jxvf httpd-2.4.37.tar.bz2

3、进入解压后的文件夹

cd httpd-2.4.37

4、配置

./configure --prefix=/usr/local/httpd --enable-mods-shared=most --enable-so --enable-module=so --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-ssl --enable-dav --enable-maintainer-mode --with-ssl=/usr/local/Cellar/openssl/1.0.2o_1 --with-apr=/usr/local/Cellar/apr/1.6.5/bin/apr-1-config --with-apr-util=/usr/local/Cellar/apr-util/1.6.1_1/bin/apu-1-config

ps:由于apr、apr-util、openssl都是使用brew 下载安装的,所以需要用brew info apr来确定apr的安装路径,然后在配置apache的时候指定到相应的路径,其中必须配置参数--enable-so 不然安装php的时候无法生成libphp.so文件

5、编译以及安装apache

make && make install

6、开启apache

sudo /usr/local/httpd/bin/apachectl start

ps:启动时遇到错误-->遇到错误:httpd: Could not reliably determine the server's fully qualified domain name

vim /usr/local/httpd/conf/httpd.conf找到ServerName 完成一下修改,再重启

macbook pro 编译安装apache、php

7、从官网下载php

官网地址:http://php.net/get/php-5.6.38.tar.bz2/from/a/mirror

8、解压php、进入目录、配置

tar -jxvf php-5.6.38.tar.bz2

cd php-5.6.38

 ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --enable-inline-optimization --disable-debug --disable-rpath --with-apxs2=/usr/local/httpd/bin/apxs  --enable-pcntl --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --enable-bcmath --enable-soap --with-libxml-dir --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --with-libedit --enable-zip --with-bz2 --with-readline --enable-pcntl -with-openssl-dir=/usr/local/Cellar/openssl/1.0.2o_1 

配置过程中的坑

(1)pcntl默认不开启,必须配置时候开启--enable-pcntl

(2)必须通过sudo find / -name 'apxs'找到apache安装路径然后配置路径保证php与apache能连接

(3)openssl由brew下载安装所在路径与configure文件默认的openssl路径不一致,需要在配置的时候配置为正确的路径(brew info openssl 可以看到路径)-with-openssl-dir=/usr/local/Cellar/openssl/1.0.2o_1 

(4)最后报错configure: error: Cannot locate header file libintl.h 

  • 安装 gettextbrew install gettext
  • vim configure 文件:
  • for i in $PHP_GETTEXT /usr/local /usr ; do  改成  for i in $PHP_GETTEXT /usr/local /usr /usr/local/Cellar/gettext/0.19.8.1 ; do

9、编译安装php

make && make install

10、打开apache配置文件

vim /usr/local/httpd/conf/httpd.conf

修改

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

增加

<IfModule mod_php5.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>

 

11、在网站更目录增加index.php,输入<?php phpinfo(); 保存

12、访问http://localhost/index.php

macbook pro 编译安装apache、php