David Stilson


  Linux System Administration


Installing Apache

Create and configure a web server using Apache

1) Open a terminal and type the following command: sudo apt-get install apache2. You will be prompted to enter the root password.

Installing Apache using the apt-get command

2) After installation Apache will start automatically. To see if is working type in 'localhost' in a web browser. Your site should look like the following:

Testing Apache using localhost

3) During the installation process Apache is added to the 'init.d' file, and will start automatically on boot up. To prevent Apache from starting during the boot process type: sudo update-rc.d -f apache2 remove . To restore Apache's default boot settings type: sudo update-rc.d apache2 defaults.

4) To see changes to your web site you will need to restart Apache. The following commands allow you to start, restart, stop Apache.


     sudo /etc/init.d/apache2 start

     sudo /etc/init.d/apache2 stop

     sudo /etc/init.d/apache2 restart

5) By default, apache will use the '/var/www'directory to locate the startup (index.html) file. When you are creating web sites you may want to use your home directory to test your web site before it goes live.


Here is how it is done. create a directory in your home directory using the 'mkdir' command. Be certain that you are in your home page before create your directory. From the terminal use the 'cd' command to go to your home directory, and the 'pwd' command to verify that you are in the right place.

For example, if you want to create a folder named, mywebsite type: mkdir mywebsite. Use the 'ls' command to verify that the directory was created correctly. Next, create or copy the 'index.html' file, and place it into the 'mywebsite' directory.

You will now need to edit the Apache config file and have it point to the 'mywebsite' directory. The Apache config file is in the /etc directory. For this example, the config file is: '000-default' and is located in the '/etc/apache2/sites-enabled/' directory. Be aware that Apache may change the name and location of this file. Verify the name and location of the Apache config file for your system before you begin.

Open the config file using a text editor. In this examaple we used gedit from the terminal:

gedit /etc/apache2/sites-enabled/000-default

Apache config file


Change the line: DocumentRoot /var/www

to: DocumentRoot /home/user/mywebsite

Change the Directory /var/www line

to: Directory /home/user/mywebsite

Save your changes in the text editor and exit.

To make the changes effective you will need to restart Apache. When Apache is restarted it will read the changes you made to the configuration files. From the terminal type /etc/init.d/apache2 restart

.

Type localhost in a browser and verify that your web site is now pointed to your home directory. Next, make changes to your web pages and create a site that eats bandwidth!