Compiling PHP from source on Linux OS

Step 1:  Download PHP from source

Go to sourcecode and download

cd /home/sourcecode



tar -zxvf php-5.5.38.tar.gz

cd /home/sourcecode/php-5.5.38

Step 2:

Now we have to configure PHP for compilation process. There are hundreds of options which can be provided to configure script. These options include the option to specify where PHP should be installed, which functionality should be enabled, like functionality to access mysql databases from PHP and which extensions have to be compiled etc. To see a list of options supported by PHP configure, type:

$ ./configure –help

It’ll show a list of all options supported by the version of PHP that you are using.

To compile PHP as Apache shared module we have to provide path to apache apxs utility, which in our case was installed in /home/apache2/bin/ when we installed Apache.

$ ./configure –prefix=/home/apach2/php –with-apxs2=/home/apache2/bin/apxs –with-config-file-path=/home/apache2/php –with-mysql

First option –prefix=/home/apach2/php  we want PHP to be installed in /home/apach2/php directory. Otherwise it’ll be installed in some default location (/usr/local).

Second option –with-apxs2 indicates that we want to install PHP as Apache 2 shared module.

Third option –with-config-file-path specifies that PHP should look for php.ini file in /home/apache2/php directory.

Fourth option –with-mysql enables support to access mysql databases through PHP.

step 3:

You have to type make to compile PHP:


Step 4:

make install

if Apache is running stop Apache:

/home/apach2/bin/apachectl stop

Now we need to make some changes in Apache Configuration file in order to handle PHP files.

you need to add the following lines:

LoadModule php5_module modules/

AddType application/x-http-php .php

DirectoryIndex index.php index.html

Save this file and then start Apache:

/home/apach2/bin/apachectl start

Testing the PHP Installation

Now create a PHP file named info.php in /home/apach2/htdocs/



Save info.php and then access it via browser


If you get PHP Configuration. It means you are done. Thumbs Up.


Leave a Reply

Your email address will not be published. Required fields are marked *