LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   can not run simpler perl script from browser (https://www.linuxquestions.org/questions/linux-newbie-8/can-not-run-simpler-perl-script-from-browser-732084/)

vutty 06-10-2009 08:14 PM

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

j-ray 06-11-2009 05:47 AM

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.

vutty 06-11-2009 09:14 PM

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?

j-ray 06-12-2009 04:15 AM

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/

vutty 06-13-2009 12:46 PM

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.

jamescondron 06-13-2009 01:02 PM

If it works, it works; I wouldn't learn perl in that way though

chrism01 06-14-2009 08:26 PM

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


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