Knowledge Base

Authoring/Development - System CGI: php-cgiwrap

Modifications Required:


Optional Modifications:

None allowed. To run correctly, php-cgiwrap requires special privileges.

php-cgiwrap is a "script wrapper" that lets your scripts execute under your own userid and group instead of user nobody and group www. It works in the same fashion as cgiwrap but handles paths in such a way that it can be used to run PHP pages under your own userid. Running PHP pages under your own userid allows you to use chmod 700 to lock out other users on the server from viewing the source code. Locking out other users can be especially important if you are interfacing with a MySQL database, thereby preventing people from obtaining your password.

To use PHP 5 with php-cgiwrap, you must first copy php5.cgi to your own Web directory's (public_html) cgi-bin directory by SSH:

  cp /usr/www/cgi-bin/php5.cgi ~/public_html/cgi-bin/
  chmod 755 ~/public_html/cgi-bin/php5.cgi

(For PHP 4, copy the file php4.cgi from the same directory instead.)

You must then add the following lines to your .htaccess file (please note that this code should be two lines in length with a space before "/cgi-sys"):

  Action application/x-pair-sphp5 /cgi-sys/php-cgiwrap/USERNAME/php5.cgi
  AddType application/x-pair-sphp5 .php

USERNAME should be replaced with your account username. The .htaccess file mentioned above is a plain text file of that name and can be used to configure certain Web settings. If you do not already have a .htaccess file, you can create a regular file with that name to use. This should be placed into the Web directory containing the scripts you wish to wrap.

Once this is done, all .php files are run under your own user ID. If you want to use a different file extension, replace .php on the second line with whatever you prefer.

The example above only works if you are using your own domain name. If you wish to use the server name in the URL for the page you are accessing, you must add the following lines to your .htaccess file:

  Action application/x-pair-sphp5 /cgi-sys/php-cgiwrap/USERNAME/php5.cgi/users/
  AddType application/x-pair-sphp5 .php

As in the other example, USERNAME should be replaced with your account username.

These URLs run the non-debugging version of php-cgiwrap; if you want to use the debugging features, replace php-cgiwrap with php-cgiwrapd.

For more details on using cgiwrap, please visit our cgiwrap Knowledge Base article page.

Shortcut To This Article:

Related Information