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 PostgreSQL as database management system.
PHP is available trougth the port-tree ...
# cd /usr/ports/lang/php5
... and the packages ...
# pkg_add -r php5
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:
Now, you can try your installation by creating a file test.php:
<? phpinfo(); ?>
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 :
#!/usr/local/bin/php <? // Your PHP code here ... echo 'Hello World !\n'; ?>