GNU Linux


HOWTO - How I configure my local Apache server


There should be a blue line here

Table of Contents

There should be a blue line here

1. Install the Packages Packages for Apache

Install command
sudo apt-get install apache2 apache2.2-common apache2-doc 

There should be a blue line here

2. Stopping, Starting and Restarting Your Web Server

This is really simple just run the apache2 script in /etc/init.d with stop, start or restart. I bet you worked that out already

Code:
sudo /etc/init.d/apache2 stop 
sudo /etc/init.d/apache2 start 
sudo /etc/init.d/apache2 restart 

There should be a blue line here

3. If you see an error like this

Example Error Message
apache2: Could not determine the server's fully qualified domain name, using 192.168.0.1 for ServerName 

Apache cannot work out the domain name of your server machnie or perhapes you simply do not have a domain name setupone. Not to worry it is simple to fix. Edit /etc/apache2/apache2.conf add the ServerName option. Use the output from the Linux command uname -n as the value. I add the line after ServerRoot. Then restart the apache server and you are done. So for my example server called linux32 we would do the following.

Code:
uname -n 
linux32     # <<== output from the uname -n command 
 
sudo gedit /etc/apache2/apache2.conf 
 
ServerRoot "/etc/apache2"    ## <<== find this line and add the one below 
ServerName "linux32" 

There should be a blue line here

4. Checking the install works ok

Use a browser to see your web server now you will see "It Works" displayed. Use Any of the URLs below to test this out.

Code:
http://localhost 
http://127.0.0.1 
http://<your webservers host name> 

There should be a blue line here

5. Get your own content displayed.

Now to get your own pages displayed or moved into place. The guys that host my web site mythicalbeast.co.uk use the system where I see the top level directory starting my web site at /public_html so I mirror that on my test server I use locally. I want to store the pages on my nfs store accessed with /data. This means the local pages are stored in /data/www/public_html. We need to amend the Document root and the first directory option in the config file found at:

Code:
 cd /etc/apache2/sites-enabled 

and edit the config file for your default web site.

Code:
  sudo gedit 000-default 

Using my example above I edit/amend the DocumentRoot value to be /data/www/public_html. Also amend the Directory setting a few lines below to be the same. Save the edits and restart the apache server.

Code:
 sudo /etc/init.d/apache2 restart 

Now refresh the page you looked at above, It all went well your index page from DocumentRoot is now displayed. Mine is so I'm done reading the docs. If yours is not you still have some checking and reading to do.

There should be a blue line here

6. Links that were useful to me.

Apache HTTP Server Version 2.2 Documentation