Use a cgi-bin directory
A cgi-bin/ directory can be used to enable support for legacy CGI scripts.
When you enable a cgi-bin/ directory,
any executable script or program in the directory can be requested.
Any script or program that outputs a valid HTTP response
including headers can be used as a CGI script.
Enable cgi-bin for an app
To enable a cgi-bin/ directory for an app,
SSH into your server as root and create the following file
(replace APPNAME with the name of the app):
/etc/apache-sp/vhosts.d/APPNAME.d/cgi-bin.confIn the file, add the following contents (do not replace any values shown):
Define CGI_BIN ${DOCUMENT_ROOT}/../cgi-bin/ScriptAlias /cgi-bin/ ${CGI_BIN}<Directory ${CGI_BIN}> Require all granted</Directory>Restart Apache to apply the configuration changes.
sudo service apache-sp restartCreate the cgi-bin directory
Log out of your server as root and
SSH back in as the app’s system user.
Create the app’s cgi-bin directory.
mkdir ~/apps/APPNAME/cgi-binchmod 755 ~/apps/APPNAME/cgi-binTest the cgi-bin directory
You can test the cgi-bin directory by creating a simple CGI script.
Create the file:
apps/APPNAME/cgi-bin/test.shwith the contents:
#!/bin/bashecho "Content-type: text/html"echoecho "Hello, World!"and make the script executable:
chmod 755 ~/apps/APPNAME/cgi-bin/test.shYou can now request the script at
http://DOMAIN/cgi-bin/test.sh using your browser.
Debugging “Internal Server Error” for CGI scripts
If you encounter “Internal Server Error” when making HTTP requests for your CGI scripts, these are the log files you should check for more information about the error:
Apache suEXEC log:
/var/log/apache-sp/suexec.logApache service error log:
/var/log/apache-sp/error.logThe app’s Apache request error log:
/srv/users/SYSUSER/log/APPNAME/APPNAME_apache.error.log