Last time we went through steps needed for setting up apache. Now we will set up PHP. At the time of writing, the current stable release is 5.2.13. Yes, I’m compiling 5.2.x branch of PHP, because 5.3.x is still not well adopted among hosting providers. I’ll describe how to run multiple PHP versions at some later tutorial.
Download and prepare
First few steps are practically the same as for the apache. Download the source and check md5.
md5sum php-5.2.13.tar.gz | grep cdf95cdc1ebccccce9c96653fd593dd4
Extract the archive.
tar xzf php-5.2.13.tar.gz
Go into the extracted directory.
cd php-5.2.13
Configure for compiling
./configure \
--prefix=/usr/local/php5.2.13 \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php5.2.13/conf \
--enable-cli \
--with-pear=/usr/local/pear \
--with-openssl=/usr \
--with-iconv \
--with-curl \
--with-mysql \
--with-mysqli \
--enable-mbstring \
--enable-exif \
--with-jpeg-dir \
--with-zlib \
--with-zlib-dir \
--with-png-dir \
--with-gd \
--with-gettext \
--enable-gd-native-ttf \
--with-mhash \
--with-pspell \
--with-mcrypt \
--enable-bcmath \
--with-mime-magic \
--with-pdo-mysql \
--enable-sockets \
--enable-soap
You don’t need all of these extras, they just might be useful to you. Some of the more important ones are:
–prefix=… sets the location of the PHP installation.
–with-apxs2=… sets the location of the apxs binary of the apache. Adjust accordinally.
–with-config-file-path=… sets the location of the php.ini configuration file. I just set it so it is more clear where the .ini file will be.
–enable-cli wether or not you want to use php from the command line.
You can read more about the configuration options in the PHP manual.
http://php.net/manual/en/configure.php
Compile
make
If this error occures while doing “make” -> “/usr/bin/ld: cannot find -lltdl collect2: ld returned 1 exit status”, just install the libltdl-dev package. Should be something similar for other linux distributions.
sudo apt-get install libltdl-dev
It is a good practice to run tests and report any possible bugs by running this command. It however is not mandatory to run it.
make test
This might take a while. After tests are through, there might be a fail or two, so you can decide if you want to report those or not.
Let’s go on and install it. This command must be run as super user.
sudo make install
Configure
Now we have to copy the php.ini to appropriate directory.
sudo cp php.ini-recommended /usr/local/php5.2.13/conf/php.ini
Next, we configure apache to handle our PHP scripts.
sudo gedit /usr/local/apache2/conf/httpd.conf
Find a line which starts with AddType and add this below.
AddType application/x-httpd-php .php
Than in line which starts with DirectoryIndex add this.
index.php
Save the file and restart apache.
sudo /usr/local/apache2/bin/apachectl -k restart
Test
Go to your documents root directory. In previous tutorial we used /var/www directory for this.
In this directory create a file named test.php and put this in it:
<?php phpinfo(); ?>
Now go to http://localhost/test.php
If you see a lot of data about your PHP installation, you have succeeded.
Enjoy!
Update: This tutorial also applies for PHP 5.2.14.


