Difference between revisions of "Running PHP Scripts on the CS Webservers"

(Created page with "'''''(The following applies starting after the morning of Tuesday, April 23.)''''' The multi-user nature of the CS '''www.cs.jhu.edu''' website requires that we run PHP in a...")
 
Line 1: Line 1:
 
'''''(The following applies starting after the morning of Tuesday, April 23.)'''''
 
'''''(The following applies starting after the morning of Tuesday, April 23.)'''''
 
  
 
The multi-user nature of the CS '''www.cs.jhu.edu''' website requires that we run PHP in a slightly uncommon way.  We run PHP as a CGI using Apache's [https://httpd.apache.org/mod_fcgid/ mod_fcgid] [https://en.wikipedia.org/wiki/FastCGI FastCGI] module.  That means that some common ways to use PHP need to be done slightly differently in our environment.  These differences are documented below.
 
The multi-user nature of the CS '''www.cs.jhu.edu''' website requires that we run PHP in a slightly uncommon way.  We run PHP as a CGI using Apache's [https://httpd.apache.org/mod_fcgid/ mod_fcgid] [https://en.wikipedia.org/wiki/FastCGI FastCGI] module.  That means that some common ways to use PHP need to be done slightly differently in our environment.  These differences are documented below.
 
  
 
== Files in Your Home Directory ==
 
== Files in Your Home Directory ==

Revision as of 15:31, 22 April 2013

(The following applies starting after the morning of Tuesday, April 23.)

The multi-user nature of the CS www.cs.jhu.edu website requires that we run PHP in a slightly uncommon way. We run PHP as a CGI using Apache's mod_fcgid FastCGI module. That means that some common ways to use PHP need to be done slightly differently in our environment. These differences are documented below.

Files in Your Home Directory

There is a new php-cgi script in your ~/public_html/cgi-bin directory. This is the script that runs the PHP CGI interpreter for you. Apache is told about this script by the FcgidWrapper directive in your ~/public_html/.htaccess file.

Changing either of these files should be done with care, as doing so could prevent PHP from working for your webpages.

Apache AddType Directives

The CS www.cs.jhu.edu webserver treats any file that has a .php extension as a PHP script. In some cases, you might want files with other extensions to also be treated as PHP scripts. Most documentation on the web describes how to use the AddType Apache directive in your .htaccess file for this, and that directive usually looks like this:

AddType application/x-httpd-php .html

For our website, you will need to instead use the AddHandler directive to process the file as a FastCGI script and give the full path to your php-cgi script to run it.

AddHandler fcgid-script .html
FcgidWrapper /users/YOUR-ACCOUNT-HERE/public_html/cgi-bin/php-cgi .html

Apache ForceType Directives

Another way to force a particular file or files to be treated as PHP is to use a <Files> or <Directory> section in your .htaccess file to target those files specifically. The customary documentation on the web uses the ForceType directive for this:

<Files quux.foo>
   ForceType application/x-httpd-php
</Files>

For our webserver, you have to use the SetHandler directive along with the full path to your php-cgi script:

<Files quux.foo>
  SetHandler fcgid-script
  FcgidWrapper /users/YOUR-ACCOUNT-HERE/public_html/cgi-bin/php-cgi
</Files>