繁体   English   中英

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

[英]How to compile PHP with OpenSSL on OS X 10.9?

我正在尝试从源代码编译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

PS之前尝试使用/usr进行OpenSSL但得到了同样的错误。

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

为了跟进Bob Fanger的答案(在os x 10.11.3上我完全适合我),这里有一个小脚本,你可以在build目录中运行,使Makefile发生变化:

#!/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";

请享用!

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM