Introduction

Apache HTTP Server and PHP are widely used technologies for hosting dynamic websites and web applications. Installing Apache with PHP through source compilation provides greater control over versions, modules, performance optimization, and custom configurations compared to package-based installations. This method is commonly used in environments where administrators require specific features or compatibility settings that are not available in default repository packages.

Prerequisites

Before starting the Apache and PHP source installation, ensure the following requirements are met:

  • A Linux server with root or sudo access
  • Basic knowledge of Linux command-line operations
  • Development tools and compilers installed (gcc, make, perl, etc.)
  • Required dependencies and libraries installed
  • Stable internet connection to download source packages
  • Available ports (typically 80 and 443) for Apache
  • Sufficient disk space and system resources

IMPLEMENTATION

How to install/compile Apache with PHP via source installation?
 
If you like to install PHP with Apache via source installation, kindly follow the steps below.
 
This PHP installation is compiles with major modules like GD, MCrypt, xml,etc
 
1.wget http://bg.php.net/distributions/php-5.3.1.tar.bz2
2.cd php-5.3.1.tar.bz2
3.bunzip2  php-5.3.1.tar.bz2
4.tar -xvf php-5.3.1.tar
or simply do tar jxf php-5.3.1.tar.bz2
5.cd php-5.3.1
6. ./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql    –prefix=/usr/local/apache2/php
{This is to compile Apache with PHP alone}
 
./configure –with-apxs2=/usr/local/apache2/bin/apxs –prefix=/usr/local/apache2/php –with-gd[=DIR] –with-freetype-dir[=DIR]
–enable-zip
–with-xsl[=DIR]
–enable-ftp
–enable-mbstring
–with-mcrypt[=DIR]
 
 
(To know more ./configure –help)
 
 
 
7.make (if u do it again install do a “make clean”)
8.make test
9.make install
10.If file /usr/local/apache/modules/libphp5.so does not exist or is an older version, type this (change this to libphp4.so for PHP 4):
 
    cp -p .libs/libphp5.so /usr/local/apache/modules
 
11.In httpd.conf
# Use for PHP 5.x:
#Add at the end of the file
#LoadModule php5_module        modules/libphp5.so
AddHandler php5-script php 
AddType application/x-httpd-php-source phps
 
 
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
 
AddType text/html       php
 
12.cd /usr/local/apache2/htdocs
13.vim index.php
——————–
 
——————–
14./usr/local/apache2/bin/apachectl restart
15.lynx www.hemanth.com
16.You should see the phpinfo page

Conclusion

Compiling Apache and PHP from source allows administrators to build a highly customized web server environment tailored to specific application requirements. Although the process requires more effort than package-based installations, it provides flexibility, better control over enabled modules, and the ability to use custom software versions. Proper planning, dependency management, and regular updates are important to maintain server stability and security after installation.

Leave a Reply