Below are the steps to get Apache and Perl running in simple steps. I am running all commands with root access. (sudo bash). In real life it is recommended that use sudo. So preceede all commands with sudo.
1. install apache-2
apt-get install apache2
2. start the apache server
/etc/init.d/apache2 start
3. In case you make changes you can either restart or just reload the apache2 server
/etc/init.d/apache2 stop
/etc/init.d/apache2 restart
/etc/init.d/apache2 reload
4. To remove apache2. Do not remove the /etc/apache2 folder
apt-get remove apache2
5. In case you remove the /etc/apache2 folder, you may not be able to reinstall the apache server. In that case do the following.
apt-get remove --purge apache2
apt-get remove --purge apache2.2
apt-get remove --purge apache2.2-common
6. Perl is already installed by default. You can do the following to do a test.
perl -h
7. You will need libraries for perl to work with apache2.
apt-get install libapache2-mod-perl2
8. Important Locations
a. /var/www is the default folder for apache.
b. /etc/apache2/apache2.conf is the configuration file.
c. /etc/apache2/ports.conf is the file which talks which port apache2 listens. By default it is 80.
d. /etc/apache2/sites-available is the folder where you put the sites available.
9. Open a browser and enter http://127.0.0.1/ and if you see It Works. Apache is installed successfully.
10. You need a FQDN (a domain name). Let us say for testing you are using the domain skranga.test.com Then do the following
in the /etc/hosts file.
127.0.1.1 ubuntu
192.168.101.133 skranga.test.com myserver
How does Apache know that you want to use your hostname as skranga.test.com (in the above example).
To do this. Open the /etc/apache2/apache2.conf and add the following line anywhere.
ServerName "skranga.test.com"
11. Goto the /etc/apache2/sites-available folder
Open the file default
-------------------------------------------------------------------------
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
AddHandler cgi-script cgi pl
Order allow,deny
Allow from all
</Directory>
------------------------------------------------------------------------
Note : Edit the ScriptAlias so that you give the folder where you will have your scripts.
In the above case it is /var/www/cgi-bin. You have to create the cgi-bin folder.
mkdir /var/www/cgi-bin
Add the line, AddHandler cgi-scripts cgi pl
(this tells apache to execute the files with extention cgi or pl)
Also if you read the full file, you will see a line like this.
DocumentRoot /var/www
This means all your html files will be in this directory.
12. Now to test everything is running, do the following.
a. goto the /var/www folder. Edit the index.html file. You can use test code like this.
---------------------------------------------------------------------
<html>
<body>
<h1>Welcome to Apache2</h1>
<p>---------------------------------------------</p>
<p></p>
<br>
Click <a href="http://skranga.test.com/cgi-bin/test.pl">Here </a>
</body>
</html>
----------------------------------------------------------------------
In the /var/www/cgi-bin folder, add the file test.pl, with the following contents
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "testing...\n";
Save it. and give it execute permissions.
chmod a+x test.pl
13. Now open a browser and enter http://skranga.test.com/ and you should see the page ("Welcome to Apache2")
And when you click on the link, it should execute your script.
=========================================================
Comments/Suggestions/Errors. Please write to .
Suresh Ranga
skranga2011@gmail.com
8th May 2011.
(No Copyrights on this document, Please use freely)
=========================================================