7th CEENet Network Technology Workshop; Budapest, Hungary, August, 2001
Exercise with the Apache v.1.3 WWW Server on the Linux
1. Start Linux OS on Your computer.
- restart computer
- select LINUX on the start-up screen
- login as user
root password ceenet (be careful Linux is case sensitive)
- start Terminal application by clicking on the appropriate icon on the desktop
- start Netscape browser by clicking on the appropriate icon on the desktop
2. Find, copy and unpack the Apache archive. Compile the server.
- in the real situation you will have to find a software on the net (http://httpd.apache.org/). Here, it is available on your computer in the directory
/server/archive
- go to your terminal window
- copy the Apache source archive by typing
cp /server/archive/apache_1.3.20.tar.gz /server/source/.
- go to the working directory by typing
cd /server/source
- unpack the archive by typing:
- gunzip apache_1.3.20.tar.gz
- tar –xvf apache_1.3.20.tar
- go to the
apache_1.3.20 directory by typing cd apache_1.3.20
- install Apache server by typing:
- ./configure --prefix=/server/httpd
- make
- make install
- go to the server's home directory by typing
cd /server/httpd
- check the result with the
ls –al. Examine the directories and files that have just been created. It should look like:
[root@pc01 httpd]# ls -al
total 48
drwxr-xr-x 12 root root 4096 Aug 21 11:36 .
drwxrwxr-x 6 root root 4096 Aug 21 11:36 ..
drwxr-xr-x 2 root root 4096 Aug 21 11:36 bin
drwxr-xr-x 2 root root 4096 Aug 21 11:36 cgi-bin
drwxr-xr-x 2 root root 4096 Aug 21 11:36 conf
drwxr-xr-x 3 root root 4096 Aug 21 11:36 htdocs
drwxr-xr-x 3 root root 4096 Aug 21 11:36 icons
drwxr-xr-x 3 root root 4096 Aug 21 11:36 include
drwxr-xr-x 2 root root 4096 Aug 21 11:36 libexec
drwxr-xr-x 2 root root 4096 Aug 21 11:37 logs
drwxr-xr-x 4 root root 4096 Aug 21 11:36 man
drwxr-xr-x 2 nobody nobody 4096 Aug 21 11:36 proxy
3. Configure the server (necessary directives)
- There is a nice on-line documentation about Apache. Use your Netscape browser and go to the URL:
http://httpd.apache.org/docs/mod/directives.html (whole documentation is available at http://httpd.apache.org/docs/).
- change the directory to your server configuration directory (
/server/httpd/conf) by typing: cd conf
- check (using more command or joe editor) the available configuration files.
- edit the
httpd.conf by typing joe httpd.conf (you can use any other editor)
- change the line:
- ServerAdmin you@your.address
to (use your e-mail address at track2.ceenet.ceu.hu):
ServerAdmin your_user_name@track2.ceenet.ceu.hu
observe that other important parameters have been already set correctly:
ServerType standalone
Port 80
ServerRoot /server/httpd
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 /server/httpd/htdocs
UserDir public_html
DirectoryIndex index.html
ScriptAlias /cgi-bin/ /server/httpd/cgi-bin/
Alias /icons/ /server/httpd/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 /server/httpd/htdocs>
Options Indexes Includes FollowSymLinks
AllowOverride All
</Directory>
4. Start, stop and restart the server.
- check configuration by typing
: /server/httpd/bin/apachectl configtest
- start the server by typing:
/server/httpd/bin/apachectl start
- see if it is running by typing
ps -ef | grep httpd. You should get something like this:
[root@pc01 httpd]# ps -ef | grep httpd
root 10490 1 0 11:37 ? 00:00:00 /server/httpd/bin/httpd
nobody 10491 10490 0 11:37 ? 00:00:00 /server/httpd/bin/httpd
nobody 10492 10490 0 11:37 ? 00:00:00 /server/httpd/bin/httpd
nobody 10493 10490 0 11:37 ? 00:00:00 /server/httpd/bin/httpd
nobody 10494 10490 0 11:37 ? 00:00:00 /server/httpd/bin/httpd
nobody 10495 10490 0 11:37 ? 00:00:00 /server/httpd/bin/httpd
nobody 10496 10490 0 11:37 ? 00:00:00 /server/httpd/bin/httpd
nobody 10497 10490 0 11:37 ? 00:00:00 /server/httpd/bin/httpd
nobody 10498 10490 0 11:37 ? 00:00:00 /server/httpd/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 /server/httpd/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: /server/httpd/bin/apachectl stop)
- observe that all httpd processes have gone (use ps command as instructed before). Start httpd again (as instructed before).
5. Modify the home (welcome) page of your server.
- use
cd command to go to the /server/httpd/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!
6. Server Side Includes.
- using your Netscape browser download from
http://track2.ceenet.ceu.hu/lab3/ example file named first.shtml to /server/httpd/htdocs directory
- examine
first.shtml file using command more or an editor
- open URL:
http://pcxx.ceenet.ceu.hu/first.shtml in your Netscape browser and examine the result.
7. Authentication.
- try to disable viewing the files in your DocumentRoot directory (
/server/httpd/htdocs) for the clients on the ceenet.ceu.hu domain. Place the appropriate directives (see the lecture slides!) in the .htaccess file in the /server/httpd/htdocs/. You can also make these changes using httpd.conf file (in that case you will have to restart the server).
- try to browse pages from your server. Observe results. Stop your server and look into the access and error file in the
/server/httpd/logs directory. Restart your server.
8. CGI scripts.
- go to your servers CGI script directory by typing
cd /server/httpd/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
- using your Netscape browser download from
http://track2.ceenet.ceu.hu/lab3/ example file named finger to /server/httpd/cgi-bin directory
- examine
finger file using command more or an editor
- 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@track2.ceenet.ceu.hu”.
9. 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
htdocs2 by typing the following commands:
cd /server/httpd
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 htdocs and other with the starting page (DocumentRoot) in directory htdocs2. IP address of your PC is written on the terminal. Do not forget to restart your server!
10. Compiling Apache server with the desired modules
- your task is to compile Apache with enabled caching control (module mod_expires must be included) and php 4.0 (this is a third party module).
- to be able to compare servers check the header that is being generated by the present server.
Type in the command telnet 0 80 and after the connection has been established enter the following HTTP request manually: OPTIONS * HTTP1.1 (do not forget one blank line after that). Your session should look like:
[root@pc01 httpd]# telnet 0 80
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
OPTIONS * HTTP1.1
HTTP/1.1 200 OK
Date: Tue, 21 Aug 2001 10:02:00 GMT
Server: Apache/1.3.20 (Unix)
Content-Length: 0
Allow: GET, HEAD, OPTIONS, TRACE
Connection: close
Connection closed by foreign host.
- now stop your apache server
- first you must prepare php module. Execute following list of commands:
- cp /server/archive/php-4.0.6.tar.gz /server/source/.
- cd /server/source
- gunzip php-4.0.6.tar.gz
- tar -xvf php-4.0.6.tar
- cd php-4.0.6
- ./configure --with-ldap --prefix=/server/php
--with-config-file-path=/server/php --enable-track-vars
--with-apache=/server/source/apache_1.3.20 --with-mysql=/server/mysqld
- make
- make install
- now it is time to recompile Apache server with desired modules (mod_expires and php4). Execute following commands:
- cd /server/source/apache_1.3.20
- ./configure --prefix=/server/httpd --enable-module=expires
--activate-module=src/modules/php4/libphp4.a
- make
- make install
- finally you have to alter http.conf file. It is necessary to uncomment lines (remove #)
- AddType application/x-httpd-php .php
- AddType application/x-httpd-php-source .phps
and add directives for cache control with the desired values:
- ExpiresActive on
- ExpiresDefault "access plus 1 day"
- start the server and examine the header that is being generated by the server now.
Type in the command telnet 0 80 and after the connection has been established enter the following HTTP request manually: OPTIONS * HTTP1.1 (do not forget one blank line after that). Your session should look like:
[root@pc01 conf]# telnet 0 80
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
OPTIONS * HTTP1.1
HTTP/1.1 200 OK
Date: Tue, 21 Aug 2001 10:28:55 GMT
Server: Apache/1.3.20 (Unix) PHP/4.0.6
Cache-Control: max-age=86400
Expires: Wed, 22 Aug 2001 10:28:55 GMT
Content-Length: 0
Allow: GET, HEAD, OPTIONS, TRACE
Connection: close
Connection closed by foreign host.
- to test how the PHP works you can, using your Netscape browser, download some example files (first.php, finger.php) from
http://track2.ceenet.ceu.hu/lab3/ to /server/httpd/htdocs directory.
11. More work for the experienced 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).
Thank you, Miroslav Milinovic and Dubravko Penezic