Posts Tagged ‘Install (Compile) PHP5 from deb source to increase php performance on Debian Lenny Linux / Install php from source the debian way’

Install (Compile) PHP5 from deb source to increase php performance on Debian Lenny Linux / Install php from source the debian way

Saturday, March 19th, 2011

If you’re looking for one further way to increase your Apache+PHP performance. You should definitely think about recompiling the lib php from the php’s source code.
Building from source your php library is a great way to decrease your php scripts execution time and therefore increase the responce time of your webserver server.
Recompiling will speed up your websites and make the user feel more interactivity when using them.

Of course there are two ways to go to compile a php library on your node. One is to install it directly downloading the latest source from php.net which if you’re on a Debian Linux platform is not recommended and the other method is to use the debian provided source bundled package (e.g. deb package) – the recommended one

As I prefer to do my system installs the straight debian way I choose the path to build and install the php library from a previously prepared version with build scripts for Debian, (e.g. to compile and install the php library from source the debian way.)

Here is exactly what commands you need to issue to properly build a php library from the php sources;
First you need to install the pre-requirement packages which will be further necessary for the php library compliation;

1. Install the build-essential debhelper and fakeroot through apt debian:~# apt-get install build-essential debhelper fakeroot

If you have the above 3 packages already installed you can skip further to the next step.

2. Use apt-get to fetch all the required libraries and programs necessary for the php compilation

debian:~# apt-get build-dep php5

The build-dep apt option causes apt-get to install/remove packages in an attempt to satisfy the build dependencies for a source package.

3. Download the php5 source code with apt-get debian:~# cd /usr/src/
debian:~# apt-get source php5

After the completion of apt-get source php5, you should have the php5 programming language source code, stored in /usr/src;

The files which should reside in /usr/src are:

php5_5.2.6.dfsg.1-1+lenny9.diff.gz
php5_5.2.6.dfsg.1-1+lenny9.dsc
php5_5.2.6.dfsg.1.orig.tar.gz

apt-get source php5 command will also extract the php from php5_5.2.6.dfsg.1.orig.tar.gz and apply the php5_5.2.6.dfsg.1-1+lenny9.diff.gz patch file.

4.cd to the php directory;

debian:~# cd php5-5.2.6.dfsg.1/

5. Now let’s compile the php library the debian way

debian:~# dpkg-buildpackage -rfakeroot
....

Now go and make yourself a coffee and have a cigarette if you’re a smoker. In about 10/20 minutes (depending on your computer CPU) your php should have been built.

You should have the php packages now built, if you get any error messages, don’t blame me. Blame Microsoft! 🙂

6. Switch back one directory back

debian:~# cd ../

You should have the following debian packages built and ready to be installed;

libapache2-mod-php5_5.2.6.dfsg.1-1+lenny9_amd64.deb
libapache2-mod-php5filter_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5_5.2.6.dfsg.1-1+lenny9_all.deb
php5-cgi_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-cli_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-common_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-curl_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-dbg_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-dev_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-gd_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-gmp_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-imap_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-interbase_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-ldap_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-mcrypt_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-mhash_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-mysql_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-odbc_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-pgsql_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-pspell_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-recode_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-snmp_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-sqlite_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-sybase_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-tidy_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-xmlrpc_5.2.6.dfsg.1-1+lenny9_amd64.deb
php5-xsl_5.2.6.dfsg.1-1+lenny9_amd64.deb
php-pear_5.2.6.dfsg.1-1+lenny9_all.deb

7. Install the newly built php libraries

debian:/usr/src# for i in *.deb; do dpkg -i $i; done

Now if you need something to be configured in the way your apache interprets php scripts go and edit your /etc/php5/apache2/php.ini

Now as you should have installed and configured your libapache2-mod-php5 from source, the last thing to do before you can benefit from the improved performance is to restart apache.
8. Restart Apache server

debian:~# /etc/init.d/apache2 restart

I hope my article is helpful to somebody. If it works for you or it doesn’t give me your feedback 😉