Skip navigation.
New Mexico State University


Using CGI scripts on Web.NMSU.Edu

CGI Now Available!

CGI scripting is now supported on Web.NMSU.Edu as of 12-21-2007. We use Apache SuExec which runs your scripts out of your public_html/cgi-bin directory. Your scripts are executed as your userid for security purposes.

What is CGI?

CGI stands for common gateway interface. It allows users to run scripts as part of a web site. For example, a script which processes data from a form, or displays random text and images on your web site. >>More ...

How to use CGI scripts on Web.NMSU.Edu

Step 1

Create the cgi-bin directory and set the permissions

Executable scripts will only run if they are located in your cgi-bin directory. Your cgi-bin directory must be created inside your public_html directory with file permissions set to 755. You must name your scripts with the extension of .cgi or .pl and your script file permissions should also be set to 755.

You can have the directory created and the file permissions set automatically by clicking the following link: Check/Fix File Permissions This utility will require you to log-in using your myNMSU Username and Password. You may also wish to run this utility anytime you add new scripts.

Step 2

Create and Upload Your CGI Script

Write your CGI script using a plain text editor. Optionally, you may wish to use a CGI script which is freely available on the internet.

Upload your script into your cgi-bin directory. Be sure to upload as plain ascii test and NOT as binary. You must name your scripts with the extension of .cgi or .pl and your script file permissions should also be set to 755.

 Step 3

Test and Troubleshoot

You can test your script by going to the url: http://web.nmsu.edu/~USERNAME/cgi-bin/SCRIPTNAME.cgi where USERNAME is your myNMSU Username and SCRIPTNAME is the file name of your script. It should correctly do what ever the script is designed to do and optionally display results in the web page.


If your script does not work as expected then you will need to troubleshoot the problem.

Begin by using the following link to look at the apache Raw Error Log.

Scripts can fail for any number of reasons. Use your favorite search engine to look up any errors you find in the Raw Error Log.

Permission errors are one of the most common causes of CGI script failures. Remember, you can always use our Check/Fix File Permissions utility to make certain your permissions are set correctly.

Many scripts (but not all) can also be tested from the command line. You can ssh into web.nmsu.edu and log-in with your myNMSU Username and Password. from there, cd to your public_html/cgi-bin directory and try running your script from the command line. If it works from the command line but not from the browser, then you will need to solve any problems by using the Raw Error Log. If it will not run from the command line (but you believe it should), then there may be errors in the script itself.

Because we use Apache SuExec, there are additional requirements that must be met by your script. Most of these requirements are covered by our Check/Fix File Permissions utility. However, SuExec will not allow writable files in the cgi-bin directory. It will also not allow any file paths that begin with / or a backreference of ../

See the Apache SuExec Security section for details.

CGI Tutorials:

If you are still having problems or simply want to learn more about CGI programming, you may want to search for CGI tutorials and particularly look for examples that work with Apache SuExec. For your convenience, here are a few places to start:


Quick Access - Many of the features below require a valid myNMSU User Name and Password.
Set Up Access Reference