博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mac Pro 编译安装 PHP 5.6.21 及 问题汇总
阅读量:6683 次
发布时间:2019-06-25

本文共 6881 字,大约阅读时间需要 22 分钟。

系统环境

操作系统:OS X 10.11.5

Xcode:7.3.1

注意

编译之前,需要安装 xcodeHomebrew 套件!

 

1、准备相关软件包,统一放到 /usr/local/src/php 目录下:

 

2、安装依赖库

# 安装 libmcryptcd /usr/local/src/phptar -xzvf ./libmcrypt-2.5.7.tar.gzcd ./libmcrypt-2.5.7./configuresudo make sudo make install# 安装 libmhashcd /usr/local/src/phptar -xzvf ./mhash-0.9.9.9.tar.gzcd ./mhash-0.9.9.9./configuresudo makesudo make install# 安装 libiconvcd /usr/local/src/phptar -xzvf ./libiconv-1.14.tar.gzcd ./libiconv-1.14./configuresudo makesudo make install# 安装 bzip2cd /usr/local/src/phptar -xzvf ./bzip2-1.0.6.tar.gzcd ./bzip2-1.0.6sudo make sudo make install# 安装 libpng (png图片处理, GD库依赖)cd /usr/local/src/phptar -xzvf ./libpng-1.6.21.tar.xzcd ./libpng-1.6.21./configuresudo makesudo make install# 安装 ibjpeg (jpg图片处理, GD库依赖)cd /usr/local/src/phptar -xzvf ./jpegsrc.v9a.tar.gzcd ./jpeg-9a./configuresudo makesudo make install# 安装 freetypecd /usr/local/src/phptar -xzvf ./freetype-2.4.12.tar.gzcd ./freetype-2.4.12./configuresudo makesudo make install# 安装 gettextcd /usr/local/src/phptar -xzvf ./gettext-0.19.tar.gzcd ./gettext-0.19./configuresudo makesudo make install

 

3、安装PHP

# 解压PHP安装包cd /usr/local/src/phptar -xzvf ./php-5.6.21.tar.gzcd ./php-5.6.21
# 编译./configure \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--with-openssl \--with-zlib \--with-bz2 \--with-gd \--with-jpeg-dir \--with-png-dir \--with-gettext \--with-mhash \--with-freetype-dir \--with-mcrypt \--with-iconv \--with-curl \--with-xmlrpc \--with-mysql \--with-pdo-mysql \--with-mysqli \--enable-calendar \--enable-pdo \--enable-zip \--enable-mbstring \--enable-mbregex \--enable-bcmath \--enable-soap \--enable-sockets \--enable-ftp \--enable-gd-native-ttf \--enable-shmop \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \--enable-xml \--enable-pcntl \--enable-fpm \--enable-opcache \--without-pear

报错1

configure: error: Cannot find OpenSSL's <evp.h>

解决

(1)、安装 openssl

brew install openssl

(2)、把 --with-openssl 改为 --with-openssl=/usr/local/opt/openssl

(如果安装了 brew,那么openssl的路径为 /usr/local/opt/openssl/

./configure \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--with-openssl=/usr/local/opt/openssl \--with-zlib \--with-bz2 \--with-gd \--with-jpeg-dir \--with-png-dir \--with-gettext \--with-mhash \--with-freetype-dir \--with-mcrypt \--with-iconv \--with-curl \--with-xmlrpc \--with-mysql \--with-pdo-mysql \--with-mysqli \--enable-calendar \--enable-pdo \--enable-zip \--enable-mbstring \--enable-mbregex \--enable-bcmath \--enable-soap \--enable-sockets \--enable-ftp \--enable-gd-native-ttf \--enable-shmop \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \--enable-xml \--enable-pcntl \--enable-fpm \--enable-opcache \--without-pear

 

# 执行 makesudo make

【报错2】

Undefined symbols for architecture x86_64:

  "_PKCS5_PBKDF2_HMAC", referenced from:
      _zif_openssl_pbkdf2 in openssl.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
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sapi/cli/php] Error 1

【解决】

修改 Makefile 文件

找到 EXTRA_LIBS 节点,删除所有的 -lssl 和 -lcrypto 然后追加 libssl.dylib 和 libcrypto.dylib 的路径(如果你安装了 brew,那么则是 /usr/local/opt/openssl/lib/),重新运行 make 命令。

附上我修改后的 MakeFile EXTRA_LIBS 那一行:

EXTRA_LIBS =  -lz -lresolv  -lintl -lpng -lz -ljpeg  -lcurl -lbz2 -lz -lm -lxml2 -lz -licucore -lm -lcurl -lxml2 -lz -licucore -lm -lfreetype -lz -lbz2 -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm /usr/local/opt/openssl/lib/libcrypto.dylib /usr/local/opt/openssl/lib/libssl.dylib

 # 重新编译sudo make cleansudo make

【报错3】

Undefined symbols for architecture x86_64:

  "_libiconv_open", referenced from:
      _do_convert in gdkanji.o
      _convert in encodings.o
  "_libiconv", referenced from:
      _do_convert in gdkanji.o
      _convert in encodings.o
  "_libiconv_close", referenced from:
      _do_convert in gdkanji.o
      _convert in encodings.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1

 【分析】

Makefile中有两个 -liconv,于是想到,会不会在系统中存在两份不同的 libiconv 呢,果然,系统本身 和 brew(或自己编译)各有一份iconv:

$ nm /usr/lib/libiconv.dylib | grep iconv

00000000000f1af0 S ___iconv_2VersionNumber
00000000000f1b90 S ___iconv_2VersionString
00000000000f60f0 D __libiconv_version
000000000000a1e1 T _iconv
000000000000a5a0 T _iconv_canonicalize
0000000000013164 T _iconv_close 0000000000013171 T _iconv_open
000000000000a72c T _iconvctl
000000000000a20f T _iconvlist
0000000000014dbd T _libiconv_relocate
0000000000014cff T _libiconv_set_relocation_prefix

$ nm /usr/local/lib/libiconv.dylib | grep iconv

00000000000f90c0 D __libiconv_version
0000000000002f10 T _iconv_canonicalize
0000000000002650 T _libiconv
0000000000002680 T _libiconv_close
00000000000011d0 T _libiconv_open
0000000000002690 T _libiconv_open_into
0000000000017970 t _libiconv_relocate
00000000000fa7a8 b _libiconv_relocate.initialized.b
00000000000178b0 T _libiconv_set_relocation_prefix
0000000000002bc0 T _libiconvctl
0000000000002d00 T _libiconvlist

所以就导致了–with-iconv-dir 无论配置成哪一个都链接不成功。

解决

最终的解决方案是直接修改Makefile,把里面的 两个-liconv分别替换成 /usr/lib/libiconv.dylib, /usr/local/lib/libiconv.dylib。使用绝对路径之后,这个链接就没有问题了。

EXTRA_LIBS =  -lz -lresolv  -lintl -lpng -lz -ljpeg  -lcurl -lbz2 -lz -lm -lxml2 -lz -licucore -lm -lcurl -lxml2 -lz -licucore -lm -lfreetype -lz -lbz2 -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm /usr/local/opt/openssl/lib/libcrypto.dylib /usr/local/opt/openssl/lib/libssl.dylib /usr/lib/libiconv.dylib /usr/local/lib/libiconv.dylib 

 # 重新编译sudo make cleansudo make

报错4

"_mcrypt_enc_get_algorithms_name", referenced from:

      _zif_mcrypt_get_cipher_name in mcrypt.o
    ......

解决

(1)、安装 mcrypt

brew install libmcrypt

(2)、修改 Makefile 文件,追加 libmcrypt 库的完整路径 /usr/local/lib/libmcrypt.dylib

EXTRA_LIBS =  -lz -lresolv  -lintl -lpng -lz -ljpeg  -lcurl -lbz2 -lz -lm -lxml2 -lz -licucore -lm -lcurl -lxml2 -lz -licucore -lm -lfreetype -lz -lbz2 -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm /usr/local/lib/libmcrypt.dylib /usr/local/opt/openssl/lib/libcrypto.dylib /usr/local/opt/openssl/lib/libssl.dylib /usr/lib/libiconv.dylib /usr/local/lib/libiconv.dylib 

 

终于没报错,继续安装,需要 sudo 一下获得权限

 # 重新编译sudo make cleansudo makesudo make install

 

4、通过以下指令 启动 和 停止 php-fpm

# 启动 php-fpmphp-fpm -D# 关闭 php-fpmkillall php-fpm

 

注意:php-fpm.conf 中的 用户名 及 用户组 配置为当前用户,即  jianbaostaff

 

延伸阅读:

 

 

参考

转载地址:http://lhxao.baihongyu.com/

你可能感兴趣的文章
2015下半年中项-yuansy-10月15日作业
查看>>
JQuery 1.4.2 'index.html'跨站脚本漏洞
查看>>
我的友情链接
查看>>
云计算IDC未来的四个发展阶段
查看>>
CentOS 系统自动化安装
查看>>
美国当地做seo优化工资,做一样的事情,区别这么大
查看>>
Flex_Gird列表信息源码
查看>>
桌面小部件 widget
查看>>
text-overflow
查看>>
Dns服务的简单配置
查看>>
浏览器兼容--input标签
查看>>
C# 语言规范
查看>>
用Nagios监控AIX
查看>>
【源码学习】time.Timer 和 time.Ticker
查看>>
spring-mvc restful web services
查看>>
我的友情链接
查看>>
java多线程详解
查看>>
测试用例的设计心得
查看>>
Q9头
查看>>
Android中讯飞语音云开发环境搭建
查看>>