Create a New Account        Home  |  Contact  |  Login           

Zrinity is the leader in enterprise-class email marketing management solutions and content management solutions for marketing professionals and developers worldwide.
Products Services Solutions Support Resources Partners Company
Setting up PHP on Apache 2

This page describes how to setup php on Apache 2. PHP 4.3.0 with Apache 2.0.46 was used on Redhat 8.

Install Apache

Install Apache2 following these instructions.

Download the latest PHP sources

Download the PHP tar.gz from php.net

Extract the source code

Extract the source code to a directory under /usr/local/src


 cp php-4.3.0.tar.gz /usr/local/src

 cd /usr/local/src

 gunzip php-4.3.0.tar.gz

 tar -xvf php-4.3.0.tar

 rm -f php-4.3.0.tar

 cd php-4.3.0

Set compiler options (optional)

If you want you can set some compiler options, this is typically done to create optimized code. One very common thing to do is to set CFLAGS=-O2 or CFLAGS=-O3 (that's an Oh, not a Zero) that tells the compiler how much code optimization to do, setting it to a higher value does more optimization, but also takes longer to compile and may potentially cause unexpected things (not common). O2 is a fairly safe level to use. To do this type the following:

 
 export CFLAGS=-O2

You can also tell the compiler what kind of CPU you have to perform more optimizations, I'm not going to get into that here, but if your interested check out the GCC manual.

Configure php with autoconf

Now you need to set the configuration options, and check that all libraries needed to compile are present. This is done with a script called configure, to find out what options you can set type the following:

 
 ./configure --help

You will see quite a few options, here's a page that defines the configure options. We will tell configure to enable mysql, and also tell it where to find apxs Apache's tool for building modules.

 configure --with-mysql --with-apxs2=/usr/local/apache2/bin/apxs 

Compile PHP

 
 make
 

Install PHP


 make install

Tell apache to load the module Edit httpd.conf /usr/local/apache2/conf/httpd.conf with your text editor. Add the following to httpd.conf

 
 Include conf.d/*.conf

This allows you to create a specific configuration file for each module that you install, for instance php.conf Now create a directory in your apache directory if its not there called conf.d

 mkdir /usr/local/apache2/conf.d
 
 cd /usr/local/apache2/conf.d

Make a file called php.conf located at /usr/local/apache2/conf.d/php.conf with the contents:
# PHP Configuration for Apache

#
# Load the apache module
#
LoadModule php4_module modules/libphp4.so

#
# Cause the PHP interpreter handle files with a .php extension.
#
<Files *.php>
    SetOutputFilter PHP
    SetInputFilter PHP
    LimitRequestBody 9524288
</Files>

AddType application/x-httpd-php .php 
AddType application/x-httpd-php-source .phps 

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

Note you could have just inserted the above in your httpd.conf file, and omit the conf.d step if you desire. I feel that the conf.d approch is a cleaner way to do it.

That's it, restart apache and you should have PHP working.

Note: To install PostgreSQL support on redhat 9 with php/apache2 you will need to install the postgresql libs, and devel rpms, and add --with-pgsql to your configure line

Thanks, Jonathan Crowe for suggesting the AddType directive.





  


Email Marketing Best Practices Blog

home products services partners company support contact my account

Copyright 2006 © Zrinity Inc. All rights reserved.     View our privacy policy         November 21, 2008