How to Set Up Multiple Web Pages With an Apache Server
The Apache Project has produced a very popular and free Web server, featuring a full list of the features that you would expect from a world-class server package. When implemented on Ubuntu Linux, which is also free, it provides a robust Web hosting environment. Apache's default configuration supports only one website, but by configuring the server for virtual hosting, you can support multiple home pages. The Resource section contains links for help with Linux implementations other than Ubuntu.
Instructions
-
-
1
Open a terminal session and from the command prompt, update Ubuntu with the following command:
sudo apt-get update
This ensures that all of the software on your Ubuntu server is up-to-date.
-
2
Install the Apache 2 package with the following command:
sudo apt-get install apache2
This installs and starts the Apache 2 server.
-
-
3
Make a copy of the default configuration with the following command:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/yourdomain
In this command, "yourdomain" is the name of your second site, other than the default Apache 2 site.
-
4
Edit the configuration file for Apache 2 to be sure the following line is in the file:
DocumentRoot /var/www
Any text editor, such as vi, nano or gedit, will work. Save the file and exit.
-
5
Update the file you created in Step 3 as follows:
ServerAdmin youremail@localhost.com (the default is webmaster@localhost)
Servername yourdomain (the new fully qualified domain name)
ServerAlais www.yourdomain.com (the server alias)
DocumentRoot /var/www/yourdomain (where Apache looks for pages)
Errorlog /var/www/yourdomain/error.log
Customlog /var/www/yourdomain/access.log combined
Save the file and exit.
-
6
Edit the /etc/hosts file to stop your browser from searching the Web for your new domain by adding your domain name and alias to the localhost line in /etc/hosts using the following command:
127.0.0.1 localhost yourdomain www.yourdomain.com
-
7
Make a directory to hold the Web pages for your domain:
sudo mkdir /var/www/yourdomain
Later, you will save the pages for your Web site in this directory.
-
8
Enable your domain using the following command:
sudo a2ensite yourdomain
Start (or restart) Apache using the following command:
sudo /etc/init.d/apache2 start (or "restart")
The server should be ready to serve pages.
-
9
Create a Web page and save it in the directory you created in Step 7. Name it "index.html." Be sure to differentiate the new page from the default "It Works!" page that Apache supplies, so that you can be sure the new site is actually working.
-
10
Restart Apache with the following command:
sudo /etc/init.d/apache2 restart
Start a Web browser and enter "localhost" as the URL. Press "Enter." You should see the default page for Apache. Using a new tab, enter "localhost/yourdomain" as the URL and press "Enter." Your new page should display, indicating that Apache 2 is now hosting multiple Web pages.
You can repeat the procedure for as many different pages or sites as you want to host with your Apache 2 server.
-
1
References
Resources
- Photo Credit www and internet image by mbs from Fotolia.com