First you need to setup your HTTP server to allow CGI:
On the as400 the HTTP server jobs run in the subsystem QHTTPSVR. You will see groups of jobs running for each HTTP Server instance (each configured HTTP Server).
To gain access to the confirguration of the HTTP server you can use the green screen command Work with HTTP Configuration (WRKHTTPCFG), but I much prefer the browser based HTTP Admin client.
To use this you must have started you HTTP Server admin instance using STRTCPSVR SERVER(*HTTP) HTTPSVR(*ADMIN). This will start the QHTTPSVR subsystem if it is not active, and then start the ADMIN instance.
In your browser, Go to http://youras400name:2001/. You will need to login with an authorised as400 logon at this point.
At the AS400 tasks screen click on IBM HTTP Server. At this point you need to either select an existing HTTP server, or setup a new HTTP Server using the wizard.
Click the Add a Directory to the Web task. Click CGI programs, and click next.
Enter the serving directory (as400 program library), and clicked next,
enter Alias (url to be used to invoke the as400 CGI program), click next.
Restart the HTTP server.
Now you can serve CGI. Here is a sample RPG CGI Program
Create a binding directory for the CGI service program:
CRTBNDDIR, and add QHTTPSVR / QZHBCGI (*SVRPGM) to it.
H bnddir('CGI') * New Line Constant DCRLF C CONST(X'0D25') C EVAL OUTTXT = 'Content-Type: text/html'+CRLF+CRLF C EXSR OutputText C EVAL OUTTXT = '
Hello World C EXSR OutputText C SETON LR C RETURN C OutputText BEGSR C ' ' CHECKR OUTTXT OUTLEN C CALLB 'QtmhWrStout' C PARM OUTTXT C PARM OUTLEN C PARM ERRCDE C ENDSR
This would get invoked by something such as a URL like http://your-server/your-cgi-bin/helloworld
and as400 Bobs your uncle!