Just a thought

Archive for May 7th, 2009

Configuring Apache Web Server (Debian/Ubuntu)

Posted by stringofthoughts on May 7, 2009

Please refer to my other post on installing web server on debian/ubuntu

Before we start, you need to know about the files and directories involved

/etc/apache2 :: Server’s root directory

/etc/apache2/sites-available :: Keeps the configurations files for the hosted sites

/etc/apache2/sites-enabled :: Keeps soft links of hosted sites.

/etc/apache2/ports.conf :: Server port and nameserver config file

/etc/apache2/apache2.conf :: Server’s main configuration file

Let’s assume our user name is saumya. The document root for apache by default is /var/www/. You need to change this.

$ mkdir ~/public_html

This will create a directory for user saumya (/home/saumya/public_html). This is the root directory for her website. We need to change the default document root.

$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/saumya

Edit the new configuration file saumya.

$ sudo gedit /etc/apache2/sites-available/saumya

In the file replace /var/www/ with /home/saumya/public_html . Now enable the new site configuration.

$ sudo a2dissite default  // disables the default configuration.

$ sudo a2ensite saumya // Enables the new configuration

Restart the server.

$ sudo /etc/init.d/apache2 restart

Make a file index.html in /home/saumya/public_html/ and you are done setting up documet root for your website.To test the file open index.html and write a basic html code


Linux is awesome.


save it and open web browser and type http://localhost . If it shows up in the browser everything is working fine.

Assigning IP to server.

By default the server is accessed at or localhost. To assign the IP to server we need to update ports.conf. open the file

$ sudo gedit /etc/apache2/ports.conf

and add a line

Listen  // Replace with your server IP

Restart the server and it’s all done. Now you can access your website with your IP.

Setting up cgi-bin

Setting up cgi-bin is very easy. Make a directory cgi-bin in document root.

$ mkdir ~/public_html/cgi-bin

Open your the configuration file sites-available folder. In our case it’s saumya.

$ sudo gedit /etc/apache2/sites-available/saumya

and add these lines in between <Virtualhost > tags.

ScriptAlias /cgi-bin/ /home/sam/public_html/cgi-bin/
<Directory /home/sam/public_html/cgi-bin/>
Options ExecCGI
AddHandler cgi-script cgi pl

Well Now you ‘ve configured your website completely. This configuration is good for hosting you website on LAN like university campus. If you really want to host your website on Internet you need to learn a lot about securing apache. Let’s leave that for some other day.


Posted in Linux | 1 Comment »

Installing Web Server in Debian/Ubuntu

Posted by stringofthoughts on May 7, 2009

A Friend of mine needed help with the websites they are designing and he asked me for help. The first thing i needed was a webserver with php, python and mysql server. I ‘ve installed web server in Linux many times but i haven’t really learnt it. Everytime I need to search for steps/guidelines on Internet. So I’m just gonna make a walk through for installing web-server in Linux. There are mainly 4 things you need for a fairly good web server. Apache web server with PHP and Python support and a MySQL server for database.

We ‘ll be installing everything one by one.

Installing webserver.

$ sudo apt-get install apache2

This will install Apache web server on your system. Open a browser and type http://localhost it’ll open a webpage telling you it works!!!.I

Installing PHP support for your web server.

$ sudo apt-get install php5 libapache2-mod-php5

After installing php you need to restart your server.

$ sudo /etc/init.d/apache2 restart

To test if the php is working with your webserver.

$ sudo gedit /var/www/testphp.php

insert <?php phpinfo(); ?> in the file testphp.php. Open your browser and type http://localhost/testphp.php . If a page opens displaying the php info then you did it :).

Installing python

$ sudo spt-get install python libapache2-mod-python

Instaling perl

$ sudo apt-get install perl libapache2-mod-perl2

Python and perl are scripting languages.

If you don’t wanna do all this you can use tasksel and choose the task Web Server. It ‘ll install Apache, php, python and peron your system. Tasksel is the easy way.

Now we are gonna install MySQL server.

$ sudo apt-get install mysql-server mysql-client

Setting up root password for MySQL server

$ sudo mysqladmin -u root password “yourpasswd”

MySQL server is almost useless without php. Although you can use other languages like Ruby. So installing php-mysql to make MySQL available to PHP.

$ sudo apt-get install php5-mysql

You can access your mysql server from command line or from php but handle the database in much better ans easy way you need to install phpmyadmin. It’s a awesome tool for administering MySQl over web.

$ sudo apt-get install phpmyadmin

Well now you have installed a very feature rich web server on your system. Check my other post on configuring web server for all the configuration details.

Installing this in ubuntu is very easy. All the packages are bundled together in a task LAMP (Linux Apache MySQL PHP). So for installing web server in ubuntu.

$ sudo tasksel

It’ll show you all the tasks.(See my earlier post on tasksel for details info on tasksel.). Select LAMP by pressing space bar and just OK it. Fully featured web server will be installed in your system.

Posted in Linux | 1 Comment »