PHP 5 on FreeBSD

From FiberWiki

Jump to: navigation, search

PHP 5 install on FreeBSD


PHP (PHP: Hypertext Preprocessor) is a computer scripting language, originally designed for producing dynamic web pages. It is mainly used in server-side scripting, but can be used from a command line interface or in standalone graphical applications. -definition taken from Wikipedia

Installing the PHP Port
cd /usr/ports/lang/php5
make config
make install

When you run make config you will be shown a list of options to choose from. To use PHP with Apache make sure the Apache Module box has a “X”.

Adding the PHP 5 module to Apache Apache needs the following lines in the httpd.conf file for php to work. These lines should already be added by the port but if you have problems you should double check your httpd.conf file.

Apache 1.3.x
LoadModule php5_module        libexec/apache/libphp5.soAddModule mod_php5.c
Apache 2.x
LoadModule php5_module        libexec/apache/libphp5.so

If you installed using the port and had Apache installed already the LoadModules should have been added during port install.

Next find your DirectoryIndex section in your httpd.conf file. Apache may be setup for PHP 4, but not PHP 5 currently so you will need to change your DirectoryIndex to look like this:

<IfModule mod_dir.c>

<IfModule mod_php3.c>

<IfModule mod_php5.c>

DirectoryIndex index.php index.php3 index.html

</IfModule>

<IfModule !mod_php4.c>

DirectoryIndex index.php3 index.html

</IfModule>

</IfModule>

<IfModule !mod_php3.c>

<IfModule mod_php5.c>

DirectoryIndex index.php index.html index.htm

</IfModule>

<IfModule !mod_php4.c>

DirectoryIndex index.html

</IfModule>

</IfModule>

</IfModule>

Setting HTTPD to read index.php first.
DirectoryIndex index.php index.html index.htm

Now apache just needs to know what it should parse the PHP files with. These two lines should be added to the httpd.conf file, and can be put at the bottom if needed.

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

If want to use PHP code inside of .htm files you can just add on those extensions.

AddType application/x-httpd-php .php .htm .html
Personal tools
Navigation