Apache

Preparation
- Perform this stage using your functioning PC.
- Download the Apache source code from httpd.apache.org.
- Visit httpd.apache.org and click on the "Download: from a mirror" link.
- You will be asked to choose a mirror site to use. Choose one closest to you.
- This example uses an HTTP mirror, rather than an FTP mirror.
- Click on the link for the source code of the latest version of Apache. You will need the source code in
.tar.gzformat.- At the time of writing the latest version of Apache was version 2.0.40, so the file downloaded was
httpd-2.0.40.tar.gz.
- At the time of writing the latest version of Apache was version 2.0.40, so the file downloaded was
- You will be asked to where you wish to save the file. Chose a safe place and make a note of it.
- The download is about 4.5Mb and will take at least half an hour over a modem, but a lot less over a broadband connection.
- If you are using a download accelerator program, it will save the file to your default download directory.
- Burn the file
httpd-2.0.40.tar.gzand your webpages to a CD. This page assumes that the subdirectory/appsis used for the.tar.gzfile and that the subdirectory/htmlis used for the webpages. The CD-ROM can be a multi-session disk.- Use your CD burning software to create an ISO9660 disc image with the file
httpd-2.0.40.tar.gzin the/appsdirectory. - Put your webpages in a directory called
/htmlon the CD. - Burn the CD and verify the data stored on it.
- Use your CD burning software to create an ISO9660 disc image with the file
Booting
- Perform this stage and subsequent stages, unless otherwise stated, using your Core Linux PC.
- Boot your Core Linux PC.
- Login as
root. You will need to enter the password at the prompt.- Wait for the following text to appear:
localhost login: - Type
rootand press Enter. - The screen will display this message:
Password: - Enter the password for
rootthat you set earlier. - You will be shown a prompt that looks like this:
[~]#
- Wait for the following text to appear:
Extract the source
- Place the CD-R in the CD-ROM drive. Mount the CD-ROM drive under
/mnt/cdrom.- At the prompt enter:
mount /dev/hdb /mnt/cdrom - You will see the following line appear:
mount: block device /dev/hdb is write-protected, mounting read-only
- At the prompt enter:
- Change to the
/appsdirectory on the CD-R.- At the prompt enter:
cd /mnt/cdrom/apps - The prompt will change to:
[/mnt/cdrom/apps]#
- At the prompt enter:
- Copy the
httpd-2.0.40.tar.gzfile to the directory/usr/src.- At the prompt enter:
cp httpd-2.0.40.tar.gz /usr/src - The system will not display a message if everything is OK.
- At the prompt enter:
- Change to the
/usr/srcdirectory and extract the source from the.tar.gzfile.- At the prompt enter:
cd /usr/src - The prompt will change to:
[/usr/src]# - At the prompt enter:
tar -zxvf httpd-2.0.40.tar.gz - A long stream of unzipping files and directories should scroll up the screen for a few seconds.
- At the prompt enter:
Configure and compile
- Change to the
/usr/src/httpd-2.0.40directory.- At the prompt enter:
cd httpd-2.0.40 - The prompt will change to:
[/usr/src/httpd-2.0.40]#
- At the prompt enter:
- Run the
./configurescript.- At the prompt enter:
./configure - N.B. If you wish the software to be installed in a directory other than the default directory of
/usr/local/apache2then use the alternative command:where the word./configure --prefix=PREFIXPREFIXis replaced by your alternative directory path. - A long stream of processes should scroll up the screen for about two mintues.
- The script finishes with the line:
config.status: executing default commands
- At the prompt enter:
- Run the
makeprogram.- At the prompt enter:
make - A long stream of processes should scroll up the screen for about two mintues.
- The program finishes with the line:
make[1]: Leaving directory '/usr/src/httpd-2.0.40'
- At the prompt enter:
- Run the
makeprogram with the argumentinstall.- At the prompt enter:
make install - A long stream of processes should scroll up the screen for about a minute.
- The program finishes with the line:
make[1]: Leaving directory '/usr/src/httpd-2.0.40'
- At the prompt enter:
Initial Testing
- If you are certain that the networking elements of your Core Linux PC are set up correctly, and that the Apache software was correctly compiled and installed then you may want to skip this section.
- Add the user
nobody.- At the prompt enter:
useradd nobody - The system will not display a message if everything is OK.
- At the prompt enter:
- Start the Apache webserver using
/usr/local/apache2/bin/apachectl start.- At the prompt enter:
/usr/local/apache2/bin/apachectl start - The following message will appear on the screen:
httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
- At the prompt enter:
- Using your other computer, see if you can access the web server.
- Launch your web browser.
- In the address bar type the IP address of your Core Linux PC. In the installation guide the Core Linux PC was set up with the IP address 192.168.0.10. The line entered should read:
http://192.168.0.10 - Press Enter.
- Your web browser should load a page with the title "Test Page for Apache Installation":

- If the test page loaded successfully then you have correctly compiled and installed the Apache webserver. You may want to spend some time browsing the site to learn about more advanced configuration of the Apache webserver.
Setting up Apache
- These stages are discretionary, but demonstrate a typical Apache configuration.
- Change to the
/usr/local/apache2/confdirectory.- At the prompt enter:
cd /usr/local/apache2/conf - The prompt will change to:
[/usr/local/apache2/conf]#
- At the prompt enter:
- Backup
httpd.conftohttpd.conf.bak- At the system prompt enter:
cp httpd.conf httpd.conf.bak - The system will not display a message if everything is OK.
- At the system prompt enter:
- Edit the
httpd.conffile.- At the prompt enter:
nano httpd.conf - The screen will show the contents of
httpd.confwith information about the file at the top and bottom of the screen. The file is 1036 lines long. - Navigate the file using the arrow keys.
- At the prompt enter:
- Configure the Server Name. If you are planning to access your webserver using only its IP address then you do not need to complete this stage. Also, you will not be able to access your webserver using the specified address just be including in the configuration file. As there will be no DNS servers referencing it, no potential clients will be able to convert find the IP address for your machine from the given Server Name.
- Press Ctrl+w on the keyboard.
- The white text bar at the bottom of the screen will change to read:
Search: - Enter the search string:
ServerName - Press Enter.
- The screen will change to show the first occurance of the search string in the file.
- Scroll down 11 lines using the down arrow to find the following line:
#ServerName new.host.name:80 - Remove the
#symbol from the beginning of the line. - Change the text to reflect the FQDN of your webserver.
- Configure the Server Admin e-mail address.
- Press and hold PageUp until you return to the top of the document.
- Press Ctrl+w on the keyboard.
- The white text bar at the bottom of the screen will change to read:
Search: - Enter the search string:
ServerAdmin - Press Enter.
- The screen will change to show the first occurance of the search string in the file.
- Scroll down 4 lines using the down arrow to find the following line:
ServerAdmin you@your.address - Change the dummy e-mail address
you@your.addressto your e-mail address. - Press Ctrl+w on the keyboard.
- The white text bar at the bottom of the screen will change to read:
Search: - Enter the search string:
ServerSignature - Press Enter.
- The screen will change to show the following line:
ServerSignature On - Change the line to read:
ServerSignature Email
- Configure the user and group as which Apache will run.
- Press and hold PageUp until you return to the top of the document.
- Press Ctrl+w on the keyboard.
- The white text bar at the bottom of the screen will change to read:
Search: - Enter the search string:
User - Press Enter.
- The screen will change to show the first occurance of the search string in the file.
- Scroll down 11 lines using the down arrow to find the following line:
User nobody - Change the line to:
User httpd - Scroll down 1 line using the down arrow to find the following line:
Group #-1 - Change the line to:
Group httpd
- Configure the Document Root. This is the directory from which your webpages will be served. The default location is the location of the "Test Page for Apache Installation" files.
- Press and hold PageUp until you return to the top of the document.
- Press Ctrl+w on the keyboard.
- The white text bar at the bottom of the screen will change to read:
Search: - Enter the search string:
DocumentRoot - Press Enter.
- The screen will change to show the first occurance of the search string in the file.
- Scroll down 4 lines using the down arrow to find the following line:
DocumentRoot "/usr/local/apache2/htdocs" - Change the line to reflect the directory from which you wish your website to be served. This example uses the following directory:
/home/httpd/html
- Save the file and exit the text editor.
- Press Ctrl+x on the keyboard.
- The contents of the white line at the bottom of the screen will change to read:
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ? - Type
y. - The contents of the white line at the bottom of the screen will change to read:
File Name to write: httpd.conf - Press Enter.
- You will be returned to the system prompt.
Creating the Document Root
- Change to the
/homedirectory.- At the prompt enter:
cd /home - The prompt will change to:
[/home]#
- At the prompt enter:
- Create the directory
httpd/html.- At the prompt enter:
mkdir -p httpd/html - The system will not display a message if everything is OK.
- At the prompt enter:
- Add the user and group
httpd.- At the prompt enter:
groupadd httpd - The system will not display a message if everything is OK.
- At the prompt enter:
useradd -M -g httpd httpd - The system will not display a message if everything is OK.
- At the prompt enter:
- Change the ownership of the
/home/httpddirectory to the userhttpdand the grouphttpd.- At the prompt enter:
chown -R httpd:httpd /home/httpd - The system will not display a message if everything is OK.
- At the prompt enter:
- Change the access permissions of the
/home/httpddirectory to 0755.- At the prompt enter:
chmod 0755 /home/httpd /home/httpd/html - The system will not display a message if everything is OK.
- At the prompt enter:
Copying the webpages
- Copy the webpages from the CD-R to the Document Root directory.
- At the prompt enter:
cd /mnt/cdrom - The prompt will change to:
[/mnt/cdrom]# - At the prompt enter:
cp -rf html /home/httpd - The system will not display a message if everything is OK.
- At the prompt enter:
- Change to the
/home/httpd/htmldirectory.- At the prompt enter:
cd /home/httpd/html - The prompt will change to:
[/home/httpd/html]#
- At the prompt enter:
- Change the ownership of the files in the
/home/httpd/htmldirectory to the userhttpdand the grouphttpd.- At the prompt enter:
chown -R httpd:httpd * - The system will not display a message if everything is OK.
- At the prompt enter:
- Change the access permissions of the files in the
/home/httpd/htmldirectory to 0755.- At the prompt enter:
chmod -R 0755 * - The system will not display a message if everything is OK.
- At the prompt enter:
Checking and restarting Apache
- Check the syntax of your edited
httpd.conffile using/usr/local/apache2/bin/apachectl configtest.- At the prompt enter:
/usr/local/apache2/bin/apachectl configtest - The following message will appear on the screen:
Syntax OK
- At the prompt enter:
- Restart Apache using the command
/usr/local/apache2/bin/apachectl restart.- At the prompt enter:
/usr/local/apache2/bin/apachectl restart - The system will not display a message if everything is OK.
- If you skipped the section on initial testing, then you will not have started server yet, and the screen will display will show the following:
httpd not running, trying to start
- At the prompt enter:
Stopping Apache
- Stop the Apache webserver using
/usr/local/apache2/bin/apachectl stop.- At the prompt enter:
/usr/local/apache2/bin/apachectl stop - The system will not display a message if everything is OK.
- At the prompt enter:
Automating Apache
- This section details how to have your Apache server start automatically when the computer boots. The advantage of this method is that you do not have to log in to start Apache. If you wish to start Apache manually after each reboot then skip this section.
- Append the following line to the
/etc/rc.d/rc.muscript:You can also add comments and echoes for your own information./usr/local/apache2/bin/apachectl start- At the prompt enter:
nano /etc/rc.d/rc.mu - The screen will show the contents of
/etc/rc.d/rc.muwith information about the file at the top and bottom of the screen. - Add the following text to the end of the file:
# Start Apache
/usr/local/apache2/bin/apachectl start
echo Apache Started - Save the file and exit the text editor.
- Press Ctrl+x on the keyboard.
- The contents of the white line at the bottom of the screen will change to read:
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ? - Type
y. - The contents of the white line at the bottom of the screen will change to read:
File Name to write: /etc/rc.d/rc.mu - Press Enter.
- You will be returned to the system prompt.
- At the prompt enter:
- Insert the following line at the second line of the
/etc/rc.d/rc.rbscript:You can also add comments and echoes for your own information./usr/local/apache2/bin/apachectl stop- At the prompt enter:
nano /etc/rc.d/rc.rb - The screen will show the contents of
/etc/rc.d/rc.rbwith information about the file at the top and bottom of the screen. - Insert the following text at the second line of the file:
# Stop Apache
/usr/local/apache2/bin/apachectl stop
echo Apache Stopped - Save the file and exit the text editor.
- Press Ctrl+x on the keyboard.
- The contents of the white line at the bottom of the screen will change to read:
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ? - Type
y. - The contents of the white line at the bottom of the screen will change to read:
File Name to write: /etc/rc.d/rc.rb - Press Enter.
- You will be returned to the system prompt.
- At the prompt enter:
- Insert the following line at the second line of the
/etc/rc.d/rc.hascript:You can also add comments and echoes for your own information./usr/local/apache2/bin/apachectl stop- At the prompt enter:
nano /etc/rc.d/rc.ha - The screen will show the contents of
/etc/rc.d/rc.hawith information about the file at the top and bottom of the screen. - Insert the following text at the second line of the file:
# Stop Apache
/usr/local/apache2/bin/apachectl stop
echo Apache Stopped - Save the file and exit the text editor.
- Press Ctrl+x on the keyboard.
- The contents of the white line at the bottom of the screen will change to read:
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ? - Type
y. - The contents of the white line at the bottom of the screen will change to read:
File Name to write: /etc/rc.d/rc.ha - Press Enter.
- You will be returned to the system prompt.
- At the prompt enter:
- Reboot the system and check that Apache is running.
- At the system prompt enter:
shutdown -r now - Wait for the system to reboot.
- As the system reboots, watch for any error messages.
- Once the system has rebooted, try to access the webserver using the web browser on your other PC.
- At the system prompt enter:

The text of this page is licensed under a Creative Commons License.
