Upgrading PHP from version 5.3 to 5.4.7

Quickly so to speak I have noticed this topic around, I have searched and there are plenty of solutions. However these solutions do not work for me, not only that but I'm intending to learn more about the Debian based OS.

Questions

  1. I would like to know how to upgrade PHP 5.3 to PHP 5.4.7 compiling it from source myself without using a third-party PPA.
  2. Is the way (explained below) the correct way of configuring PHP 5.4? I'm new to compiling from source.

Set-up

I run Ubuntu Server 12.04 64-bit. I've currently got:

  • PHP 5.3
  • MySQL-Server
  • Apache2
  • Memcached

The Problem

I initially installed PHP 5.3 using apt-get. I now wish to upgrade to PHP 5.4 due to the advantage of traits in OOP and the struct with arrays and all the other recent patches and such.

Possible Solutions

I've seen this ondrej/ppa repository, which I refuse to use, given the fact that it may work, but it's an unknown/untrusted source. Also, I'm not learning how to administer from source, using configure, make and install accordingly.

I've seen a solution compiling from source, which is essentially how I was hoping to go about it with some guidance.

Conclusion

I didn't just expect to be spoon-fed and I went out and did some manual reading and at least started the ball rolling myself; this is how far I've got.

The first thing I did was su into root (to save typing sudo all the darn time).

$ sudo su

The next thing I did was download the latest version of PHP (5.4.7) and extracted its' contents ready to configure before installing it.

$ mkdir php5-new && cd !$
$ wget -O php-5.4.7.tar.bz2 http://php.net/get/php-5.4.7.tar.bz2/from/uk3.php.net/mirror
$ bzip2 -d php-5.4.7.tar.bz2
$ tar xvf php-5.4.7.tar.gz
$ cd php-5.4.7
$ ./configure --help

Finally I decided to have a bash, I looked through the list of options and decided I needed to list ALL of the things I wanted to include in the configuration.

$ ./configure --with-mysql --with-apache2 --with-libxml --with-openssl --with-zlib --with-bz2 --with-curl --with-dom --with-gd --with-imap --with-imap-ssl --with-mcrypt --with-mysqli --with-pdo-mysql --with-libxml --enable-ftp --enable-mbstring --enable-soap

Finally, the results...

When the configuration process had finished, it threw an error:

configure: error: xml2-config not found. Please check your libxml2 installation.


Progress Update (Solution)

The accepted answer turns out to be the solution. For anyone who may bump into this question in the future, I'll add a few additional tips (extending what "Ladadadada" stated below).

I bumped into another issue with OpenSSL, so I had to install the dev libraries; I did this using:

$ apt-cache search openssl | grep dev
$ apt-get install libssl-dev
$ dpkg -L openssl

Then I set --with-openssl=/usr/includes/openssl which moaned about an evp.h. I tried to locate this file using find / -type f -name evp.h and discovered it inside the /usr/includes/openssl/evp.h directory and so I again removed =/usr/includes/openssl.


You will likely need to install libxml2-dev via apt-get install libxml2-dev and then try again. This will install all the header files and other dev tools for this library. It's quite possible that this is necessary for other modules as well.

This is one of the reasons that it's a much better idea to install from binary packages and not clutter your production system with these unecessary packages. Also, to learn how to compile your own binaries, you shouldn't use a production system.


You seem to have --with-libxml twice in your configure line. Probably doesn't matter but it's best to remove the extra one.

Besides that, do you have libxml2 installed? You will need that. If you do have it installed, where is it? If it's not under /usr/lib/ (say, it's under /opt/ instead) then you will need to specify the path to it using --with-libxml=/path/to/libxml2.

It's important to completely remove the old version of PHP using apt-get purge before attempting to compile your own version. Failing to do this often ends up leaving two different versions of PHP on your system under two different paths and some difficult-to-debug problems. It's also good practice to build a .deb of your compiled PHP and install that, even if it's only for a single system and you aren't going to bother with dependencies, simply because it makes uninstalling it later on that much easier. Uninstalling a compiled package like this is about the same amount of effort as building a .deb so you might as well do it.

Make sure you also understand the differences between the CLI, CGI and Apache-module versions of PHP. With Debian-based distros these all have separate php.ini files. Make sure you uninstall all of those and compile the correct one for how you are running PHP.