ELS Howto: Apache and PHP


Synopsis

This document explains how to add PHP scripting capabilities to the Apache web server on an Elemental Linux Server (ELS) system.


Prerequisites

These instructions assume that you already have a working Apache web server installed. If you do not, please see the ELS Howto: Apache Web Server before continuing.

You will also need to have the ELS 'Extra Applications' CD-ROM mounted on /media/cdrom or be able to download packages from the ELS distribution site.


Installation

The following instructions describe how to install PHP using the ELS CD-ROM.

  1. Extract the PHP package into the root of the server's directory hierarchy.
  2. Create a link in the Apache httpd's modules directory that points to libphp5.so in the PHP package's modules directory.
  3. Create symbolic links for the PHP package's binaries in the /opt/bin directory.

Example

The following example shows how you would install php-5.2.6 for httpd-2.2.9 using the ELS CD-ROM:

cd /
tar -zxf /media/cdrom/extra/php-5.2.6.i586.tar.gz

cd /opt/httpd-2.2.9/modules
ln -s ../../php-5.2.6/modules/libphp5.so

cd /opt/bin
ln -s ../php-5.2.6/bin/* .

Configuration

After installing PHP you will need to adjust the httpd configuration as well as supplying a configuration file for PHP.

  1. Edit the httpd.conf file and make the following changes:
  2. Install an appropriate php.ini file in the /etc/opt/php directory.
  3. Restart the httpd server to apply the changes.

Note

The latest recommended php.ini file may be found from the PHP project's CVS repository or by looking in the source package for PHP.

Example

The following example shows how to modify httpd.conf and how to fetch the recommended php.ini file from the PHP project's CVS site.

vi /etc/opt/httpd/httpd.conf

LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
AddType application/x-httpd-php .php
DirectoryIndex index.php index.html

mkdir /etc/opt/php
cd /etc/opt/php
wget http://svn.php.net/viewvc/php/php-src/trunk/php.ini-production?revision=324317&view=co
mv php.ini-production?view\=co php.ini

/etc/init.d/httpd restart

Note


Testing

Check the php installation by trying a simple php test script.

  1. Copy the test script from http://www.htmlite.com/php003.php and save it as info.php in your httpd document root directory.
  2. Use a web browser to navigate to the URL of the test script (e.g. http://your-server-name/info.php).
  3. Verify that you see a page listing the capabilities of your PHP configuration.

The following example shows a successful test using Lynx as the web browser.

login: joe
password:

$ lynx -dump http://127.0.0.1/info.php | head 

   [1]PHP Logo

PHP Version 5.2.6

   System Linux els.mynetwork.lan 2.6.25.10 #5 Sun Aug 24 20:48:35
   CDT 2008 i686
   Build Date Aug 10 2008 16:17:45
   Configure Command '/usr/src/php-5.2.6/configure'

If you cannot view the info.php page, here are some things to try.

  1. Verify that you can view non-PHP pages on your web server.
  2. Make sure the link to libphp5.so was created properly.
  3. Double-check the modifications to httpd.conf.
  4. Stop and start the httpd server to activate any configuration changes to httpd.conf or php.ini.

Additional Information

Help with php.ini directives can be found at: http://us.php.net/manual/en/ini.php.