Uninstall PHP
Easily done (P.S. uninstalling is always the easy bit)
sudo apt-get remove php5-* sudo apt-get purge php5-*
Get PHP
Simple head here to pick the version of PHP you want. I got version 5.6.11 (latest one at the time)
wget -P ~ http://uk1.php.net/distributions/php-5.6.11.tar.gz
(replace url with url of preferred php install)
Fulfill all the dependencies
One thing I have learnt while doing the configure;make;make install process is that not having all the dependencies can be a real bummer. So you would want to make sure you have got them all.
You can check for the dependency list here. Also make sure that the dependency versions you install are compatible with those mentioned in the list.
This is the command to install all the dependencies needed:
sudo apt-get install \ libxml2-dev \ libcurl4-openssl-dev \ libjpeg-dev \ libpng-dev \ libxpm-dev \ libmysqlclient-dev \ libpq-dev \ libicu-dev \ libfreetype6-dev \ libldap2-dev \ libxslt-dev \ libreadline6-dev \ libmcrypt-dev \ autoconf \ automake \ libtool \ re2c \ bison
Installation:
If you have ever done any installation by compiling from source and suddenly you wish to uninstall the application then you would know it can be a real painstaking process to get the application out. If we had installed via APT, a simple apt-get purge/remove would have done the trick but no such luck for source installs.
To uninstall you would have to manually delete all the files and folders created by the installation process and God help you if you do not remember where they all were. (P.S. by default, the make installation method usually uses the /usr/local/ directory)
In view of this we would be using stow. Stow manages this whole process by giving a common tree where all the files get installed and then when you are ready it creates a symlink from the stow directory to the target tree i.e. /usr/local/.
To install stow (we would not be building it from source *sigh*)
sudo apt-get install stow
You should now have a /usr/local/stow directory. Now we can get on with our installation.
Extract the tarball
cd ~ tar -xvJf php-5.6.11.tar.gz cd ~/php-5.6.11/
Next we configure, this was my configuration command (Note you should run this as a regular user and not sudo)
./configure \ --prefix=/usr/local/ \ --with-apxs2=/usr/bin/apxs \ --enable-mbstring \ --with-curl \ --with-openssl \ --with-xmlrpc \ --enable-soap \ --enable-zip \
--enable-sockets \ --enable-opcache \ --enable-pcntl \ --with-pdo-mysql \ --with-pdo-pgsql \ --with-readline \ --enable-zip \ --enable-mysqlnd \ --with-pear \ --with-gd \ --with-mcrypt \ --with-jpeg-dir \ --with-png-dir \ --with-mysql \ --with-pgsql \ --enable-embedded-mysqli \ --with-freetype-dir \ --enable-intl \ --enable-maintainer-zts \ --with-xsl \ --with-config-file-scan-dir=/usr/local/lib/php/conf.d
Now we can run :
make
and finally
sudo make install prefix=/usr/local/stow/php56
When this is done, the directory /usr/local/stow/php56 would not contain all our php installation files.
Now we 'stow' it:
cd /usr/local/stow sudo stow php56and tada
php -v PHP 5.6.11 (cli) (built: Aug 4 2015 02:48:50) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend TechnologiesAnd it's a wrap!