Apache, Installing with PHP

From FreeBSDwiki
Revision as of 15:44, 28 March 2006 by Dave (Talk | contribs)
Jump to: navigation, search

Apachefeather.jpg Php.jpg


Getting Started

I have decided to use Apache/1.x with PHP/4.x. I belive this is the better combination, as time tells, they are the most popular and better stability. Anyhow, this is my opinion, so this guide will use those two versions...

First, update your ports tree and either install the packages as root:

# pkg_add -r apache13
# pkg_add -r php4

Or install from ports:

# cd /usr/ports/www/apache13 && make install clean
# cd /usr/ports/lang/php4 && make install clean

In either case, they'll be installed in /usr/local by default.

Setting up php.ini

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


You may wish to edit the above file to set PHP options. If you'd rather use php.ini-recommended, make sure to read the list of changes, and how they affect the behaviour of PHP.


Now, you will have to edit the httpd.conf file to load the PHP module:

pico /usr/local/apache/conf/httpd.conf

1) Add the following line to the above file:

LoadModule php4_module libexec/

- Or if you are lazy and can't be bothered to check httpd.conf:

echo "LoadModule php4_module libexec/" >> /usr/local/apache/conf/httpd.conf


Running "make install" might have added the line for you, best be on the safe side and check!

2) In the AddModule section of httpd.conf, add the following line to the bottom of the section:

AddModule mod_php4.c

3) Apache will need to be told on what to class as a PHP document. Add this line to the httpd.conf file in the AddType section:

AddType application/x-httpd-php .php

...You might consider using the following line to show highlighted PHP source, it can be achieved by adding the line also to the AddModule section under the line you have just added:

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

Starting Apache

Use the following command to start Apache:

/usr/local/apache/bin/apachectl start

All works?

To test everything went according to plan, we will now make a PHP file:

echo "<? phpinfo(); ?>" >> /usr/local/apache/htdocs/php-test.php

Run your favourite browser, such as FireFox and point it to http://localhost/php-test.php. You will now see lots of compilation and configuration options for PHP.

You're Done!

Final Notes

You should now have a working version of Apache with PHP. The next and only thing I will suggest is to auto-start apache via an rc.d script or via a crontab to start Apache at boot:

crontab -e

and add to the bottom:

@reboot /usr/local/apache/bin/apachectl start
Personal tools