# [SOLVED] Trying to install cgi on Ubuntu Server 9.04



## lcsfsr1 (Sep 22, 2009)

Hello everyone,
I am using Ubuntu Server 9.04 command line version. I have Apache installed and it is working (I am getting the webpage with the words “It Works” on it). I also have PHP5 installed and it is also working (I am getting the webpage that gives all of the information about PHP).

Now this is where the problem arise…CGI. I do not know how to get this CGI stuff installed.

Was CGI installed when PHP or Perl or Apache was installed??
Are these instructions correct??
What is the site configuration file??
What does it mean by <Virtual Host> tags??
I’ve seen some different things as far as the file permissions and making the file executable. 
Should I use chmod a+x or chmod 755 or chmod +x??

These are the instructions that I am using. They are located on this website:
http://www.ubuntugeek.com/how-to-in...phpcgi-and-perl-support-in-ubuntu-server.html

Enable CGI and perl support for apache2 server

You need to install the following package

sudo aptitude install libapache2-mod-perl2

Configure a cgi-bin directory

You need to create a cgi-bin directory using the following command

sudo mkdir /home/www/cgi-bin

Configuring Apache to allow CGI program execution is pretty easy. Create a directory to be used for CGI programs and add the following to the site configuration file (again between the <VirtualHost> tags).

ScriptAlias /cgi-bin/ /home/www/cgi-bin/

<Directory /home/www/cgi-bin/>
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>

The first line creates an alias that points to the directory in which CGI scripts are stored. The final line tells Apache that only files that end with the *.cgi and *.pl extensions should be considered CGI programs and executed.

Test your Perl Program
cd /home/www/cgi-bin

sudo nano perltest.pl

Copy and paste the following section save and exit the file.

###Start###
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello there!<br />\nJust testing .<br />\n";
for ($i=0; $i<10; $i++)
{
praint $i."<br />";
}
###End###
make sure you change permissions on it
sudo chmod a+x perltest.pl
Now open your web browser open http://yourserverip/cgi-bin/perltest.pl.It should be working.


----------



## sultanqasim (Oct 8, 2009)

*Re: Trying to install cgi on Ubuntu Server 9.04*

The instructions make sense. Try them and report back on what happens.


----------



## lcsfsr1 (Sep 22, 2009)

*Re: Trying to install cgi on Ubuntu Server 9.04*

Ok,
First, I created a cgi-bin folder in this location:
/home/www/cgi-bin

It has a sample perl test script in the cgi-bin folder.

Now, I have found the Site Configuration File (with the <VirtualHost> and </VirtualHost> tags. It is located in this directory:

/etc/apache2/sites-available/default

I have entered the required information between the 2 tags.

This Site Configuration File now looks like this:

<VirtualHost *:80>
ServerAdmin [email protected]

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/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</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

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>

ScriptAlias /cgi-bin/ /home/www/cgi-bin

<Directory /home/www/cgi-bin/>
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>

</VirtualHost>


I then changed the permissions on the file as stated. I even rebooted the computer.

Now when I got to http://192.168.0.9/cgi-bin/perltest.pl

I get the following error:

It is an HTTP Error 404

The webpage cannot be found 
HTTP 404 
Most likely causes:
There might be a typing error in the address. 
If you clicked on a link, it may be out of date. 

What you can try: 
Retype the address. 

Go back to the previous page. 

Go to and look for the information you want. 

More information 


Any ideas????

Thanks for the help!

Bobby


----------



## sultanqasim (Oct 8, 2009)

*Re: Trying to install cgi on Ubuntu Server 9.04*

Open the cgi-bin direcory and run "chmod a+rx perltest.pl", and try again. If that doesn't work, put an html page in the cgi-bin folder and call it test.html
Try going to http://192.168.0.9/cgi-bin/test.html

What does your browser say? 404 errors are usually errors with the apache server or permissions.


----------



## lcsfsr1 (Sep 22, 2009)

*Re: Trying to install cgi on Ubuntu Server 9.04*

ok, well to let everyone know...the problem was:
after i went into the site configuration file, i went to the bottom of the file and created a new area...
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">

</Directory>

This was apparently the problem because when i went and deleted this new area, that i created, I combined the my information into the existing ScriprtAlias area. then i went through and did everything again...this time it worked. i am able to successfully run and use perl scripts.

Thank you very much for your help!!!

Bobby Howerton


----------



## lcsfsr1 (Sep 22, 2009)

*Re: Trying to install cgi on Ubuntu Server 9.04*

This problem has be SOLVED.


----------

