Custom Apache and PHP

From RSWiki
Jump to navigation Jump to search

This information is deprecated. It should be considered end of life and should not be used in any production setting

Step 1 - Install Base OS

For this I used a minimal installation of CentOS 4.3 with No X or servers, office, sound video etc. Just a basic install with the default GCC installation.

Once setup of the OS was complete I manually installed the development RPM's for MySQL and Postgres from the installation DVD.

Step 2 - Compile and install Apache PHP

For this I downloaded and unpacked the source for Apache 2.2.2 and PHP 5.20.

First we need to compile Apache and this is done in three stages:

 cd srclib/apr
./configure --prefix=/usr/local/apr-httpd/
make
make install
cd ../apr-util
./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/
make
make install
cd ../../
./configure --with-apr=/usr/local/apr-httpd/ --with-apr-util=/usr/local/apr-util-httpd/

Next we need to compile PHP with support for MySQL and Postgres:

./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-pgsql
make
make install

There is a whole slew of optional stuff that can be compiled into PHP, such as FTP, Calendar, Socket support and support for various image formats. Many of these things don't require extra libraries and just need to be enabled before you compile. For more information about this see ./configure --help

While still in the PHP source directory we need to create a default php.ini:

cp php.ini-dist /usr/local/lib/php.ini

Step 3 - Configuring Apache to use PHP

By following the above steps the PHP make install routine should have automatically modified httpd.conf to load the php5 module. Just in case use your favourite editor to check that httpd.conf has the following entry:

LoadModule php5_module        modules/libphp5.so

Now we also need to tell Apache that PHP is there to handle files with the extension so search through httpd.conf for AddType application entries and insert a new line below them with the following:

AddType application/x-httpd-php .php .phtml

Finally we need also to tell Apache that index.php will be one of the default start pages and you can do that by searching through httpd.conf for the DirectoryIndex directive and modifying it so that it looks like the following:

DirectoryIndex index.html index.php

Now we are to start Apache so from the command console type in the following command:

/usr/local/apache2/bin/apachectl start

Point your web browser to the IP address or hostname to see if you are presented with the default startpage.

To test if PHP is working correctly we need to create a test PHP page:

cd /usr/local/apache2/htdocs
touch info.php

Use your favourite editor to edit info.php so that it contains the following:

<?php
	phpinfo();
?>

Step 4 - Testing that it all works

Now use your browser to point to info.php on your new server.

If it all works congratulations. You now have a fully functioning Apache webserver with PHP and support for Postgres and MySQL.