Install PHP 5.x from repository on Ubuntu

Install build tool

Here are detailed steps for installing compile tool for ubuntu.

Install dependencies

In most cases quite a lot of dependencies will be missing. You can install most of them using next command

Compile and install PHP

Clone the PHP repository

Choose the version of php you want to compile and install

For building php from git repository, first you have to run sudo ./buildconf .

./buildconf generates the configuration script. This may take several minutes.

 Create the folder where you want to install the php:

 Configure build

Once the ./configure script is generated via the step above, you can use it to customize your PHP build. You can list all supported options using –help:

Compile PHP

Now, you can use make to perform the actual compilation:

 Install PHP

Now you can run “make install” to install PHP into /usr/local (default) or other directories by using the --prefixconfiguration. In this case it’s /opt/php-5.6

Please note that make install will not create an ini file.

 

Copy config files

Open /opt/php-5.6/etc/php-fpm.conf and adjust the settings in the listen line. You must change to an unused port (e.g. 9001)

Init script setup

You will probably want to create an init script for your new php-fpm. Luckily, PHP 5.3+ already provides it for you, simply copy the init script to your directory and change permissions:

1
2
sudo cp /opt/source/php-src/sapi/fpm/init.d.php-fpm /etc/init.d/php5.6-fpm
sudo chmod 755 /etc/init.d/php5.6-fpm

Your init script is ready. Now, you are able to start, stop and reload php-fpm:

1
2
3
sudo /etc/init.d/php5.6-fpm start
sudo /etc/init.d/php5.6-fpm stop
sudo /etc/init.d/php5.6-fpm reload

Create alias for every command: