Skip to content

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.conf

In 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 restart

Create 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-bin
chmod 755 ~/apps/APPNAME/cgi-bin

Test 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.sh

with the contents:

#!/bin/bash
echo "Content-type: text/html"
echo
echo "Hello, World!"

and make the script executable:

chmod 755 ~/apps/APPNAME/cgi-bin/test.sh

Now request the script in your browser:

http://DOMAIN/cgi-bin/test.sh

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.log

Apache service error log:

/var/log/apache-sp/error.log

The app’s Apache request error log:

/srv/users/SYSUSER/log/APPNAME/APPNAME_apache.error.log