About nixCraft

Topics

Apache give each user their own cgi-bin directory

Posted by Vivek Gite [Last updated: January 19, 2006]

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.

Tell us how we're doing: Please answer a few questions about your experience to help us improve nixCraft.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Randal L. Schwartz Says:

    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>

  2. LinuxTitli Says:

    Randal,

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

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.