Compiling PHP 5.3 on Ubuntu 9.10

This guide will outline how to compile PHP 5.3 from source for use with Apache. The instructions in this guide have been tested with Ubuntu 9.10 and should work on other debian based distros. This guide is a slight modification of the video guide on setting up Apache, PHP 5.3 with xdebug, MongoDB, and Lithium created by Jon Adams. Before proceeding with the instructions below you will need Apache installed on your computer. If you do not yet have apache you can follow my guide for setting up Apache on Ubuntu 9.10.

The first step for installing PHP 5.3 is to get the prerequisites. For this guide you will need the following libraries in order to compile php with the options that I use. If you have some custom libraries/extensions that you want included in your build of PHP, now is the time to install them if you haven’t already.

The following command will install the libraries that I will need:

sudo apt-get install libmcrypt-dev libxml2 libxml2-dev libbz2-dev libcurl4-gnutls-dev libjpeg62-dbg libpng12-dev libxslt1-dev libbz2-dev

Once our required libraries have been installed we can go to http://www.php.net/downloads.php and choose to download the latest 5.3.x build in tar.gz format. I chose to copy the download link and use wget to download it to the tmp directory, but you can do whatever you like.

cd /tmp
wget http://ca2.php.net/get/php-5.3.1.tar.gz/from/this/mirror

now untar the file and go into the directory

tar -xvf php-5.3.1.tar.gz
cd php-5.3.1

Now comes the fun part. Here we will run the configure script that says what kind of extensions we want php built with. At the beginning of the tutorial we installed a bunch of libraries (for example libbz2) and because of that we are able to build PHP with support for these libraries by specifying the –with-%library% flag. To see the options available for configuring php type:

./configure --help

You should be fine using what I used below, but feel free to make adjustments as you see fit:

./configure --prefix=/usr --with-config-file-path=/etc/php5/ --with-config-file-scan-dir=/etc/php5/ --with-apxs2=/usr/bin/apxs2 --with-bz2 --with-curl --with-gd --with-iconv --with-mcrypt --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pear --with-xmlrpc --with-xsl --with-zlib --enable-ftp --enable-mbstring --enable-soap --enable-sockets

If all goes well with the configure script you can continue to run the make file:

sudo make -i install

Once the make script is finished running we have to manually create the modules for Apache:

cd /etc/apache2/mods-available
sudo nano php5.load

The contents of this file should be:

LoadModule php5_module /usr/lib/apache2/modules/libphp5.so

Now create the configuration file:

sudo nano php5.conf

with the contents:

<IfModule mod_php5.c>
	AddType application/x-httpd-php .php .phtml .php3
	AddType application/x-httpd-php-source .phps
</IfModule>

Once those two files have been created we can enable the php5 module for Apache, then restart Apache for the new module to load.

sudo a2enmod php5
sudo /etc/init.d/apache2 restart

Now go into your web directory (if you followed my apache guide earlier go to ~/www/sandbox.loc/httpdocs) and create a file called test.php

nano ~/www/sandbox.loc/httpdocs/test.php

with the following contents:

<?php echo phpinfo(); ?>

Now point your web browser to the new file you created. Which should be at http://sandbox.loc/test.php, you should get a phpinfo page if all went according to plan.

You have now successfully installed php 5.3. On the phpinfo page if you scroll down to the date section you will probably see an error saying you have to set your timezone. You can do this with the php.ini file. To ceate the php in file first create the /etc/php5 directory and copy the php.ini-production file included in the php-5.3.1 tar file.

sudo mkdir /etc/php5
sudo cp /tmp/php-5.3.1/php.ini-production /etc/php5/php.ini

Now edit the php.ini file:

sudo nano /etc/php5/php.ini

and find the line beginning with “;date.timezone”, remove the semi-colon and set the value to your desired time zone. There is a list of supported timezones in the PHP manual. For example, I changed mine to:

date.timezone = "America/Edmonton"

You should now be set to start using PHP 5.3 with Apache!

Discussion

There are no comments yet!

Post a comment