6th CEENet Network Technology Workshop; Budapest, Hungary, August, 2000
Exercise with the Apache v.1.3 WWW Server on the Linux
1. Start Linux OS on Your computer.
- restart computer. On LILO prompt first press <TAB> and then write linux
- login as user root password buda2000. Be careful Linux is case sensitive!
2. Preparations for Apache installation.
- start Terminal application by clicking on the appropriate icon on the desktop.
- go to your working directory by typing in the following command:
cd /home/is_serv1
- examine the content of your working directory by typing in the following commands (normally you would create working directories):
pwd
ls -l
3. Find the Apache archive, download it and unpack.
- in the real situation you will have to find a software on the net (http://www.apache.org). Here, it is available at
http://www.ceenet.ceu.hu/T2/index_lab.html
- start Netscape browser by clicking on the appropriate icon on the desktop.
http://www.ceenet.ceu.hu/T2/index_lab.html find the Apache distribution file and download it to the /home/is_serv1/source directory.
- go to your terminal window. Go to the
source directory by typing cd /home/is_serv1/source
- unpack the archive by typing:
gunzip apache_1.3.12.tar.gz
tar –xvf apache_1.3.12.tar
apache_1.3.12 directory by typing cd apache_1.3.12
- install Apache server by typing:
./configure --prefix=/home/is_serv1/serv --with-port=80
make
make install
go to the server's home directory by typing cd /home/is_serv1/serv
check the result with the ls –al. Examine the directories and files that have just been created. It should look like:
[is_serv1@test1 serv]$ ls -al
total 48
drwxr-xr-x 12 is_serv1 is_serv1 4096 Aug 21 02:39 .
drwxrwxr-x 7 is_serv1 is_serv1 4096 Aug 18 20:48 ..
drwxr-xr-x 2 is_serv1 is_serv1 4096 Aug 21 02:39 bin
drwxr-xr-x 2 is_serv1 is_serv1 4096 Aug 21 02:39 cgi-bin
drwxr-xr-x 2 is_serv1 is_serv1 4096 Aug 21 02:39 conf
drwxr-xr-x 3 is_serv1 is_serv1 4096 Aug 21 02:39 htdocs
drwxr-xr-x 3 is_serv1 is_serv1 4096 Aug 21 02:39 icons
drwxr-xr-x 3 is_serv1 is_serv1 4096 Aug 21 02:39 include
drwxr-xr-x 2 is_serv1 is_serv1 4096 Aug 21 02:39 libexec
drwxr-xr-x 2 is_serv1 is_serv1 4096 Aug 21 02:39 logs
drwxr-xr-x 4 is_serv1 is_serv1 4096 Aug 21 02:39 man
drwxr-xr-x 2 is_serv1 is_serv1 4096 Aug 21 02:39 proxy
4. Configure the server (necessary directives)
- There is a nice on-line documentation about Apache configuration. Use your Netscape browser and go to the URL:
http://www.apache.org/docs/mod/directives.html (whole documentation is available at http://www.apache.org/docs/.
- change the directory to your server configuration directory (/home/is_serv1/serv/conf) by typing:
cd conf
- check (using more command or joe editor) the available configuration files.
httpd.conf by typing joe httpd.conf
change the line:
ServerAdmin you@your.address
to (use your e-mail address at bush.ceenet.ceu.hu):
ServerAdmin your_user_name@bush.ceenet.ceu.hu
observe that other important parameters have been already set correctly:
ServerType standalone
Port 80
ServerRoot /home/is_serv1/serv
observe values of ErrorLog, CustomLog and PidFile
change the lines:
#ServerName pcxx
#AddType text/html .shtml
#AddHandler server-parsed .shtml
accordingly to lines (instead of pcxx real hostname will be used):
ServerName pcxx.ceenet.ceu.hu
AddType text/html .shtml
AddHandler server-parsed .shtml
observe that other important parameters have been already set correctly:
DocumentRoot /home/is_serv1/serv/htdocs
UserDir public_html
DirectoryIndex index.html
ScriptAlias /cgi-bin/ /home/is_serv1/serv/cgi-bin/
Alias /icons/ /home/is_serv1/serv/icons/
be sure that Root Directory has the setting that looks like (you should add Includes option, and change AllowOverride None to AllowOverride All):
<Directory /home/is_serv1/serv/htdocs>
Options Indexes Includes FollowSymLinks
AllowOverride All
</Directory>
5. Start, stop and restart the server.
- check configuration by typing
: /home/is_serv1/serv/bin/apachectl configtest
- start the server by typing:
/home/is_serv1/serv/bin/apachectl start
- see if it is running by typing
ps -ef | grep httpd. You should get something like this:
[root@test1 serv]# ps -ef | grep httpd
root 9740 1 0 03:46 ? 00:00:00 /home/is_serv1/serv/bin/httpd
nobody 9741 9740 0 03:46 ? 00:00:00 /home/is_serv1/serv/bin/httpd
nobody 9742 9740 0 03:46 ? 00:00:00 /home/is_serv1/serv/bin/httpd
nobody 9743 9740 0 03:46 ? 00:00:00 /home/is_serv1/serv/bin/httpd
nobody 9744 9740 0 03:46 ? 00:00:00 /home/is_serv1/serv/bin/httpd
nobody 9745 9740 0 03:46 ? 00:00:00 /home/is_serv1/serv/bin/httpd
nobody 9746 9740 0 03:46 ? 00:00:00 /home/is_serv1/serv/bin/httpd
nobody 9747 9740 0 03:46 ? 00:00:00 /home/is_serv1/serv/bin/httpd
nobody 9748 9740 0 03:46 ? 00:00:00 /home/is_serv1/serv/bin/httpd
- use the Netscape browser and go to the first page of your server. URL is:
http://pcxx.ceenet.ceu.hu/
- look for the httpd.pid file (
more /home/is_serv1/serv/logs/httpd.pid). Use the stored number (pid) to stop the sever by typing: kill –TERM pid
(you can also stop the server by the following command: /home/is_serv1/serv/bin/apachectl stop)
- observe that all httpd processes have gone (use ps command as instructed before). Start httpd again (as instructed before).
6. Modify the home (welcome) page of your server.
- use
cd command to go to the /home/is_serv1/serv/htdocs directory and prepare simple index.html file.
- In the real life you should now give the Read/Write permission to the user or a group that will author the files. This should be done ONLY for
htdocs directory!
7. Add server side include.
- use
joe editor to create first.shtml file (it should be in htdocs directory ) that looks like this:
<HTML>
<HEAD>
<TITLE>Welcome</TITLE>
</HEAD>
<BODY>
<H2>Welcome to the
<!--#echo var="SERVER_NAME" -->
</H2>
<HR>
This server is running just for learning purposes.
<BR>
Today is: <!--#exec cmd="/bin/date" --> or <!--#echo var="DATE_LOCAL" --><BR>
Have a nice day !
<BR>
<HR>
<I>
Last time changed on: <!--#echo var="LAST_MODIFIED" -->
</I>
</BODY>
</HTML>
http://pcxx.ceenet.ceu.hu/first.shtml in your Netscape browser and examine the result.
8. Try to work with the authentication.
- try to disable viewing the files in your DocumentRoot directory (
/home/is_serv1/serv/htdocs) for the clients on the ceenet.ceu.hu domain. Place the appropriate directives (see the lectures slides!) in the .htaccess file in the /home/is_serv1/serv/htdocs/. You can also make these changes using httpd.conf file (in that case you will have to restart the server).
- ask others in lab to try to browse pages from your server. Observe results. Stop your server and look into the access and error file in the
/home/is_serv1/serv/logs directory. Restart your server.
- For the exeperienced students
: using the lecture slides try to work with the user/password authetication. Generate a user and allow (only) him to browse your files. Try to combine both methods (by host/domain and by password).
9. CGI scripts.
- go to your servers CGI script directory by typing
cd /home/is_serv1/serv/cgi-bin
- you have two scripts there:
printenv and test-cgi. Have a look at the scripts (examine actual code). To give the server posibility to execute them you have to change the privileges to 755 (chmod 755 *).
- try to execute both programs (
printenv and test-cgi) by opening in your Netscape browser URL:
http://pcxx.ceenet.ceu.hu/cgi-bin/printenv
http://pcxx.ceenet.ceu.hu/cgi-bin/test-cgi
create the finger script using the following code (start editor with command joe finger and type in the following commands):
#!/bin/sh
echo Content-type: text/html
echo
cat << EOM
<HTML>
<HEAD>
<TITLE>Finger Gateway</TITLE>
</HEAD>
<BODY>
EOM
if [ x = x$QUERY_STRING ]; then
cat << EOM
<H1>Finger Gateway</H1>
This is a gateway to "finger". Type a user@host
combination in your browser's search dialog.<P>
<ISINDEX>
EOM
else
echo \<PRE\>
z=`echo $QUERY_STRING | sed 's/%40/@/'`
/usr/bin/finger -l "$z"
echo \</PRE\>
fi
cat << EOM
</BODY>
</HTML>
EOM
- set execute permission for finger script by typing
chmod 755 finger
with your Netscape browser open the URL http://pcxx.ceenet.ceu.hu/cgi-bin/finger
try to finger „miro@bush.ceenet.ceu.hu”.
10. Virtual servers.
- your PC is registered in DNS with alias hostname
wwwxx.ceenet.ceu.hu! Try to access your web server using the alias hostname.
- create another document directory
httpd2 by typing the following commands:
cd /home/is_serv1/serv
mkdir htdocs2
- using the lecture slides on virtual servers try to setup two web servers
wwwxx.ceenet.ceu.hu and pcxx.ceenet.ceu.hu!. One with the starting page (DocumentRoot) in directory httpd and other with the starting page (DocumentRoot) in directory httpd2. IP address of your PC is written on the terminal.
Thank you, Miroslav Milinovic and Dubravko Penezic