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.


Apache Installation From Source

Compiling and Installing Apache Version 2.4 from source on Linux OS

We create the folder named ‘sourcecode‘ and ‘apache2‘ in /home

mkdir /home/sourcecode

we will use this directory to keep downloaded file

mkdir /home/apache2

at apache2 we are going to Compiling and Installing Apache.

Prerequisite for Apache installation * important

* Apache source code -Download the latest release of Apache from

*  APR and APR-Util Source Code Download Apr from

ANSI-C Compiler and Build System -Make sure you have an ANSI-C compiler installed. The GNU C compiler (GCC) from the Free Software Foundation (FSF) is recommended. If you don’t have GCC then at least make sure your vendor’s compiler is ANSI compliant. In addition, your PATH must contain basic build tools such as make.

Perl-Compatible Regular Expressions Library (PCRE) – Download the source code from or from rpm and package

Step 1: Download

cd /home/sourcecode


extract Apache here

gzip -d httpd-2.4.25 tar.gz

tar xvf httpd-2.4.25.tar

same way extract APR and APR util


gzip -d apr-1.5.2.tar.gz

tar xvf apr-1.5.2.tar

mv apr-1.5.2 /home/sourcecode/httpd-2.4.25/srclib/apr


gzip -d apr-util-1.5.4.tar.gz

tar xvf apr-util-1.5.4.tar.gz

mv apr-util-1.5.4 /home/sourcecode/httpd-2.4.25/srclib/apr-util

Step 2:

cd  /home/sourcecode/httpd-2.4.25

./configure –prefix=/home/apache2 –enable-so

First option –prefix tells configure script that we want Apache to be installed in directory apache2

If we don’t provide a prefix option than it’ll be installed in default location, which is /usr/local/apache2.

Second option –enable-so tells configure to enable module so, which allows Apache to load shared modules.

Step 3: make

Step 4: make install

This will install Apache to /home/apache2

Step 5: Test Apache installation is done by starting Apache

/home/apache2/bin/apachectl start

If you get to shell prompt without any error then Apache is started.

Now you open a browser

http://localhost, which should display the default message “It Works!”

Now your apache is ready

Start Apache automatically during system startup

Modify the /etc/rc.d/init.d/httpd script and change apachectl and httpd variable to point to the appropriate new location



Now, you can perform the following to stop and start the Apache

service httpd stop

service httpd start

Setup the Apache to automatically startup during reboot as shown below.

# chkconfig --list httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
# chkconfig --level 2345 httpd on
# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

Apache configure command Line Example

./configure –prefix=/wwwroot –enable-auth-anon –enable-auth-dbm –enable-auth-digest –enable-file-cache –enable-echo –enable-charset-lite –enable-cache –enable-disk-cache –enable-mem-cache –enable-example –enable-ext-filter –enable-case-filter –enable-case-filter-in –enable-deflate –with-z=/usr/local –enable-mime-magic –enable-cern-meta –enable-expires –enable-headers –enable-usertrack –enable-unique-id –enable-proxy –enable-proxy-connect –enable-proxy-ftp –enable-proxy-http –enable-ssl –with-ssl=/usr/local –enable-optional-hook-export –enable-optional-hook-import –enable-optional-fn-import –enable-optional-fn-export –enable-bucketeer –enable-static-support –enable-static-htpasswd –enable-static-htdigest –enable-static-rotatelogs–enable-static-logresolve –enable-static-htdbm –enable-static-ab –enable-static-checkgid –enable-http –enable-dav –enable-info –enable-cgi –enable-cgid –enable-dav-fs –enable-vhost-alias –enable-rewrite –enable-so