The Apache web server – Part 2


At first we create a site with a PHP script to test the functionality. On the main site we create a link to this PHP site. So we create a file called ‘phpTest.php’ in the ‘/var/www’ directory with the following contents:

Now the server can not interpret this code and may only returns this text. So to execute PHP script we have to install the following packages:


After a restart of the Apache web server, the PHP script is executed and the browser displays the following:

erstes PHP Skript


We now create a second script file to test the Perl functionality. But first we need to create a directory for both Perl and Python scripts. This directory is called ‘cgi-bin’ and is also located in the ‘/var/www’ directory. Now its time to create a file called ‘’ (pl is the normally used for Perl scripts)  and copy this contents into the file:

This file and the newly created directory need execute rights. You have to change this.

The last thing here is to install the Perl module for the web server:


Now Perl is installed an activated. But we need to configure our virtual host. You can find this host in ‘sites-avaliable’. The default virtual host already has a configuration for the ‘cgi-bin’ directory. This configuration needs to be replaced with this:

The first line defines an alias to the directory of our scripts. The line AddHandler defines all file endings that should be treated as script files. For our example this are *.cgi and *.pl files.

After a restart of the server, the browser display the Perl script output:

erstes Perl Skript


Again we create a new file inside the ‘cgi-bin’ directory and call it ‘’.

Here we also need to set executable rights for the file.

Now we install the Python module:

And the last thing is also a change on the configuration of the virtual host. We add the following:

erstes Python Skript

Possible Errors

If you follow the instructions it can happen, that there may be some errors. The main source of problems are script languages, because the configuration is not that easy. First you should check if all needed modules are correctly installed. A restart of your server can also be helpful. If you want to test scripts, you can do this also on the command line (for example type ‘./’ and watch the output). With this you can easily check if the file has executable rights. If the scripts still does not work when they are started with the browser, you may check the Apache log. You can find all log files in ‘/var/log/apache2’.

The third Part is about the Tomcat web server and how to run Java Programs.

Part 1 I Part 3

(Visited 195 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *