From FreeBSDwiki
Revision as of 15:31, 19 July 2005 by Smortex (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PHP is the recursive acronym for PHP Hypertext Preprocessor. It is an interpreted script language commonly used for dynamic pages generation on webservers. Then it is generaly installed side by side with the Apache web server, and MySQL or PosgreSQL as database management system.


Installing PHP

PHP is available trougth the port-tree ...

# cd /usr/ports/lang/php5

... and the packages ...

# pkg_add -r php5

Using PHP

There are two ways to use PHP :

  • With apache, configured to make PHP to proceed .php files asked by the user.
  • As any any interpreter

PHP for dynamic websites

All the steps of Apache configuration are explained after PHP installation. You have to add these two lines to httpd.conf:

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

You will probably also want to add index.php as a possible directory index:

DirectoryIndex index.html index.php

You have to restart Apache to have your changes effective. For example, if you use Apache 2:

/usr/local/etc/rc.d/apache2 restart

Now, you can try your installation by creating a file test.php:


Pointing that file with your web browser should show you your php settings.

Shell scripts in PHP

You can write shell scripts in PHP, whitch is very useful for quick and dirty hacks... A PHP shell script looks like this :

  // Your PHP code here ...
  echo 'Hello World !\n';

PHP Website

Personal tools