Apache give each user their own cgi-bin directory

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

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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Randal L. Schwartz Jan 20, 2006 @ 4:48

    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

  • LinuxTitli Jan 20, 2006 @ 13:10


    Thanks for pointing out. Sometime this kind of small problem makes me crazy 🙁

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum