Skip to main content

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 and unpack it so you can work with the sources.
Then just execute:
./Configure shared darwin64-x86_64-cc
make depend
sudo make install


Download the latest PHP 7 source code from 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/ \
--with-openssl=/usr/local/ssl \
--with-curl \
--with-gd \
--with-libedit \
--with-mcrypt=/usr/local/bin \
--with-mysqli \
--with-zlib \
--with-pdo-mysql \
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!
Edit PHP's Makefile and find the line that begins with EXTRA_LIBS. In this line, replace the following references -lcrypto with /usr/local/ssl/lib/libcrypto.dylib and -lssl with /usr/local/ssl/lib/libssl.dylibor where you have installed the latest OpenSSL library.
A convenient way is to use vi and use :s/\-lcrypto/\usr\/local\/ssl\/lib\/libcrypto.dylib/g to immediately replace all instances of -lcrypto in the line. Do the same for -lssl as well.
Once done, just execute makemake test and sudo make install to 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 -v you 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.
In /etc/apache/httpd.conf find the following line:
LoadModule php5_module libexec/apache2/
And comment it out, as we're no longer use php 5, like this:
#LoadModule php5_module libexec/apache2/
Locate the line:
#LoadModule php7_module        libexec/apache2/
And remove the comment hash (#) in front of it
LoadModule php7_module        libexec/apache2/
Restart apache with sudo /usr/sbin/apachectl restart
Now put the following file (info.php) in your document root (see /etc/apache/httpd.conf where this is)
>?php phpinfo();
And point your browser to that file on your local machine, in my case it is http://localhost/info.php.
PHP 7.0.8 running on "El Capitain"

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.


Popular posts from this blog

Speeding up database calls with PDO and iterators

When you review lots of code, you often wonder why things were written the way they were. Especially when making expensive calls to a database, I still see things that could and should be improved.
No framework development When working with a framework, mostly these database calls are optimized for the developer and abstract the complex logic to improve and optimize the retrieval and usage of data. But then developers need to build something without a framework and end up using the basics of PHP in a sub-optimal way.

$pdo = new \PDO( $config['db']['dsn'], $config['db']['username'], $config['db']['password'] ); $sql = 'SELECT * FROM `gen_contact` ORDER BY `contact_modified` DESC'; $stmt = $pdo->prepare($sql); $stmt->execute(); $data = $stmt->fetchAll(\PDO::FETCH_OBJ); echo 'Getting the contacts that changed the last 3 months' . PHP_EOL; foreach ($data as $row) { $dt = new \DateTime('2015-04-…

Deploy Docker containers fast to Microsoft Azure

DEPLOY DOCKER CONTAINERS FAST TO MICROSOFT AZURE It’s hard to ignore the fact thatDockeris a way to move forward for rapid application development, distributed architectures and microservices. For developersDockeroffers great advantages as they can build their containers specifically for the task they work on. They grab a base image of a container, modify it for their purpose and prepare the functionality inside the container. Quality, testing and security teams now have a single instance to look at and ensure all functional and regulatory requirements are met. System engineers now don’t have to worry about providing a system with the required specs as the container is already provisioned for that purpose. But where do you deploy yourDockercontainers? You can set up your existing bare metal infrastructure to allow them to run containers, but this also means you need to learn about securing your container infrastructure, which is not an easy task. Luckily “the cloud” offers container …

PHP Arrays - Associative Arrays or Hash Maps

Associative array or hash maps are listings of key and value pairs with a posibility to nest additional keys and values. An associative array is a very powerful construct within PHP.

In our previous article we discussed simple arrays, which in their turn are indexed associative arrays under the hood. Take the following example:

$array = [

Is in fact an indexed associative array under the hood:

$array = [
0 => 'apple',
1 => 'banana',
2 => 'chocolate',

But associative arrays can be so much more than just an indexed array, and you will find many database operations returning arrays where the fields of a table are the keys in the array while their values are also the values within the array.

$productRowData = [
'product_id' => 1234,
'brand_id' => 321,
'product_name' => 'Our awesome product',
'prodcut_description' => 'This is our most awesome product.&#…