Apache has public_html directory support. With this you specify the name of the directory which is appended onto a user's home directory if a ~user request is received. For example http://domain.com/~rocky/file.html will be rocky's home directory /home/rocky/public_html/file.html. Recently I took small part time job to setup web server for university. I want to give every student access to cgi-bin so that they can use perl. I don't wanna give everyone access to /var/www/cgi-bin or /usr/lib/cgi-bin directory. ScriptAliases enables documents in the cgi-bin directory treated as applications and run by the server when requested rather than as documents sent to the client. So first I did setup ScriptAlias. However it was not working.
So all students was able to see each others perl source code :( so I was called again to fix this problem. After searching little bit, I found solution from offical Apache docs. So I modified httpd.conf and added following two directives to /home/*/public_html/cgi-bin section:
Options ExecCGI SetHandler cgi-script
At the end final entry looked like as follows:
<Directory /home/*/public_html/cgi-bin> Options ExecCGI SetHandler cgi-script </Directory>
Then I restarted apache and it worked like a charm. See Apache document Dynamic Content with CGI. Update: As pointed out by Randal you just need to add above four lines.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 2 comments… read them below or add one }
Doing it this way means that you can’t have ordinary files, because all executables are treated as CGI programs, and all non-executables are treated as 500 errors!
Perhaps what you should have done is created a subdirectory under each public_html called “cgi-bin”.
Then you could have added:
<Directory /home/*/public_html/cgi-bin>
Options ExecCGI
SetHandler cgi-script
</Directory>
Randal,
Thanks for pointing out. Sometime this kind of small problem makes me crazy :(