Enable PHP Module In Compile Apache Web Server

This tutorial shows you How to enable PHP module on Apache server. Before enabling php module on apache, you need to first refer “Apache Compilation steps“.

Once you have done with Apache compilation, you should perform below steps to enable PHP module.

The first step is to Install below required dependency

$ apt-get install build-essential


Enable PHP Module

 1. Download PHP 5.6.32

$ cd /opt/
$ wget http://mirror.cogentco.com/pub/php/php-5.6.32.tar.gz

 2. Extract file

 $ tar -xvf php-5.6.32.tar.gz

 3. Compile PHP with Apache

$ cd /opt/php-5.6.32

$ ./configure --prefix=/opt/Apache2433/php5632 --with-config-file-path=/opt/Apache2433/php5632/etc --with-apxs2=/opt/Apache2433/bin/apxs --enable-mbstring --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-curl --with-mcrypt --with-iconv --with-gmp --with-pspell --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-xpm-dir=/usr --with-freetype-dir=/usr --enable-gd-native-ttf --enable-gd-jis-conv --with-mysql --with-mysqli --with-zlib --with-openssl=/opt/Apache2433/ssl

$ make

$ make install


Check “libphp5.so” is present in the modules directory

 $ ll /opt/Apache2433/modules/libphp5.so


4. Load PHP Module in Apache

 Check below line present in httpd.conf file. If not present then add,

 $ vim /opt/Apache2433/conf/httpd.conf

LoadModule php5_module  modules/libphp5.so

Add below lines in httpd.conf

$ echo "AddType application/x-httpd-php .php" >> conf/httpd.conf
$ echo "AddType application/x-httpd-php-source .phps" >> conf/httpd.conf


5. Test PHP Module

 Create .php page to test

Create .php page to test

$ vim /opt/Apache2433/htdocs/phpinfo.php


Save and exit.

Browse URL:

Enable php

Below are the errors encountered while trying to compile PHP5.6.32 from source, I have done this setup on Debian server so i used apt-get to install libraries. If you are using centos then just use yum instead of apt-get.

configure: error: xml2-config not found. Please check your libxml2 installation.
$ apt-get install libxml2-dev
configure: error: Please reinstall the libcurl distribution / easy.h should be in /include/curl/
$ apt-get install libcurl4-gnutls-dev
configure: error: jpeglib.h not found.
$ apt-get install libjpeg-turbo8-dev
configure: error: png.h not found.
$ apt-get install libpng-dev
configure: error: xpm.h not found.
$ apt-get install libxpm-dev
configure: error: freetype-config not found.
$ apt-get install libfreetype6-dev
configure: error: Unable to locate gmp.h
$ apt-get install libgmp-dev
$ ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
$ apt-get install libmcrypt-dev
configure: error: Cannot find pspell
$ apt-get install libpspell-dev

If you face any difficulties to install any of library or stuck anywhere between compilation comment me on this post. I will try to solve all your queries.

I hope you like the article if you find any difficulties then please do comment your queries or problem via the comment section, till then stay tuned to techthings.org for more such valuable articles.

Leave a Reply

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