Indiana University Bloomington

School of Informatics and Computing


Computer Science Program







 Home

 Contacts

 Courses

 Academics

 Careers

 Research

 People

 Calendar

 Resources

 Facilities
   FAQ
   System Notices
   Help
   Hardware
   Software
   Network
   Policies
   Lindley Hall

CSG FAQ

Q: How do I run PHP scripts on the department web server?

See the How to run CGI scripts to create the necessary directories for your php scripts. It is not neccessary to do this if you have already run makecgi for cgi script support. Please note that you are only doing this to make directories and are not setting up suexec support for php. Php scripts do not follow the same rules as cgi since they are run as the webserver; in other words, a privledge-less user equivalent to nobody.

Once your environment is set up, the only requirements are...

  • By default, scripts must end with the .php extension. If you want to have a php file without the .php extension, you can do this by creating a .htaccess file in the directory containing the script that contains something like this:

    <Files somefile>
    SetHandler application/x-httpd-php
    </Files>

    In this example, you would replace somefile with the name of your php script.

  • The script must be readable by the web server running on the CGI server (user cgi and group cgid). The easiest way to accomplish this is to make the file world readable. See the associated FAQ entry for more details about file permissions and other options for limiting access.

  • All php scripts run in Safe Mode. See the associated Safe Mode system notice for more information about Safe Mode. The limitations of safe mode you are most likely to encounter are:

    1. Limited exec access - You will only be able to exec programs that are in our trusted list. Contact the CSG if you need to have a program added to the list.
    2. File ownership restriction - Your script will only be able to read other files on the system that have the same owner as the php script. This is generally not a problem unless your scripts are creating files on the fly. Since the execution of the php script is done as the cgi user, files created by your script will be owned by the cgi user and, subsequently, your script will not be able to read them. If you find yourself in a situation where this becomes a problem please seek help. UPDATE: We have now applied safemode patches to php that get around most of the permissions problems that you are likely to encounter as a result of php scripts creating files on the fly.

PHP Version Information

Please note that the CGI/PHP server is running PHP version 4.x. If you require PHP version 5 then there are two options:

  1. You can run your PHP by way of CGI. In order to do this create an executable cgi script with the .cgi file extension (as you would for any cgi script) and then put the following as the first line in the script to envoke php5:

    #!/l/php5/bin/php

    After this first line, the rest of the script just contains your normal php source. When run in this way, php is running per the CGI Suexec model so it is running as your userid and is not running in safe mode.

  2. We can configure things so that all .php files in a "PHP5" subdirectory of your cgi-pub directory are envoked with php5. Setting this up is simple but requires a change in the apache config so just let us know if you want to set this up for your account. As with option 1, this results in your .php scripts being processed per the CGI Suexec model so it is running as your userid and is not running in safe mode. This option is particulary useful when trying to run 3rd party php5 applications without having to modify filenames and embedded links.



See an error in this FAQ entry? Please report it.

[Return to the FAQ index]









Valid HTML 4.01!