Configuring User Directories with CGI Scripting in Apache

Objective:
Each user must be able to execute cgi scripts from within their home directories.
~/public_html/cgi-bin

References:
http://httpd.apache.org/docs-2.0/howto/cgi.html
http://cri.ch/linux/docs/sk007.html

First, change the httpd.conf to point to the cgi-bin directory to the user’s public directory.
ScriptAlias /cgi-bin/ /home/*/public_html/cgi-bin/

/home/*/public_html/cgi-bin>
AllowOverride None
Options +ExecCGI +Includes +Indexes
Order allow,deny
Allow from all

AddHandler cgi-script .cgi .sh .pl

—–
1. Set the permissions for directories.

/home/ must have 711 permissions
/home/public_html must have 755 permissions
and all files in public_html must be world-readable.

2. Activate the ~user directories

Edit httpd.conf.
- UserDir for user root:
UserDir disabled root
- UserDir is defined as public_html

Note:
Do 3.a. only if you want to set it for a single user.
For multiple users, you need to configure each ScriptAlias separately.
In such a case, it is better to use 3.b.

3. a. Define a ScriptAlias
ScriptAlias /~sven/cgi-bin “/home/sven/public_html/cgi-bin/”

3.b. Add the Option ExecCGI
The option ExecCGI can be defined at a level in httpd.conf.

Following definition gives each user to run cgi-scripts from his ~/cgi-bin directory:

/home/*/public_html/cgi-bin>
AllowOverride None
Options +ExecCGI +Includes +Indexes
Order allow,deny
Allow from all

Errors that might occur: (and it did for me, for a most stupid reason - ME)

Premature end of script headers

Short answers:
1. Check the execute permission of the script.
2. Deactivate or rename suexec.

Detailed explanation:
http://httpd.apache.org/docs-2.0/howto/cgi.html

Log files:

/var/log/httpd/error_log
/var/log/httpd/suexec.log

Commands:
apachectl -V
apachectl restart

Leave a Reply