Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 index.pl file to download instead of executing it. What I tried:
1. chmod 755 index.pl
2. Adding line DirectoryIndex index.pl index.html to etc/apache2/site-available/example.com, 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
        ServerName example.com
    DocumentRoot /var/www/example.com/public_html
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/example.com/public_html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
# This line was added by me
DirectoryIndex index.html index.pl
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    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 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

You didn't explain where your index.pl 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/index.pl, and put the index.html in the DocumentRoot
  2. Move your index.pl to a directory pointed to by ScriptAlias (with a corresponding Directory section - which has +ExecCGI flag). Ensure the index.pl is executable, and ensure that its shebang line points to a resolvable perl.

The html output of your index.pl 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/processform.pl)

share|improve this answer
    
My index.html has meta tag as follows: meta http-equiv="refresh" content="0; URL='cgi-bin/index.pl'". Index.html file resides in var/www/example.com/public_html folder. In this folder I created folder cgi-bin with index.pl file in it. The browser when typed localhost give following error: 404 /cgi-bin/index.pl was not found on this server. And configuration file called example.com (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="webmasters.stackexchange.com/questions/53184/…; –  msinfo Oct 5 '13 at 7:28

Your Answer

 
discard

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.