Installing PHP on Apache 2

This page describes how to setup php on Apache2. 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=-O2You 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 --helpYou 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/*.confThis 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.dMake 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.phpNote 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.
Related Entries
- 20 ways to Secure your Apache Configuration - December 6, 2005
- ServerTokens Prod, ServerSignature Off - July 25, 2005
- Free Chapters in Apache Security - June 13, 2005
Trackbacks
Trackback Address: 516/E11925CCA22663A8F9CBB5F28E75EF5B
Comments
On 02/28/2006 at 1:55:13 AM EST Barry wrote:
1
Thanks, it worked.
On 06/02/2006 at 12:11:31 AM EDT phoneynk wrote:
2
Worked for me also thanks But configuring php with mysql was problamatic as mysql header files were not present on my linux box
so i did following ยท To connect with mysql install mysql header files
> Download MySQL-devel-standard-5.0.22-0.rhel3.i386.rpm from http://dev.mysql.com/downloads/mysql/5.0.html (http://dev.mysql.com/get/Downloads/MySQL-5.0/MySQL-devel-standard-5.0.22-0.rhel3.i386.rpm/from/http://mirror.switch.ch/ftp/mirror/mysql/)
> Change directory to the directory containing MySQL-devel-standard-5.0.22-0.rhel3.i386.rpm > rpm ?ivh MySQL-devel-standard-5.0.22-0.rhel3.i386.rpm
On 06/06/2006 at 6:25:42 AM EDT sivakumar wrote:
3
how to configure. apache and php ? the apache tell error for no service installer then Apache"
On 07/13/2006 at 8:11:51 PM EDT BigTony wrote:
4
noice won.
On 10/15/2006 at 1:45:37 AM EDT yatin wrote:
5
can ny body help how to use OCI.dll in php/apache
On 03/25/2007 at 10:23:54 PM EDT GowthamiP wrote:
6
The Application has failed to start because OCI.dll was not found.Re-installing the application may fix this problem.
On 11/23/2007 at 12:33:49 PM EST Manee wrote:
7
when i install php everything go well until this step
# make
the messgae appeared: make: *** No targets specified and no makefile found. Stop.
On 06/19/2008 at 5:20:06 AM EDT great wrote:
8
Amateur MILF's who love to show off.
On 09/26/2008 at 9:05:57 AM EDT Ryan wrote:
9
when running the ./configure command, redirect the error output to a file so you can figure out what's wrong. To do this, append "2> error.file" to the configure command, specifying the file to save the error log in.
On 03/23/2009 at 8:25:49 PM EDT dumbphpprogrammer wrote:
10
you guys are so por...thanx for the help
On 07/03/2009 at 4:46:25 AM EDT Vickey Rihal wrote:
11
Thanks buddy
It really works.
This issue had wasted my 3 days.
Again thanks
On 10/29/2009 at 10:37:11 PM EDT Sat wrote:
12
Worked perfectly, thanks a lot. You saved my day.
Post a Comment
Recent Entries
- Cache Template in Request Setting Explained
- What Version of Java is ColdFusion Using?
- ColdFusion 9 Performance Brief from Adobe
- Request Filtering in IIS 7 Howto
- J2EE Session Cookies on ColdFusion / JRun
- Hands on ColdFusion Security Training
- ColdFusion 9 Solr Vulnerability - Are you at Risk?
- FCKEditor Year 2010 Bug for Firefox 3.6 with ColdFusion
so i did following ยท To connect with mysql install mysql header files
> Download MySQL-devel-standard-5.0.22-0.rhel3.i386.rpm from http://dev.mysql.com/downloads/mysql/5.0.html (http://dev.mysql.com/get/Downloads/MySQL-5.0/MySQL-devel-standard-5.0.22-0.rhel3.i386.rpm/from/http://mirror.switch.ch/ftp/mirror/mysql/)
> Change directory to the directory containing MySQL-devel-standard-5.0.22-0.rhel3.i386.rpm > rpm ?ivh MySQL-devel-standard-5.0.22-0.rhel3.i386.rpm
# make
the messgae appeared: make: *** No targets specified and no makefile found. Stop.
It really works.
This issue had wasted my 3 days.
Again thanks



add to del.icio.us



