Friday, December 23, 2011

Compiling php 5.3.7 with FPM on mac osx lion

My work machine is a new MBP 13 with mac osX lion. This machine had php 5.x installed in factory but I wanted to compile the latest PHP (5.3.x). Here are the required steps. One thing you have to be aware of is that pre-requisites may vary depending on what all module you want to bake in. I wanted mcrypt and GD2. GD2 has dependency on libpng and libjpeg. Also, I wanted to use mysql native driver.
Before compiling set the compiler flags to be 64 bit x86. Download required libraries (libmcrypt, libpng, libjpeg) from respective sites and do a configure make sequence.

Install dependencies
  • php-5.3.7.tar.gz
  • libmcrypt-2.5.8.tar.gz
  • libpng-1.5.4.tar.gz
  • jpegsrc.v8c.tar.tar.gz
Use following information to compile and install our dependencies
  CFLAGS="-arch x86_64"   
 echo $CFLAGS   
 ./configure --prefix=/usr/local make make install  
mysql was already installed on mac osx lion and I went with the default install of mysql. After compiling and installing the dependencies we compile PHP tar ball. Note that we supply required library paths to configure script. Use the --enable-fpm switch to enable baking in FPM module.

  ./configure --prefix=/usr/local --enable-fpm --with-mysql=mysqlnd   
 --with-mysqli=mysqlnd --with-openssl --with-pcre-regex --with-mhash   
 --with-curl --with-mcrypt=/usr/local/lib --with-gd   
 --with-png-dir=/usr/local --with-jpeg-dir=/usr/local

After successful install, check modules using $php -m. CLI, CGI, JSON etc. are default with 5.3.7 source bundle. install nginx from source. Nginx normally has only one dependency, PCRE. Now both nginx and php with fpm are installed.

 PHP layout

After successful install, PHP executable will be in /usr/local/bin and php.ini is in /usr/local/lib. php-fpm is in /usr/local/sbin and php-fpm config files are in /usr/local/etc

Start/stop NGINX, php-fpm and mysql
  sudo /usr/local/sbin/nginx -- to start nginx 
sudo /usr/local/sbin/nginx -s stop -- to stop nginx 
sudo /usr/local/sbin/php-fpm to start fpm 
sudo kill `cat /usr/local/var/run/php-fpm.pid` to kill fpm 
sudo /usr/local/mysql/bin/mysqld_safe to start mysql
© Life of a third world developer
Maira Gall