I'm running Apache 2.2.14 (Ubuntu 10.04 64-bit). I have it working, responding to requests for html files, and Perl scripts in cgi-bin. It also properly processes index.html and index.php files when I visit a directory. I wanted it to process index.pl files the same way it processes index.php files. I went into mods-enabled/dir.conf and added "index.pl" to the DirectoryIndex line. (Of course, I did apache2ctl restart.). Apache seems to be trying to do something. It recognizes the file. But, my browser (Firefox 3.6.8) prompts "You have chosen to open (no file name provided) which is a text/x-perl. Open or Save." If I choose "save" and view the file, it's serving the script contents, not the execution results. I've googled about this, and everything seems to say all I need to do is add "index.pl" to the DirectoryIndex line. I've studied all the configuration entries for php to see if something stands out about why it works. But, nothing does. I get the impression I need to set a handler or add a type. But, I'm not sure how to do that when I'm not directly referencing a .pl file. It's really accessed as "/path/". Anyone have any ideas?
I want to update my post in case anyone stumbles across it in the future. My Firefox browser apparently cached one of my unsuccessful tests (when it prompted me to open/save). After that, even though I had set my Apache 2.2 configuration correctly, the browser used the cached Text/Pl or text/x-perl results, and continued to prompt me to open/save as if it was responding to the server. I didn't notice this incongruity until I deleted the index.pl file and the browser kept prompting me to open/save. (Scratching my head... How could that be when the file doesn't exist any more? And, the access log doesn't show any activity? Why didn't I go to truck driving school? Why oh why???). On a hunch I cleared my browser cache. Suddenly I got an index listing of the directory, which is what I expected since no index.* files existed, and I had Options +Indexes defined for the directory. I recreated index.pl and suddenly it worked!!!! To recap, to enable index.pl, you have to: 1. Add "index.pl" to mods-enabled/dir.conf. If the file doesn't exist, then the "dir" mod hasn't been enabled. You'll have to enable it. (See note below about how you can also add the DirectoryIndex directive to your .htaccess file.). 2. Add the following to the directory definition in your server config or virtual host definition: Options +ExecCGI AddHandler cgi-script .pl Code (markup): Alternatively, you could use a .htaccess file in the directory and place the above two directives in it. Alternatively, if you don't want to enable CGI processing for the entire directory, you could place the following block in that .htaccess file: <Files index.pl> Options +ExecCGI SetHandler cgi-script </Files> Code (markup): There are other ways to do this, such as using wildcards with the FilesMatch directives in the server config, applying the above two directives to index.pl files in any directory. (If you copy the examples above, be aware that mixing options prefixed with +/- with options that aren't can lead to unpredictable results. Give consideration to how the options may already be set. Study the Apache 2.2 documentation to understand how +/- and non-prefixed options interact.). Also, you can put the DirectoryIndex in the .htaccess file if your host provider won't add index.pl to the mod_dir's dir.conf file. The dir.conf file comes with index.cgi Your host provider may tell you to name your files thusly instead. You could change all references in this post from index.pl to index.cgi. Or, add the following to your .htaccess file if you're fond of the .pl extension: DirectoryIndex index.pl Code (markup): Also, be aware that if your configuration ever comes undone, it could display the content of your scripts. If your index.pl files contain any significant logic, you should put all that logic in a file kept outside your document root directory. Use a "require" statement to pull that code into your script. Then, if your script is ever displayed instead of executed, nobody will see much. Anyway, I wanted to give 2-3 examples of how to enable index.pl files. BUT, MORE IMPORTANTLY, I wanted to point out that, if you get anything wrong, and are prompted to open/save the results of accessing an index.pl, CLEAR YOUR BROWSER'S CACHE or YOU'LL NEVER GET BEYOND THE OPEN/SAVE PROMPT -- ever!!!. (This may only affect you if you actually save or open. Canceling that prompt may not result in you getting stuck with the caching problem I experienced. But, if there's any doubt, clear your cache each time until you get it working!!!).