compile php with openssl on mac osx error

从源码手动编译 PHP 时出现如下错误:

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: *** [libs/libphp5.bundle] Error 1

解决办法

MakeFile 里面找到类似下面这一行:

EXTRA_LIBS = -lresolv -lmcrypt -lltdl -liconv-lm -lxml2 -lcurl -lssl -lcrypto

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

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

EXTRA_LIBS = -lz -lresolv -lmcrypt -lltdl -lstdc++ -liconv -liconv -lpng -lz -lcurl -lz -lm -lxml2 -lz -licucore -lm -lcurl -lxml2 -lz -licucore -lm -licui18n -licuuc -licudata -licuio -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm /usr/local/opt/openssl/lib/libssl.dylib /usr/local/opt/openssl/lib/libcrypto.dylib

 

Ubuntu Server 14.04 编译安装 PHP

每次编译安装 PHP 过程中出现了一些错误,都是直接谷歌相应的解决方案。刚才又在 Linode 上编译了一遍最新的 PHP,记录过程如下,以做备忘。

首先安装 build-essential 包:

apt-get install build-essential

进入 php 源码目录,我的 configure 命令选项如下:

./configure --with-bz2 --with-curl --with-jpeg-dir --with-gd --enable-shared --enable-mbstring --with-mcrypt --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-fpm --enable-phar --enable-bcmath --with-zlib --enable-zip --enable-ftp --with-gettext --enable-sockets --with-freetype-dir --with-fpm-user=www-data --with-fpm-group=www-data --with-config-file-path=/usr/local/etc/php/php.ini --with-config-file-scan-dir=/usr/local/etc/php/conf.d

配置过程中,会出现若干错误,提示各种头文件找不到,下面分别给出错误提示和对应的需要安装的包:

#Cannot find libz
apt-get install zlib1g-dev

#Please reinstall the BZip2 distribution
apt-get install libbz2-dev

#Please reinstall the libcurl distribution -
#    easy.h should be in <curl-dir>/include/curl/
apt-get install libcurl4-gnutls-dev

#jpeglib.h not found
apt-get install libjpeg-dev

#png.h not found
apt-get install libpng12-dev

#freetype-config not found
apt-get install libfreetype6-dev

#mcrypt.h not found. Please reinstall libmcrypt
apt-get install libmcrypt-dev

直到没有错误为止。最后:

make && make install

至此编译安装完成。