Apache2 Web Server in Ubuntu

Posted by NGTHFONG - 阮・青・風 On Friday, December 11, 2009 0 コメント

Install Apache Web Server on Ubuntu

This step-by-step howto shows a basic setup for Apache 2 web server. Apache is installed on Ubuntu 6.06 LTS Dapper, but instructions will probably work on any Ubuntu. This document is a work in progress, initially only required commands are listed without troughout explanations.
© 2006 Tero Karvinen. GNU General Public License, version 2.

Install Apache

$ sudo apt-get install apache2

Test it


Surf to your own server on your own local computer:
$ firefox "http://localhost"
Find out how your server is found on the net. Anyone can use your IP address or DNS name to connect to your server:
$ ip addr
Use your own IP address (eth0, first IP number, does not end .255)
$ firefox "http://1.2.3.4"
If DNS is working on your network, you can see your fully qualified domain name with:
$ host 1.2.3.4

User homepages

With user homepages, anything you put in public_html in your home directory is published on the web.

Enabling Userdir on Server

For newer Ubuntu such as 8.04 Hardy, you have to explicitly enable userdir module. On older ones such as 6.06 LTS Dapper, userdir is enabled by default.
$ sudo a2enmod userdir
$ sudo /etc/init.d/apache2 restart

Configuring - Create a new Apache site

To create a new site, first create a directory where you want to keep files associated with this site. I like to keep sites in my home directory so (using my user name of sam) I create a /home/ngthfong/public_html directory. The configuration files for all sites available to Apache are stored in the /etc/apache2/sites-available/ directory. Create a configuration file for your new site (here called zaphu) by copying the configuration file for the default site.
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/zaphu
Open the new configuration file.
sudo vi /etc/apache2/sites-available/zaphu
You will notice that there is a lot of stuff between tags. You have to edit some of this. Change the DocumentRoot path to point to the newly created site directory.
DocumentRoot /home/ngthfong/public_html
In a similar fashion, change one of the Directory directives (it looks something like this)

to be consistent with your site path.
ngthfong/public_html/>
After making these changes, disable the default site using the Apache disable site script.
sudo a2dissite default
Next, use the Apache enable site script to activate the new site.
sudo a2ensite zaphu
Finally, restart Apache.
sudo /etc/init.d/apache2 restart
Create a simple index.html file and save it in /home/ngthfong/public_html/ to test your new site. Something simple like

Welcome to NGTHFONG's New Apache Web Server (^^)/

Browse (preferable on another machine) to your new site to test the configuration.
Congratulation!
Now you've finished installing the Apache2 Web Server.

Thanks for reading. Did you enjoy this post?

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Comment by facebook?

Post a Comment

Viết cảm nhận của bạn ở đây ... Leave your feelings here ....

Recent comments