University of Florida :: Department of Computer and Information Science and Engineering (CISE)

CISE Help & Resources

Running PHP Programs

This page is intended to provide you with Department-specific information about running PHP programs on our server. We assume you have read Creating a Personal Web Page and have basic, general knowledge of writing PHP programs.

For more information on PHP, visit php.net.

Example: Hello World

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

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 these steps:

  1. Download php.ini into the directory containing PHP scripts. In php.ini, add the following lines:
    cgi.force_redirect = 0
    display_errors = On 
    			
  2. 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.
  3. After debugging, set display_errors = Off.

Note: www-pub is only accessible from within the CISE network.

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

Tips and Caveats

Feedback