CISE Help & Resources

Running PHP Programs

Please note: This document asssumes that you know how to use Unix, understand how to create web pages at CISE, and that you have sufficient knowledge of how to write PHP programs.

For more information on PHP see php.net.

Hello World example

Suppose you have the following program located in $HOME/public_html/hello.php

#!/usr/local/bin/php

<html><head><title>PHP Test</title></head>
<body>
<?php print( "Hello World<br />"); ?>
</body></html>

and you wish to execute it. First you need to tell the webserver that files with an extension of .php are programs, and should be executed by the program specified in the shebang line. Create (or edit) a file called htaccess in the same directory as your script (or above it), and add the following lines:

AddHandler cgi-script .php
DirectoryIndex index.html index.php

Both the program and the htaccess file should have the proper permissions, world executable for the former, world readable for latter. Neither should be world writable.

This can be done by running the commands:

chmod 711 hello.php
chmod 644 htaccess

You should now be able to run the PHP program with this url:

http://www.cise.ufl.edu/~username/hello.php

And it should display "hello world" if everything went okay.

Debugging PHP Scripts

One of the most helpful tools for debugging PHP scripts is the interpreter's native error reporting functionality. This option is disabled by default to prevent security risks, but it can be enabled on a per-directory basis by placing a customized php.ini file in that directory. Every time a PHP script is run, it checks for this file in the local directory and sets a number of configuration variables from its contents. By setting the display_errors variable to On, you are configuring PHP to echo errors to the browser. To enable error reporting for your application, follow the steps below:

  1. Download a modified version of the php.ini file here.
  2. Place this file in the directory containing your PHP scripts.
  3. Modify the file contents to your specifications (optional). The file you downloaded is set to display all errors, but you may wish to further refine the level of error reporting. Below is a list of global configuration variables you may modify, with the suggested value in italics and corresponding line number in parentheses.
    (285) error_reporting = E_ALL
    (292) display_errors = On
    (297) display_startup_errors = Off
    (302) log_errors = On
    (345) error_log = ~username/public_html/php.error.log
  4. Debug your program. Navigate your browser to the page you wish to debug on the testing server, www-pub.
    http://www-pub.cise.ufl.edu/~username/foo.php
    Any errors should now be displayed in the browser.
  5. After debugging, set display_errors = Off or remove the php.ini file to prevent any security vulnerabilities.

For more information on using the php.ini file, see the file's verbose commenting or view the official online documentation.

Some Things to Keep in Mind

Info for Students

Info for Faculty & Staff

Industrial Advisory Board