您的位置:首页 > 编程语言 > PHP开发

mac下php7.0.9的编译安装及问题处理总结

2016-08-26 23:25 1321 查看
下载php7.0.9.tar.gz解压。
./configure --prefix=/usr/local/php7 \
--with-apxs2=/usr/sbin/apxs \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli \
--with-pdo-mysql \
--with-iconv-dir \
--with-freetype-dir \
--with-zlib \
--with-jpeg-dir \
--with-png-dir \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--disable-fileinfo \
--enable-maintainer-zts
问题一:
checking for pkg-config... no
configure: error: Cannot find OpenSSL\'s <evp.h>
本地
whereis openssl
/usr/bin/openssl
Linux系统一般是yum install openssl openssl-devel这种。关于Mac OS一般是说要通过brew来安装。有些文章提到pkg-config,在报错提示那里有显示它。经查它是一个用来处理第三方库依赖的。对pkg-config的说明:pkg-config的一些用法
curl http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz -o pkg-config-0.28.tar.gz
tar zxvf pkg-config-0.28.tar.gz
cd pkg-config-0.28
./configure  --with-internal-glib
make
make install
(上面的版本是2003年的,实际有更新的版本。)但是上述执行完后,执行whereis pkg-config提示找不到,但是再执行前面php的configure的时候就会显示
checking for pkg-config... /usr/local/bin/pkg-config
说明安装成功了。不过下面还是提示找不到evp.php决定自己编译安装openssl,openssl-devel
curl https://www.openssl.org/source/openssl-1.0.2h.tar.gz -o openssl-1.0.2h.tar.gz
tar zxvf openssl-1.0.2h.tar.gz
cd openssl-1.0.2h
./config
make depend
make
make test
make install
查看configure文件,里面显示安装的位置在/usr/local/ssl/再次执行前面php的configure,又报错:
configure: error: jpeglib.h not found.
把--with-jpeg-dir和--with-png-dir去掉,结果报错。还是保留吧。加了个--with-webp-dir,后来这里报错。这一条不加了。到这里下载源码:http://libjpeg.sourceforge.net/执行configure的时候报错,看起来是/bin/sh后面有个奇怪的字符。查了一下因为是configure文件是dos格式的,可以通过vim ./configure:set ff//查看文件格式是dos还是unix,相当于:set fileformat:set ff=unix:wq再执行./configure即可。然后make && sudo make install这时会报/usr/local/man/man1/xxx文件或目录不存在。这时手动创建这个目录即可。继续执行php的configure发现报错,说找不到jpeglib.h查看jpeg的configure里写默认安装目录在/usr/local,但下面并有include,创建这个目录然后把源码里的*.h复制到这个目录下;重复执行,又报jpeglib.a找不到。这次需要在/usr/local/lib(如果没有目录创建之),然后把jpeg源码目录里编译出来的jpeglib.a文件复制到其中。又报错:
configure: error: png.h not found.
来这里http://www.libpng.org/pub/png/libpng.html找libpng.编译安装即可。又报错:
configure: error: freetype-config not found.
http://download.savannah.gnu.org/releases/freetype/下载freetype编译安装,没报什么错。又报错,查了一下都说通过一个叫gettext的包来获得。
configure: error: Cannot locate header file libintl.h
wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.2.tar.xz[/code] 
tar -zxvf gettext-0.19.2.tar.xz
cd gettext-0.19.2/
./configure
make
sudo make install
中间弹了几次对javac的提示,因为我没有安装java。又报错:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
来这里ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt下载。编译安装即可。搞定!configure完成。然后执行
make test
中间报错,说在php源码包里的ext/openssl/里有文件没找到,要找的文件刚好在下载的openssl源码包里有。直接把源码包里的/include/openssl目录整个复制到ext/openssl中。又报错,说ext/ftp里缺少openssl/ssl.h文件。像上面那样处理,通过。又报错,说ext/phar里缺少openssl/evp.h文件。像上面那样处理,通过。又报错,说ext/mysqlnd里缺少mysqlnd/evp.h文件。像上面那样处理,通过。又报错:
undefined symbols for architecture x86_64
查了一下,说是跟xcode有关系。参考stackoverflow的文章说要使用
xcode-select --install
实际执行的时候说已经安装了,需要更新。错误详细:
Undefined symbols for architecture x86_64:
"_PKCS5_PBKDF2_HMAC", referenced from:
_zif_openssl_pbkdf2 in openssl.o
"_SSL_CTX_set_alpn_protos", referenced from:
_php_openssl_setup_crypto in xp_ssl.o
"_SSL_CTX_set_alpn_select_cb", referenced from:
_php_openssl_setup_crypto in xp_ssl.o
"_SSL_get0_alpn_selected", referenced from:
_php_openssl_sockop_set_option in xp_ssl.o
"_SSL_select_next_proto", referenced from:
_server_alpn_callback in xp_ssl.o
"_TLSv1_1_client_method", referenced from:
_php_openssl_setup_crypto in xp_ssl.o
"_TLSv1_1_server_method", referenced from:
_php_openssl_setup_crypto in xp_ssl.o
"_TLSv1_2_client_method", referenced from:
_php_openssl_setup_crypto in xp_ssl.o
"_TLSv1_2_server_method", referenced from:
_php_openssl_setup_crypto in xp_ssl.o
ld: symbol(s) not found for architecture x86_64
说是因为openssl版本不一致此bug的官方报告:https://discussions.apple.com/thread/7066528?start=0&tstart=0安装了homebrew,说是用来做包依赖管理的。从这个地址安装:http://brew.sh/index_zh-cn.html使用
brew list openssl
显示没有。于是执行
brew install openssl
安装完毕之后再list显示:
NeodeMacBook-Pro:openssl neosong$ brew list openssl
/usr/local/Cellar/openssl/1.0.2h_1/bin/c_rehash
/usr/local/Cellar/openssl/1.0.2h_1/bin/openssl
/usr/local/Cellar/openssl/1.0.2h_1/include/openssl/ (75 files)
/usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2h_1/lib/libssl.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2h_1/lib/engines/ (12 files)
/usr/local/Cellar/openssl/1.0.2h_1/lib/pkgconfig/ (3 files)
/usr/local/Cellar/openssl/1.0.2h_1/lib/ (4 other files)
/usr/local/Cellar/openssl/1.0.2h_1/share/man/ (1588 files)
参考文章:https://github.com/phpbrew/phpbrew/issues/636 https://github.com/phpbrew/phpbrew/wiki/Trouble-Shooting:-Can't-build-PHP-on-OS-X-El-Capitan 按文章里的建议,说在配置的时候,--with-openssl=/usr/local/Cellar/openssl/1.0.2h_1这样就可以解决前面的问题了。
export LDFLAGS="/usr/local/opt/openssl/lib/libssl.dylib /usr/local/opt/openssl/lib/libcrypto.dylib"
最后是上面这句搞定的。总之看起来是编译依赖的问题。这里需要注意执行上面这句的用户与进行make的用户得是同一个,不然变量注册会无效。如果make的时候使用的是sudo执行的,需要切换到root用户来执行上面的命令。
sudo su -
然后以root用户执行前面的export与make等命令。补充:如果安装过程中出现了使用sudo仍然提示“Operation not permitted”的情况的话,是因为Mac El Captain加入了rootless机制,相当于给系统加了一道安全防线。要解决这类问题,需要重启mac,在启动时不断按command+r,这时会进入恢复模式,打开Terminal,执行:
csrutil disable
然后再重启就可以了。之后再进入恢复模式,执行:
csrutil enable
即可恢复。nginx的编译安装更简单,只需要注意要带上zlib和pcre两个扩展即可。yaf框架的一般nginx代理配置如下:
server {listen 80;server_name   myyaf myyaf.com;access_log  /var/log/nginx/myyaf.access.log;error_log   /var/log/nginx/myyaf-error.log;root /Users/xxxx/yaftest/public;index  index.html index.php;if (!-e $request_filename) {rewrite ^/(.*) /index.php?$1 last;}location ~ /.svn/ {deny all;}location / {root /Users/xxxx/yaftest/public;index  index.html index.php;}location ~ \.php$ {index index.php;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME$document_root$fastcgi_script_name;include fastcgi_params;}}
参考文章:

PHP编译过程中常见错误信息的解决方法

关于El Captain的Rootless机制
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php php7 mac