Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl/CGI scripts downloading not running

Status
Not open for further replies.

disturbedone

Vendor
Sep 28, 2006
781
AU
Hi, firstly I'm a relative newbie to Apache and Linux. My issue has been written about by a couple of others on here but I couldn't see a definitive answer.

Here goes...
Very basic install of Ubunutu 9.04 Desktop, Apache2.2, PHP5, MySQL5.1, PHPMyAdmin. I've literally installed that and left it as is. Yes, there is a lot to do to get this secure and configured correctly if I was to place this server publicy but at this stage I just need to get it to work in the lab and then I'll work on the rest of it.

Browsing to gives the Apache "It works!" page. Browsing to works. All ok there.

I've got a very simple MySQL db with one table for a list of names, phone numbers, address etc. I've got a Perl script that opens the db and extracts all the fields and should display it on an HTML page. Running the script from the command line shows what it should - it shows the values of the fields from the db.

The issue is the placement and permissions for the .pl/.cgi file. From my reading the /usr/lib/cgi-bin/ folder should be where I place the file. The /etc/apache2/sites-available/default file has the following which makes me thinlk this...

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
AddHandler cgi-scripts .cgi .pl
Order allow,deny
Allow from all
</Directory>

Regardless of where I place the .pl (or .cgi) file my browser (Firefox 3) on both the local machine and a network machine both ask me if I want to open/save the file rather than the server running the script. I'm accessing this via I'm sure I could place this in another folder if I'd setup multiple virtual hosts but I'm not worried about that just yet.

I've tried adding the 'Options +ExecCGI' & 'AddHandler cgi-scripts' to the default root directory in the /sites-enabled/default file but no change. And restarted Apache too.

Can someone please point me in the right direction to get this to work? Cheers.
 
What do you mean by "installed". CGI, as far as I can see, is not an installable application as such.

As per my post, I have Perl installed and this works on my script from the command line.

In /etc/apache2/mods-enabled/ I have cgi.load so that is "installed".

I've also checked the test.pl file has 755 permissions (also tried 777). But still no luck.

Any other ideas? Thx
 
Unsure exactly what the problem was but it works now.

I've found various forums, help topics, FAQs etc and they vary in their details. Some say to have 'Options +ExecCGI' whereas some say 'Options ExecCGI', or some say 'AddHandler cgi-script cgi pl' and some say 'AddHandler cgi-script .cgi .pl'. So I changed those things, they worked, then I changed them back to what I had and they still worked. Can someone explain the differences?

I also found I had a typo in 'AddHandler cgi-scripts .cgi .pl' instead of what it should be 'AddHandler cgi-script .cgi .pl'.

So all is good now. I did find a quite helpful tutorial at for anyone else who's trying to set this up.
 
I'm not quite sure why things are working the way they are. You shouldn't need +ExecCGI in the cgi-bin. The reason for that is the ScriptAlias directive. The ScriptAlias directive actually does two things. It Aliases the directory so that even though the cgi-bin is actually in /usr/lib/cgi-bin, it will apeart to be in a sub-directory called cgi-bin off the DocumentRoot. The Script part of the directive tells httpd to parse everything in that directory as a script. This is why you shouldn't have html pages in your cgi-bin. The AddHandler directive says that anything with these extensions are scripts. There may be times when you want to run a cgi script in an html directory. That is where you would use the +ExecCGI Option. However, this could slow down the server because it will parse everything in that directory. Earlier I asked if you had cgi installed because I'm not familiar with Ubuntu at all and you said you did a very basic install. Many modules are not compiled into apache and are loaded at runtime. To load these modules they need to be downloaded or installed into the modules directory. The fact that you were able to run perl script from the command line only tells me that you have the perl interpreter installed. To get the script to run interactively over the net, you need the Common Gateway Interface (CGI). In most cases mod_perl and mod_cgi are installed at runtime as modules but this is not always true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top