CGI/PHP on the Homepage Server
Can I run CGI/PHP scripts on the Homepage Server
Yes, you can run CGI/PHP scripts on the Homepage server if you have an active Unix userid.
Follow the steps below to set up the necessary support for scripts.
PHP scripts can be run from anywhere within your public_html directory.
CGI scripts (perl, bash, python, etc) can be run by following the procedure here:
- Create a cgi-bin directory within your public_html directory (for instructions on setting up your public_html directory, visit https://home.cc.umanitoba.ca/setup.html).
- Put your CGI/PHP script into the cgi-bin directory.
- Set the proper access permissions on the script and the directory by typing this command from within the public_html directory:
makepublic cgi-bin
Your script can be accessed by using the following URL format:
https://home.cc.umanitoba.ca/~userid/cgi-bin/scriptname
Every file in the cgi-bin directory must be set to be executable. This can be done by doing a chmod 755 on each file you create.
Please note:
- There are no global variables. To access information submitted to a script you have to use predefined variables such as HTTP_GET_VARS and HTTP_POST_VARS.
- Every Perl CGI page must contain:
#!/usr/bin/perlas the first line. Equivalent lines much be present for other script types. - The output of the CGI, when run, must start with a
Content-Type:line, followed by a blank line. See Examples below. - There are security contraints on what accounts and files are allowed to run CGI. If you are getting "Internal Server" errors, in spite of valid syntax, this may be the reason.
- The IST Service Desk does not support/troubleshoot CGI or PHP scripts, but if you are having trouble we will try our best to help.
You may wish to use a test script to ensure that everything is working properly.
Examples
The following python script, when entered into a file called hello_world.py and placed into the cgi-bin directory, will display "Hello World!" on a web page:
#!/usr/bin/python3 print("Content-Type: text/html\n") print("<html>\n<head><title>Hello World</title></head>\n<body>") print("<h1>Hello World!</h1>") print("</body></html>")
The following perl script, when entered into a file called hello_world.pl and placed into the cgi-bin directory, will display "Hello World!" on a web page:
#!/usr/bin/perl use CGI; print "Content-Type: text/html\n\n"; print "<html>\n<head>\n<title>Hello World</title>\n</head>\n"; print "<body><center><h1>HELLO WORLD!</h1></center>\n"; print "<p>Hello World!</p>\n"; print "<p><em>Hello World!</em></p>\n"; print "<p><strong>Hello World!</strong></p>\n"; print "</body></html>\n";
The following PHP script, when entered into a file called php_test.php and placed into your public_html directory, will display "PHP rocks!" on a web page:
<html>
<head>
<title>PHP ROCKS!</title>
</head>
<body>
<?php
print "PHP rocks!";
?>
</body>
</html>