How to compile PHP with OpenSSL on OS X 10.9?

与世无争的帅哥 提交于 2019-12-05 05:14:10

The Makefile has a line with EXTRA_LIBS, something like:

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

Remove all occurrences of -lssl and -lcrypto and add the full path to libssl.dylib and libcrypto.dylib (brew links openssl to /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

To follow up on Bob Fanger's answer (which worked perfectly for me on os x 10.11.3), here's a little script you can run from within the build directory that makes the Makefile changes:

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

Enjoy!

if you're using phpbrew on OSX El Capitan you need to provide the full path of your openssl:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!