Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

<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

share|improve this question
up vote 0 down vote accepted

You didn't explain where your file resides within the file hierarchy, but I'd guess that you have it in your DocumentRoot.

The problem with this is that your DocumentRoot directory traditionally is used to serve static documents. For security reasons, files in the DocumentRoot hierarchy aren't ever processed (ie executed) - and files in the ScriptAlias directory are never served statically.

You need to separate out your executable content (perl, php, sh) from your statically served content (html files, images, css, js) - so that the webserver knows that files in 'this' directory and below don't need to be processed (such as images), and files in that directory do.

To this end:

  1. Create an index.html file with meta headers that redirect to /cgi-bin/, and put the index.html in the DocumentRoot
  2. Move your to a directory pointed to by ScriptAlias (with a corresponding Directory section - which has +ExecCGI flag). Ensure the is executable, and ensure that its shebang line points to a resolvable perl.

The html output of your can still reference images etc from the root (e.g. put an images folder in your document root folder and reference images from html as /images/logo.png) , and scripts can be linked to (via form submission or href) from your html content from the script folder (e.g. as /cgi-bin/

share|improve this answer
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/. – msinfo Sep 7 '13 at 4:02
finely info helped me to understand problem, and following link helped me to make exact changes to config file and making it work.<a href="…; – msinfo Oct 5 '13 at 7:28

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.