Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-10-2009, 09:14 PM   #1
LQ Newbie
Registered: Jun 2009
Posts: 9

Rep: Reputation: 0
can not run simpler perl script from browser


I have recently installed ubuntu linux and also setup apache2 web server with cgi and perl. went into my config file in apache2 and set the scriptalias folder to /home/www/cgi-bin instead of keeping the default which was /var/www/.

created the simplest perl file, made sure the script was going back to /usr/bin/perl path, set proper permissions for perl script (755) and also set directories as well. set my ip as static and made sure it was my localhost. when i try to run the perl file in my browser it gives me an "exec format error". please help...

perl script:
print "Content-type: text/html\r\n\r\n";
print "Hello, World.";

name of perl script is:

this is my whole config file word for word:

NameVirtualHost *
<VirtualHost *>
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

ScriptAlias /cgi-bin/ /home/www/cgi-bin/
<Directory /home/www/cgi-bin/>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
AddHandler cgi-script cgi pl

ErrorLog /var/log/apache2/error.log

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

CustomLog /var/log/apache2/access.log combined
ServerSignature On

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


the path to my config file is /etc/apache2/sites-available/default.
*sorry if I'm getting a little too semantic, i'm just frusturated...

this is what my (firefox) browser returns:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Apache/2.2.8 (Ubuntu) mod_perl/2.0.3 Perl/v5.8.8 Server at 192.168.*.* Port 80

error log:

[Wed Jun 10 20:37:29 2009] [error] (8)Exec format error: exec of '/home/www/cgi-bin/' failed
[Wed Jun 10 20:37:29 2009] [error] [client 192.168.*.*] Premature end of script headers:

Web Server: Apache2
site where I followed instructions from:
Old 06-11-2009, 06:47 AM   #2
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,534

Rep: Reputation: 132Reputation: 132
try that declaration
print "Content-type: text/plain\n\n"; -->no that won't help

you declare everything in a <VirtualHost> tag. All declarations are only valid in this virtual host but I think you want them to be public if you call the scipt http://localhost/cgi-bin/

If you use virtual hosts then you better give them names I think.

Last edited by j-ray; 06-11-2009 at 07:01 AM.
Old 06-11-2009, 10:14 PM   #3
LQ Newbie
Registered: Jun 2009
Posts: 9

Original Poster
Rep: Reputation: 0
i think i understand what your saying about making it public but give what names? should i just comment out the virtual tags to troubleshoot?
Old 06-12-2009, 05:15 AM   #4
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,534

Rep: Reputation: 132Reputation: 132
yes, would be worth trying to simply comment out the virtual host tags. You can run
apache2ctl configtest
to see if there's something wrong with the configuration... (if apache2ctl is not in a directory in the $PATH you have to give the complete path/to/apache2ctl)

For more info on vhosts:
Old 06-13-2009, 01:46 PM   #5
LQ Newbie
Registered: Jun 2009
Posts: 9

Original Poster
Rep: Reputation: 0
tried commenting out the <virtualhost> tags and that didn't work. tried setting the $path env variable to path etc/init.d/apache2ctl

i think i did that one wrong...

command was

export /etc/init.d/apache2ctl

make sure u copy whats in $PATH first because the export command copies over all the other paths already in there. then export what was in there already and add what u want at the end.

ie: export /whatever was in here before:/etc/init.d/apache2ctl

anyway- ended up finding a different perl script sample and pating that in.

#!/usr/bin/perl -w

# Tell perl to send a html header.
# So your browser gets the output
# rather then <stdout>(command line
# on the server.)
print "Content-type: text/html\n\n";

# print your basic html tags.
# and the content of them.
print "<html><head><title>Hello World!! </title></head>\n";
print "<body><h1>Hello world</h1></body></html>\n";

the difference was that i needed to add the html tags...
so i should be ok right. i can start learning perl now or was this a wrong fix.
Old 06-13-2009, 02:02 PM   #6
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
If it works, it works; I wouldn't learn perl in that way though
Old 06-14-2009, 09:26 PM   #7
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,254

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
If you're going to learn Perl, you'll need this:, particularly see the Tutorials link , upper left.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to run script on the server from client machine in windows in a perl script vpradeep Linux - Newbie 2 09-01-2008 04:29 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 10:56 AM
unable to run perl script using browser madhuri Debian 3 12-02-2005 05:46 PM
unable to run perl script using browser madhuri Linux - Distributions 1 11-22-2005 03:19 PM
PERL script OK at command line, not in browser alvo Programming 4 12-19-2004 09:28 AM

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration