How to enable the server to run CGI programs

The iSeries™ server stores some CGI programs in QSYS.LIB. You can write the programs in C++, REXX, ILE C, ILE RPG, or ILE COBOL. If the UserID directive is not active, the server profile QTMHHTP1 needs access to the *PGM object and all objects the program accesses. If the UserID directive is active, the UserID profile needs access to the *PGM object and all objects the program accesses. The ScriptAlias directive is required in HTTP Server (powered by Apache) configuration to run a CGI program on the server.

Here is a summary of the steps you need to take to enable your server to run CGI programs:

  1. Decide for which CGI mode you will write your program.
  2. Write the C++, REXX, ILE C, ILE RPG, or ILE COBOL program.
  3. Compile your program, if required.
  4. Create a directory structure for your program using MKDIR.
  5. Transfer your program to the new directory.
  6. If you are using HTML, set the source type using CHGPFM.
  7. Create the program object using CRTCMOD and CRTPGM.
  8. Ensure that your program has the correct authority using *PUBLIC, QTMHHTTP or QTMHHTP1.
  9. Create a new server instance to associate with your program.
  10. Make any changes to your server configuration file that are needed. For example, you need to add the Exec or ScriptAlias directive at a minimum.
  11. Start or restart the server.
  12. Point your web browser to the URL for the HTML document on the server where hostname is the fully qualified host domain name of your server.
    http://hostname/sample
    Note: For REXX programs, you only need to indicate the path and the file name in the EXEC or ScriptAlias directive. REXX CGI execs must reside in database files named REXX or QREXSRC. For example:
    EXEC /REXX/* /QSYS.LIB/AS400CGI.LIB/QREXSRC.FILE/*

    Or in HTTP Server (powered by Apache):

    ScriptAlias /REXX /QSYS.LIB/AS400CGI.LIB/QREXSRC.FILE/*

    The URL is :

    http://hostname/REXX/samplecgi.REXX