Skip to content

Instantly share code, notes, and snippets.

@robertrossmann
Last active August 29, 2015 14:13
Show Gist options
  • Save robertrossmann/ab7eb28f039c020ecfd9 to your computer and use it in GitHub Desktop.
Save robertrossmann/ab7eb28f039c020ecfd9 to your computer and use it in GitHub Desktop.
PHP - Compiling with Brew support

Usage

If you have another version installed in the Brew's Cellar directory, make sure to brew unlink php it and possibly also delete the version folder.

Then, simply download the latest version of PHP source and run the configure command below, then continue as usual with make && make install. Afterwards, activate the installation by brew link php.

Note: You will need to install any pecl extensions (like xdebug) again after this procedure.

Apache?

Nope - I do not use PHP with Apache. If you require this add relevant configuration to the configure command below as needed.

Install required Brew packages

If you wish to use the openssl version provided by OS X (which is outdated, mind you!) simply remove the path from the command below.

brew install \
gettext \
libedit \
mcrypt \
openssl

Configure:

The command in the prefix extracts the current PHP version from the NEWS file and uses it as a subdirectory of the installation (as Brew expects).

./configure \
--prefix=/usr/local/Cellar/php/$(head -n 3 NEWS | tail -n 1 | tr " " "\n" | tail -n 1) \
--with-config-file-path=/usr/local/etc \
--enable-cli \
--enable-exif \
--enable-maintainer-zts \
--enable-mbregex \
--enable-mbstring \
--enable-pcntl \
--enable-zip \
--with-bz2=shared \
--with-curl=shared \
--with-gettext=shared,/usr/local/opt/gettext \
--with-kerberos=shared \
--with-ldap-sasl \
--with-ldap=shared \
--with-libedit=shared,/usr/local/opt/libedit \
--with-mcrypt=shared,/usr/local/opt/mcrypt \
--with-mysqli=mysqlnd \
--with-openssl=shared,/usr/local/opt/openssl \
--with-pdo-mysql=mysqlnd \
--with-snmp=shared \
--with-tidy=shared \
--with-xsl=shared \
--with-zlib=shared

php.ini - Extensions

You can generate a list of installed PHP extensions using this command:

find `php-config --extension-dir` -name "*.so" | sed 's!^.*/!extension=!'

The first part is simply a find within the PHP extensions directory. Because find prints the full path to the found files to output, the second part removes the path to the extensions directory from it and replaces it with extension=, so it can be copy/pasted directly into php.ini:

extension=module_name.so
...

Composer:

Make sure you have PHP and its extensions configured properly before installing Composer.

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment