CGI Programming with PHP


(PHP Hypertext Preprocessor)

PHP Hypertext Preprocessor Version 3 is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

PHP 3 (Release 1.0 available June 1, 1998) has been installed on triton in your instructor's cgi-bin directory. This new language is very powerful and promises to be a very valuable tool.

Perhaps the strongest and most significant feature in PHP3 is its database integration layer. Writing a database-enabled web page is incredibly simple. The following databases are currently supported:

     Oracle                   PostgreSQL
     Sybase                   Adabas D
     mSQL 1.x and 2.x         FilePro
     MySQL                    dBase
     Solid                    Unix dbm
     Generic ODBC
Note: Not all of these databases will be supported on triton. Only MySQL, and Unix dbm are supported at this time. The Oracle support is waiting until CANS installs the new ORACLE with the C-language API. This will probably not happen in time for this semester's course

Because the scripts are run under your userid, they can do considerable damage if installed and used improperly. You should be familiar with the Security Implications of PHP before you begin using it.

The PHP executable is a binary file of over 1.6 MB in size. You will need to have it in your cgi-bin directory to run it. To avoid copying it and using your quota to store it, a symbolic link to the one physical copy in your instructor's directory will be used instead.

It is very important that you also place a PHP initialization file named php3.ini into your cgi-bin directory along with your php executable. This file configures the PHP program and the most important line in this file is as follows:

Where the bold portion should be configured to your own home directory path where you will store the actual PHP scripts. They will not be accessable in your WWW directory tree. (See Case 3 in the security documentation cited above.)

Setting up your PHP

In setting up for PHP, you should be logged in to triton using your webdv account.

Note: in the commands which follow, user types the part in bold.

  1. The following copies php to your cgi-bin directory"
    % cd ~/WWW/cgi-bin
    % cp  ~schmitt/WWW/cgi-bin/php  php
    
  2. The following copies the php3 initialization file.
    % cp  ~schmitt/WWW/cgi-bin/php3.ini  .
    
  3. Edit the php3.ini file to change the to point to your own file Note: jove or vi should be used since pico tends to wrap long lines to several shorter lines: so BEWARE!
    % jove  php3.ini
    Note: To write and save your changes in jove use: ^X^W
          To exit jove use: ^X^C
    
  4. The following creates the cgi-php directory which is not in your WWW directory tree.
    % cd
    % mkdir cgi-php
    
  5. Deny read-access to your scripts to anyone but yourself.
    % chmod 700 cgi-php
    
  6. Change to your cgi-php script directory.
    % cd cgi-php
    
  7. You are now ready to create your PHP scripts in this directory.
  8. From triton you can copy scripts from Jeff Schmitt's cgu-php directory as follows
    % cp ~schmitt/cgi-php/99bottles.php3 .
    

PHP3 Resources and Information

PHP Demos

Jeff Schmitt's PHP Demos

Jeff Schmitt's PHP-related Bookmarks