Technical Note - Personal PHP
SummaryPHP is a popular web scripting language. ECS does allow for PHP scripts to be run, but there are some steps that need to be taken for it to work. This document lists those steps.
Getting PHP going
- Setup CGI access: You must first have requested and been approved for personal CGI script access.
- Copy the PHP CGI script: All URLs of the form
http://homepages.ecs.vuw.ac.nz/~username/*.phpare translated to call a PHP CGI script in your
cgi-bindirectory. Download this file and place it in your
~/public_html/cgi-bin/directory. Set the permissions so that it is executable by you (
chmod 700 ~/public_html/cgi-bin/php).
- Create a php.ini file: We recommend you download the recommended php.ini file and save that in your
~/public_html/cgi-bindirectory, alongside the
phpscript. Edit (see why) the
- Testing: Download this example script into your
doc_root, then rename it (see why) and try viewing it in your browser.
Database accessIf you already have access to ECS databases and wish to access them from PHP, you will need to add database modules to your PHP environment, a capability that is obtained by placing the following lines in your
extension=pdo.so extension=pdo_mysql.so extension=pdo_pgsql.soYou should then be able to access MySQL and PostgreSQL databases, though other modules may be required depending on your application (and would be added to the
php.iniin a similar manner). If you have difficulties, please send a ticket to firstname.lastname@example.org.
You will recall that the URLs of your own PHP scripts are translated through a script in your
cgi-bindirectory. What is less apparent is that the PHP environment will actually look to find any scripts below a
doc_rootdirectory specified in your own
php.inifile. This means that a URL of the form
http://homepages.ecs.vuw.ac.nz/~username/myprojects/project001/scripts/do_something.phpwill actually invoke the script that lies at
path_to_doc_rootis a directory path within your filestore and need not be related to the top level directory for your personal website files. The default value of
php.inifile you will have downloaded and placed in your
~/public_html/cgi-bin/directory is currently the generic
/home/username/public_htmlthough it is probably best thought of as simply being your
~/public_htmldirectory, which is the the default directory from which ALL your HTML files are normally served. PHP scripts, like all personal CGI scripts, run as you. If you have files in your
public_htmlthat aren't for public consumption, you should probably change your
doc_rootto a different directory so that any unqualified indirection resulting from use or misuse of your PHP scripts will not necessarily expose files below your
public_htmldirectory. Some PHP doc_root options
- You may wish to have all of your PHP script paths to start one level below your
public_htmldirectory so as to have all website-related stuff in one directory hierachy, as with your
cgi-binfiles, in which case you could
- You may wish to remove all of your PHP script paths to a directory hierachy outside of your personal website-related stuff, in which case you could
Renaming the example scriptIn order to prevent the current Wiki from possibly trying to execute the example script
test.phpwhen the link is clicked on, it has been given the name
test.php.txt. If you wish to be able to run the script it must be renamed to have
.phpat the end. You may wish to do this renaming at download time or simply
mv test.php.txt test.php
once you have downloaded the file.