Child pages
  • How do I use PHP on a Luddy web server?
Skip to end of metadata
Go to start of metadata


In order to use PHP on the Luddy server you will need to first set things up exactly as you would for CGI script usage. So, please see the following KB article and set things up as described in the Configuration section there:

                                 How do I run CGI scripts on the Luddy school web server?

Once that is done, you can set up PHP files (with a .php file extension) in the same location as described for CGI scripts.

Script Requirements

Your php scripts must meet the following minimum requirements:

  • File Extension - 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 same directory where the php file is that contains something like this:

    <Files somefile>
        SetHandler x-httpd-php

    In this example, you would replace somefile with the name of your php script. If you want everything in the directory to be treated as php regardless of the file extension, then just include the SetHandler line in your .htaccess file without the Files lines.

  • Permissions - The script must be readable by the web server running on the CGI server (user apache and group apache, wwwd, or cgid). The easiest way to accomplish this is to make the file world readable with something like:

    chmod go+r yourscript.php

    If that is not acceptable in your case, you can make the file readable by either the cgi user or the cgid group in a couple different ways. One convenient way to do that is using Access Control Lists (ACLs) and the acl_open script can be used to help with that process. For example, you could make yourscript.php readable by the CGI server group (cgid) as follows:

    acl_open -r -g yourscript.php cgid
  • Reading/Writing Files - If your php script needs to read and/or write other files, these files must be readable or writable by the owner of the php script. The server uses suphp to run php scripts as the owner of the script.

suPHP Notes

All php scripts run using suPHP which means that the php is executed as the user who owns the php file. This imposes the following constraints:

  • No World-Writable Php - Scripts that are world-writable (eg. have the 'other' write permission bit set) will not be executed. Furthermore, the directory containing the script and the parent of this directory must not be world writable.
  • Directory ownership restriction - The owner of the directory that your php files are in must match the owner of the php files itself. Furthermore, the parent directory must also have the same ownership.


These troubleshooting tips apply only to PHP scripts and not CGI. See the CGI Page for more information about running CGI scripts.

There are a number of things that can go wrong when setting up your php scripts. Here are some tips and common pitfalls you are likely to run into:

  1. Use the CGI/PHP Verification Tool - We have an On-Line Verification Tool that you can use to check your URL.  It will report many common errors and give you tips on how to fix them.  It is not capable of detecting all possible problems, but is definitely the first place to start.

  2. Permissions Problems - The permissions on your php scripts need to be set so they are readable by the web server. In addition, the full path leading up to the script must be searchable by the apache server. The easiest way to do this is to make sure your cgi-pub directory (and any sub-directories you create there) are world searchable. This can be done in a number of different ways but one simple way is as follows:

    $ chmod go+x cgi-pub
    $ chmod go+x cgi-pub/somedirectory

    You will also get errors if your cgi-pub directory or php scripts are writable by others so you can make sure this is not a problem by running something like:

    $ chmod go-w cgi-pub
    $ chmod go-w cgi-pub/somedirectory
    $ chmod go-w cgi-pub/somefile.php
  3. suPHP Errors - See the above section on suPHP for information about possible problems you may encounter when running under suPHP.
  4. Incorrect Script Naming - PHP scripts must end with .php filename extension.
  5. Coding Errors and Log Access - In many cases, if you are getting server errors it is just due to errors in your php code. You can determine the cause of coding problems by looking at the apache error logs. In order to view the error log output you will first need to ssh to the cgi server, Once you are logged in there you may find it helpful to tail the error log while you access your page looking for errors. For example:

    $ ssh
    <... then, once logged into the cgi server...>
    $ tail -f /var/log/httpd/error_log | grep username

    In this example, the grep for your username (and you need to replace username with your actual username or the username of the account in which the php files reside) is done so you only see your errors and not the errors from every user of the system.   Note that not all script errors will contain the username of the user who owns the scripts.  If you aren't seeing the appropriate errors this way, you can always view all errors with:

    $ tail -f /var/log/httpd/error_log

    Just keep in mind that this is likely to give you a high volume of errors that you will have to sort through.
    Not all possible errors will show up in this log file but you should see errors related to many of the mistakes you are likely to make.  Similarly, you can also tail the access_log file in the same way if you want to watch the accesses to your page and not just the errors.  Just substitute "error_log" with "access_log" in the above examples.  In this case your username will appear in all accesses so you almost certainly want to use the pipe/grep of your username as shown above.