I've set up a CGI directory using the userdir mod in Apache. I'm using configs as general as possible to have them appliable to other users on my laptop. I got to a point where I can run the script using this URL:


But I also put a link to my public_html in the server's root directory at /var/www/html, so when the localhost URL is called, I get the index with a link to my dir at localhost/tomas. The link works fine and brings up another index, one of my user. Now, the private cgi-bin is at /home/*/public_html/cgi-bin, so I can see the cgi-bin when I get the private index. Now, when I enter this directory, I get another index with the CGI's. Which is fine with me, though I'm not sure if this is considered secure. But if I call a CGI from there, it doesn't execute and shows instead. This is the problem.

As far as I know, it's about Apache not viewing




I've been looking for a directive that would make it work, but can't find it. I'm not even quite sure what's at my disposal - a directive or what else?

Here's my usermod.conf:

<IfModule mod_userdir.c>
    UserDir public_html
    UserDir disabled root

    <Directory /home/*/public_html>
        AllowOverride FileInfo AuthConfig Limit Indexes
        Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
        <Limit GET POST OPTIONS>
            Require all granted
        <LimitExcept GET POST OPTIONS>
            Require all denied

    <Directory /home/*/public_html/cgi-bin>
        Options ExecCGI
        AddHandler cgi-script .cgi
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Since the cgi-bin directory can be reached through a separate path, one way to do it is to copy the Directory section with the alternate path, right below the other one, e.g.:

<Directory /var/www/html/*/cgi-bin>
    Options ExecCGI
    AddHandler cgi-script .cgi

This should also disable the directory listings.

If you'd prefer to have indexes enabled, either add Indexes to Options or make it inherit its parent options by changing ExecCGI to +ExecCGI, e.g.

<Directory /var/www/html/*/cgi-bin>
    Options Indexes ExecCGI
    AddHandler cgi-script .cgi

I'd prefer using Options Indexes ExecCGI over Options +ExecCGI since this way you won't be inheriting any undesired options.

  • Why are indexes disabled now? – Tomasz Jun 2 '17 at 11:31
  • @tomas because Options does not include Indexes and it overwrites the Options set in the parent directory. I'll update my answer to reflect this. – outlyer Jun 3 '17 at 1:40
  • Thanks. I also used a syntax with SetHandler, which apparently disables indexes. AddHandler works fine. – Tomasz Jun 3 '17 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.