簡體   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