Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Compile PHP for OS X
# Script to download & compile PHP for os x (restoration of a custom PHP installation after a system update)
# author: Michael Bianco <>
# References:
# you'll have to aquire a new URL here: when a new version of PHP comes out
wget "${PHP_VERSION}.tar.gz"
tar -xzf php-${PHP_VERSION}.tar.gz
rm php-${PHP_VERSION}.tar.gz
cd php-${PHP_VERSION}
# strip the 64 bit version of apache in order to eliminate compatibility issues with 32 bit PHP
sudo lipo /usr/sbin/httpd -thin i386 -output /usr/sbin/httpd
# install some modules
sudo port install libpng && sudo port install jpeg && sudo port install freetype && sudo port install gd2
# compile and install PHP
./configure --prefix=/usr --sysconfdir=/private/etc --with-libxml-dir=/opt/local --with-iconv=/opt/local/ --with-config-file-path=/etc --mandir=/usr/share/man --infodir=/usr/share/info --with-apxs2=/usr/sbin/apxs --with-zlib-dir=/usr --with-mysql-sock=/var/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-dblib=/opt/local --with-mysql=/usr/local/mysql --with-pear --with-pdo-mysql=/usr/local/mysql/bin/mysql_config --enable-sockets --enable-exif --enable-wddx --enable-ftp --enable-cli --enable-mbstring --enable-mbregex --enable-sockets --with-curl --with-sqlite --enable-soap --with-libxml-dir=/usr --with-readline=/opt/local
# have to search / replace the following:
# not sure if sed actually replaces the file so the text that actually needs to be replaced is shown below
make && sudo make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment