Installing PHP 5.5.12 with PHP-FPM for a Nginx 1.7.4 server
Most of the PHP developers use PHP module enabled servers very often in their development process. So here I am trying to use a different approach to run PHP code. For this, you should have a nginx installed and if you have not one you can install by following my previous article about installing nginx or Nginx Wiki install page.
1) First, you have to create two directories as following
2) Then you have to install following dependencies if you do not have them already
sudo apt-get install libxml2-dev mcrypt libmcrypt-dev libpng-dev libjpeg-dev
3) After that, you should obtain php source as follows
4) Unpack the source
tar -xzvf php-5.5.12.tar.gz
5) Then you can configure the source
./configure --prefix=/home/<user>/servers/php --enable-fpm --with-fpm-user=<user> --with-fpm-group=<user> --enable-mbstring --enable-sockets --enable-zip --with-mysql --with-mysqli --with-pdo-mysql --with-mcrypt --with-openssl --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-zlib-dir --with-curl --enable-gd-native-ttf --enable-bcmath
Note that here we used prefix flag to specify the installation path when configuring the php. If you configure without this flag the default installation path for php is /usr/local/php/. When configure you may get some errors about required dependencies for installation. As an example OpenSSL. So you have to install them also as we did earlier.
apt-get install OpenSSL
6) After that move configuration files using following commands
cp php.ini-development ~/servers/php/lib/php.ini
cp ~/servers/php/etc/php-fpm.conf.default ~/servers/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm ~/servers/php/sbin/
7) Change the permission of the init.d.php-fpm as below
chmod +x ~/servers/php/sbin/init.d.php-fpm
After completing those steps you can start and stop php-fpm using following commands.
start - ~/servers/php/sbin/init.d.php-fpm start
stop - ~/servers/php/sbin/init.d.php-fpm stop