如何在OS X 10.9上使用OpenSSL编译PHP?

时间:2015-06-24 10:33:54

标签: php openssl homebrew osx-mavericks

我正在尝试从源代码编译PHP 5.6.10,我遇到了以下问题:

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

OpenSSL通过Brew安装。在PHP中包括--with-openssl=/usr/local/Cellar/openssl/1.0.2c

P.S。 在尝试仅使用/usr进行OpenSSL之前,却遇到了同样的错误。

3 个答案:

答案 0 :(得分:9)

Makefile有一行EXTRA_LIBS,如:

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

删除所有-lssl-lcrypto,并添加libssl.dyliblibcrypto.dylib 的完整路径(brew链接openssl到/ usr / local / opt /的OpenSSL / LIB /)

EXTRA_LIBS = -lresolv -lmcrypt /usr/local/opt/openssl/lib/libssl.dylib /usr/local/opt/openssl/lib/libcrypto.dylib -lltdl -liconv-lm -lxml2 -lcurl

答案 1 :(得分:3)

要跟进Bob Fanger的回答(这对我来说非常适合我在os x 10.11.3上),这里有一个小脚本,你可以在构建目录中运行,使Makefile发生变化: / p>

#!/usr/bin/php
<?php
if (true != copy('Makefile', 'Makefile.sav'))
    die("** cannot copy 'Makefile' to 'Makefile.sav'\n");
$lines = file('Makefile');
if (false == $lines)
    die("** connot read 'Makefile'\n");
$output = fopen('Makefile', 'wb');
if (false == $output)
    die("** unable to open 'Makefile'\n");
foreach ($lines as $line) {
    if (preg_match('/^EXTRA_LIBS\s+=\s+/', $line)) {
        $line = preg_replace('/^EXTRA_LIBS\s+=\s+/', 'EXTRA_LIBS = /usr/local/opt/openssl/lib/libssl.dylib /usr/local/opt/openssl/lib/libcrypto.dylib', $line);
        $line = preg_replace(['/-lssl/', '/-lcrypto/'], [], $line);
    }
    if (false === fwrite($output, $line))
        die("** writing line to 'Makefile' failed\n");
}
fclose($output);
echo "Success - your Makefile is set for ssl\n";

享受!

答案 2 :(得分:0)

如果您在OSX El Capitan上使用phpbrew,则需要提供openssl的完整路径:

phpbrew install php-7.0.4 +openssl=/usr/local/Cellar/openssl/[YOUR OPEN SSL VERSION]