29.2. Requirements for PHP
PHP can run in two modes: as a module on the server or in CGI mode as an external script (similar to Perl and Python scripts). Running PHP as a CGI script requires the appropriate interpreter line at the beginning of the script on Linux (usually #!/usr/bin/php) or associating the php extension with the PHP interpreter on Windows.
Running PHP as a module is a better choice for performance and security reasons but requires the appropriate module being compiled into or loaded on the Web server.
In the case of Apache, you can usually add a line to the Apache configuration file similar to the following to load the PHP module:
LoadModule php5_module modules/libphp5.so
You must also add an appropriate type to Apache so it knows how to handle PHP files. This can be done with a line in the Apache configuration file similar to the following:
AddType application/x-httpd-php .php
To test whether PHP is correctly installed on your server, place the following script in your Web server's root directory and access it with a browser:
<?php phpinfo(); ?>
The browser should display something similar to that shown in Figure 29-1.
Figure 29-1. Figure 29-1
Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.