LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   configuring cgi on ubuntu (https://www.linuxquestions.org/questions/linux-newbie-8/configuring-cgi-on-ubuntu-786121/)

casperdaghost 02-01-2010 12:40 AM

configuring cgi on ubuntu
 
when i try to copy this script to the cgi folder, i get an error

casper@casper-laptop:~$ cp /home/casper/hello.cgi /usr/lib/cgi-bin
cp: cannot create regular file `/usr/lib/cgi-bin/hello.cgi': Permission denied
casper@casper-laptop:~$

#!/usr/local/bin/perl
# hello.pl -- my first perl script!
print "Content-type: text/html\n\n";
print <<"EOF";
<HTML>
<HEAD>
<TITLE>Hello, world!</TITLE>
</HEAD>
<BODY>
<H1>Hello, world!</H1>
</BODY>
</HTML>
EOF

i am running apache on ubuntu ibex - is there something that i have to setup to run cgi scripts on ubuntu? it runs ok from the command line - but i want to open it up in a web browser.

Tinkster 02-01-2010 12:44 AM

Do the cp via sudo

And /usr/local/bin/perl strikes me as an odd location for
perl on Ubuntu. What happened there?


Cheers,
Tink

casperdaghost 02-01-2010 09:59 PM

yeah you are right about the perl path.
i did not copy the file into /usr/lib/cgi-bin yet. - that seems harsh.



I have apache running - but when I run the cgi script is just shows up as plain text in terminal - it does not pop into the browser - lie i thought it would.

I can browse to it from firefox file:///home/casper/hello.cgi - but again it shows up at plain text in the browser, html tags and all.

do all cgi scripts have to go into a cgi-bin folder to work? do i have to configure apache to accept these scripts?
i am trying ot run the script locally on my laptop - not a web server - but i have apache running on the laptop

Tinkster 02-01-2010 11:00 PM

Yes, they need to be in a directory that is flagged to apache as
part of the cgi path.


Cheers,
Tink

casperdaghost 02-18-2010 01:49 PM

cgi - configuration
 
I created a new website:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/casperdaghost

Edited the DocumentRoot /home/casper/public_html and the <Directory /home/casper/public_html/> in the new sites configuration fle - the site works great on http://127.0.0.1.

I added a cgi-bin directory to the public_html directory, and edited the ScriptAlias as follows:

ScriptAlias /cgi-bin/ "/home/casper/public_html/cgi-bin/"
<Directory "/home/casper/public_html/cgi-bin/">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

I chmod cgi script:
-rwxr-xr-x /home/casper/public_html/cgi-bin/testscript.cgi

When browsed in Firefox the script displays the raw html code, not a "Hello, World".

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print <<END_HTML;
<html>
<head></head>
<body>Hello, World!</body>
</html>
END_HTML


I don't know if it is configuration error, or an error in the code. Anybody got any other Apache configuration examples?


All times are GMT -5. The time now is 05:06 PM.