Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have installed Apache 2.2.22 on Ubuntu 12.04. But in browser when I type localhost, it gives file to download instead of executing it. What I tried: 1. chmod 755 2. Adding line DirectoryIndex index.html to etc/apache2/site-available/, which finally looks like below.

I have done these things before on Windows machine. But the directory structure is different in Windows and Ubuntu. Httpd.conf file is blank in Ubuntu. And while searching through directories I found no. of files similar to configuration file. So I am confused where exactly I have to make configuration changes.

Update: My index.html has meta tag as follows: meta http-equiv="refresh" content="0; URL='cgi-bin/'". Index.html file resides in var/www/ folder. In this folder I created folder cgi-bin with file in it. The browser when typed localhost give following error: 404 /cgi-bin/ was not found on this server. And configuration file called (etc/apache2/sites-available) has following line: ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
# This line was added by me
DirectoryIndex index.html
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128


Update:Below is changes which I made after following krowe's suggestions, and it worked.

ScriptAlias /cgi-bin/ /var/www/
<Directory "/var/www/">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    AddHandler cgi-script .cgi .pl
    Allow from all
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Add this line to your /etc/apache2/apache2.conf file:

AddHandler cgi-script .cgi .pl

And put your scripts in /usr/lib/cgi-bin/ .

Ubuntu separates its server configuration from its site configuration. Look in your /etc/apache2/sites-available directory for the virtual host configurations. Then create links to those in /etc/apache2/sites-enabled to enable them.

Restart your server after changing any of this: sudo service apache2 restart

You should be able to access it from:

Also, I would not use a DirectoryIndex index.html line at all. Just specify your exact cgi file when needed.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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