Sunday, November 2, 2008

::Howto have your own web server on your ubuntu machine::

[This article was written during the earlier version of ubuntu:dapper drake, am not sure whether it's still applicable with the latest version of ubuntu. But just for a knowledge sharing, here you go dudes!]

If you a have an ubuntu box (I assume that you have a box installed with dapper drake) connected to the internet through broadband service, you could have a possibility to run your own web server on your linux box. Follow the instructions below in order to build your own web server.

What starter kit do you have to have?

1. Apache 2.0 - web server
2. PHP5 - server side programming language
3. PHP5 module for Apache 2.0
4. MySQL server - database server

Alright here we go, just enter the command below than you will have everything ready for you.

$ sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

OK now you can open your browser and type http://localhost, if you see an Apache web page appeared, than your web server is already up. Instead of that you also can use ps command to check whether the apache2 web server and mysql server demon is up.

$ ps aux|grep apache2
$ ps aux|grep mysqld

later, you can use this command to stop, restart, your apache2 and mysql server demon:

$ sudo /etc/init.d/apache2 stop | restart | start
$ sudo /etc/init.d/mysql stop | restart | start

Now your web server is already up and here you can upload your personal webpage into Apache webroot directory. In default, the webroot directory is located in /var/www/. To make your work later easier for uploading, deleting, editing your web pages, it is suggested that you change the default webroot to your a directory in your home directory. The instructions below will show you how to do this:

First, edit /etc/apache2/sites-available/default file

$ sudo vi /etc/apache2/sites-available/default

find this statement:

DocumentRoot /var/www

and change it to the preferable directory in your home directory (assume the home directory here is my_ubuntu):

DocumentRoot /home/my_ubuntu/public_html

Now, restart the apache,

$ sudo /etc/init.d/apache2 restart

then enter http://localhost at the address bar of your browser, you should get this page appeared on the screen:

Index of /

Icon Name Last modified Size Description
Apache/2.0.55 (Ubuntu) PHP/5.1.2 Server at localhost Port 80

Ok, now create a simple web page using html language for a testing.

Open any text editor such as gedit and write a simple html code, say a Hello World! code. Save it as index.html or index.htm into your webroot directory (/home/*/public_html). Then once again enter http://localhost at the browser address bar and you will see your first web page welcoming you there, congratulation dude!.

Ok, so far you have successfully setup the web server on your linux box, but you have to know that until this point your web page only can be viewed internally on your box. How to make your web page viewable worldwide? just follow the simple instructions below:

1. Go to and open an account there.
2. After you receive confirmation e-mail from, click to the link given to activate your account.
3. On your dyndns account, go to menu My Hosts on your left side, and add host services there for your dynamic DNS.

There, you can select your preferably hostname from the list. Let say you account name is xxx and you could select your hostname as After everyting is done, you can test whether your hostname is correctly run or not by entering at the browser. If your website appeared successfully on the screen, and your friend also can view your website then congratulation once again, your are now on a right path to be a web master hahaha baka!

No comments: