LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


hi,



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:
#!/usr/bin/perl
print "Content-type: text/html\r\n\r\n";
print "Hello, World.";

name of perl script is: perltest.pl



this is my whole config file word for word:

NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>


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
</Directory>

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

</VirtualHost>

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/perltest.pl' failed
[Wed Jun 10 20:37:29 2009] [error] [client 192.168.*.*] Premature end of script headers: perltest.pl

OS: UBUNTU 8.04
Web Server: Apache2
site where I followed instructions from:
http://www.ubuntugeek.com/how-to-ins...tu-server.html
 
Old 06-11-2009, 05:47 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,545

Rep: Reputation: 136Reputation: 136
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/test.pl

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

Last edited by j-ray; 06-11-2009 at 06:01 AM.
 
Old 06-11-2009, 09:14 PM   #3
vutty
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, 04:15 AM   #4
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,545

Rep: Reputation: 136Reputation: 136
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:
http://httpd.apache.org/docs/2.2/vhosts/
 
Old 06-13-2009, 12:46 PM   #5
vutty
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, 01:02 PM   #6
jamescondron
Member
 
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, 08:26 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
If you're going to learn Perl, you'll need this: http://perldoc.perl.org/, particularly see the Tutorials link , upper left.
Also, http://www.perlmonks.org/?node=Tutorials
 
  


Reply


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 03:29 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 09:56 AM
unable to run perl script using browser madhuri Debian 3 12-02-2005 04:46 PM
unable to run perl script using browser madhuri Linux - Distributions 1 11-22-2005 02:19 PM
PERL script OK at command line, not in browser alvo Programming 4 12-19-2004 08:28 AM


All times are GMT -5. The time now is 11:50 AM.

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