Wednesday, May 18, 2011

Installing Apache and Perl. The easy way.

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)

=========================================================

Saturday, May 07, 2011

Apache on Ubuntu. Install/Uninstall

=> i like to change to root, though this is not recommended. please use sudo.

skranga@ubuntu:~$ sudo bash

[sudo] password for skranga:

=> get the version of ubuntu

root@ubuntu:~# cat /etc/issue

Ubuntu 10.10 \n \l

=> install apache now (please add sudo before the command if you are running as root. Please be patient it can take time to install the software, on a slow connection.

root@ubuntu:~# apt-get install apache2

Reading package lists... Done

* Starting web server apache2 [ OK ]

Setting up apache2 (2.2.16-1ubuntu3.1) ...

Processing triggers for libc-bin ...

ldconfig deferred processing now taking place

=> Open a browser and enter http://localhost

If Apache is installed successfully you should see something like this

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

=> How to start, stop and check status of the Apache Server.

root@ubuntu:~# /etc/init.d/apache2 status

Apache2 is running (pid 13872).

root@ubuntu:~# /etc/init.d/apache2 stop

* Stopping web server apache2 ... waiting [ OK ]

root@ubuntu:~# /etc/init.d/apache2 start

* Starting web server apache2 [ OK ]

root@ubuntu:~#

=> How to uninstall Apache. I selected no in the below example. You should select Yes if you wish to uninstall it.

root@ubuntu:~# apt-get remove apache2

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following packages were automatically installed and are no longer required:

apache2-mpm-worker libapr1 libaprutil1-ldap apache2-utils apache2.2-common libaprutil1-dbd-sqlite3

apache2.2-bin libaprutil1

Use 'apt-get autoremove' to remove them.

The following packages will be REMOVED:

apache2

0 upgraded, 0 newly installed, 1 to remove and 323 not upgraded.

After this operation, 36.9kB disk space will be freed.

Do you want to continue [Y/n]? n

Abort.