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

Saturday, 19th March 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 😉

Share this on:

More helpful Articles

Download PDFDownload PDF

Tags:

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

  1. Marco says:
    Firefox 5.0.1 Firefox 5.0.1 Mac OS X 10.6 Mac OS X 10.6
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0.1) Gecko/20100101 Firefox/5.0.1

    Hi! but why should performance improve? The precompiled package is not debian-optimized?

    View CommentView Comment
    • admin says:
      Firefox 5.0 Firefox 5.0 GNU/Linux GNU/Linux
      Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20100101 Firefox/5.0

      Hi Marco,

      What do you mean Debian-optimized? I don’t know the package mainainer to do anything specific on the package when compiling it.
      The good thing is that when you compile the php package from source its optimized to run on the platform where compiling and it in many cases it can take advantage of using more CPU instructions specific to the computer arch where compiled. Maybe testing however can tell for sure.

      Best!
      Georgi

      View CommentView Comment
  2. Hildred Molitor says:
    Firefox 3.0.14 Firefox 3.0.14 Windows XP Windows XP
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.14) Gecko/2009082707 Firefox/3.0.14 (.NET CLR 3.5.30729)

    just the job thanks

    View CommentView Comment
  3. Yarik Dot says:
    Google Chrome 47.0.2526.80 Google Chrome 47.0.2526.80 Windows 7 x64 Edition Windows 7 x64 Edition
    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36

    What is the real performance increase? I guess 0,00 nothing.

    View CommentView Comment

Leave a Reply

CommentLuv badge