Compile PHP 7 on Mac OS X 10.11 "El Capitain"
Apple has made a numerous changes to the way OS X (10.11) "El Capitain" uses open source elements like PHP and OpenSSL. Compiling PHP from source requires a bit more modifications.
This article is a follow-up on my previous post Installing PHP 7 with XDebug, Apache and MySQL on OS X Yosemite
Get the latest OpenSSL from openssl.org and unpack it so you can work with the sources.
Then just execute:
./Configure shared darwin64-x86_64-cc make depend make sudo make install
Download the latest PHP 7 source code from php.net/download and unpack it in a temporarily directory, I like to use /tmp.
My configure command arguments:
./configure \ --prefix=/opt/php7 \ --enable-cli \ --enable-mbstring \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --enable-sockets \ --enable-exif \ --enable-ftp \ --enable-intl \ --enable-soap \ --enable-zip \ --with-apxs2 \ --with-iconv=/usr \ --with-config-file-path=/etc/php7 \ --with-config-file-scan-dir=/etc/php7/ext \ --with-libxml-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/ \ --with-openssl=/usr/local/ssl \ --with-curl \ --with-gd \ --with-libedit \ --with-mcrypt=/usr/local/bin \ --with-mysqli \ --with-zlib \ --with-pdo-mysql \ --with-mysql-sock=/tmp/mysql.sock
This gives me most of the modules and extensions I require for doing my PHP work. For concrete situations I prefer to use virtual machines or Docker containers to mimic the production environment as much as possible, but for small work it's easy to have it running natively on my local machine.
WARNING: Compile OpenSSL instead of using the build-in SSL as it's not compatible!
Makefileand find the line that begins with
EXTRA_LIBS. In this line, replace the following references
/usr/local/ssl/lib/libssl.dylibor where you have installed the latest OpenSSL library.
A convenient way is to use
:s/\-lcrypto/\usr\/local\/ssl\/lib\/libcrypto.dylib/gto immediately replace all instances of
-lcryptoin the line. Do the same for
Once done, just execute
sudo make installto install the latest PHP 7 version on your MacBook.
You might want to replace the build-in php with your new compiled version of PHP.
cd /usr/bin sudo mv php php-orig sudo ln -sf /opt/php7/bin/php php
When you execute
php -vyou should see something like the following:
PHP 7.0.8 (cli) (built: Jul 19 2016 11:36:18) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Xdebug v2.4.0RC2, Copyright (c) 2002-2015, by Derick Rethans
It's nice to have PHP on command line, but you might want to have it run in your apache configuration as well.
If you look at the output of "make install" you will see the line:
[activating module `php7' in /private/etc/apache2/httpd.conf]
This means PHP has modified your apache configuration and included the php7 module, you only need to activate it.
/etc/apache/httpd.conffind the following line:
LoadModule php5_module libexec/apache2/libphp5.so
And comment it out, as we're no longer use php 5, like this:
#LoadModule php5_module libexec/apache2/libphp5.so
Locate the line:
#LoadModule php7_module libexec/apache2/libphp7.so
And remove the comment hash (#) in front of it
LoadModule php7_module libexec/apache2/libphp7.so
Restart apache with
sudo /usr/sbin/apachectl restart
Now put the following file (
info.php) in your document root (see
/etc/apache/httpd.confwhere this is)
And point your browser to that file on your local machine, in my case it is http://localhost/info.php.
You're now ready to unleash the PHP7 power! Have fun and let me know in the comments if it worked out for you. If not, let's work together how we can solve the issue.