News from ContractorUK

This webpage uses Javascript to display some content.

Please enable Javascript in your browser and reload this page.

The Apache 2 Web-Server

These notes show how to install Apache 2 and then how to configure it to enable users to have their own web sites, with http://yourdoman/~user as the url. We will look at the situations in both unix (Ubuntu) and cygwin.

The procedures detailed on this page work for me. However, depending on your syatem configuration, they may not work for you without modification.

Apache remains a key component in the vast majority of networks on the Web, currently running more than half of the world's sites. The latest version, Apache 2.2, is a major enhancement over the earlier versions of 2.0 and 2.1. In particular, the default configuration layout has been simplified and modularised.

Table of Contents

  • Get and Install Apache 2
  • Local-User Web Site
  • Local-User cgi-bin Directory
  • Cygwin Server
  • Get and Install Apache 2

    Ubuntu and other Unix Flavors (gzipped tarball)

    I recommend downloading the gzipped tarball and complining from source. Do not forget to read all the INSTALL and README files. Compiling from source gets over the major problem with Ubuntu (and other unix flavors) in that its package manager (“synaptic”) never seems to have the latest versions of software. I had no problems installing Apache 2.2.15 on Ubuntu 7.04 using:
      ./configure --prefix=/usr/local/apache2
      make
      sudo make install
    The sudo command is necessary since you need administrator rights. Notice, Apache2 has been installed in the “--prefix” or root directory of /usr/local/apache2. This is Apache's suggested location. Of course, should you wish, you can choose a different location. And using a download manager like “synaptic” will probably put the installation in /usr/share/apache2.

    Ubuntu (download manager)

    Getting Apache2 is straightforward using the download manager (“Synaptic”). It is the only option if you are unhappy about installing from the source code, but you will probably only get the older Apache 2.1. Synaptic usually installs Apache 2 into the root /usr/share/apache2.

    Cygwin

    Fortunately, the cygwin package manager has Apache 2.2 available so it is therefore easiest to use this route rather than download the source code. However, for Apache2 to work in cygwin, the cygwin server (see below) must also be installed and running. The cygwin package manager installs Apache 2.2 into the root /usr/share/apache2.

    Installation Directories for Two Root Locations

    1. ROOT   /usr/local/apache2
      • binaries   /usr/local/apache2/bin
      • www   /usr/local/apache2/htdocs
      • cgi-bin   /usr/local/apache2/cgi-bin
      • configs   /usr/local/apache2/conf
    2. ROOT   /usr/share/apache2
      • binaries   /usr/sbin/usr/bin
      • www   /usr/share/apache2/htdocs
      • cgi-bin   /usr/share/apache2/cgi-bin
      • configs   /etc/apache2

    Starting Apache2

    Depending on the root location, you start Apache2 by entering either the command /usr/local/apache2/bin/apachectl2 start or the command /usr/sbin/apachectl2 start. In ubuntu, you will probably also have to use sudo. Confirm all is working normally by pointing a browser to http://localhost or to http://127.0.0.1. You will then see the message It Works! The URL http://your_host may also work if the name of your host is in the host file.

    In cygwin, you might get a Windows Security Alert when you attempt to start Apache2. The Alert comes from your Firewall, with the message:

      Do you want to keep blocking this program?
      Name of program: httpd2
    Click Unblock to continue.

    Local-User Web Site

    First, we construct the directory for the html pages. We will do the same for a Local-User cgi-bin Directory below.

    We keep the default setting whereby the local-user web files are in the /home/user/public_html directory.

    Unix (Ubuntu)

    (1) The user -i.e. you! - does:-

    (2) The administrator - i.e. you! - does:-

    The soft links made by the command ln -s have the effects of activating the userdir module. Look at the Apache2 documentation if you'd like to know more about modules and directives.

    (3) Open the file user.conf with a text editor. You will find it in

      /etc/apache2/mods-enabled
    Now enter the following lines:

    The file user.conf should look something like this:

    <IfModule mod_user.c>
    UserDir public_html
    UserDir disabled root

    <Directory /home/*/public_html>
    AllowOverride FileInfo AuthConfig Limit
    Options Multiviews Indexes SymLinksIfOwnerMatch IncludesNoExec
    </Directory>

    <Directory /home/*/public_html/cgi-bin/>
    Option ExecCGI
    SetHandler cgi-script
    </Directory>

    </IfModule>

    (4) Restart the apache2 server. The simplest way is to enter

      sudo /etc/init.d/apache2 restart

    When you start apache2, you may receive a Windows Security Alert from your Firewall asking if you want to keep blocking the program httpd2. (See above.) Click to unblock.

    Cygwin

    Unfortunately, the apache2 server on cygwin has its files arranged differently from the unix case.

    (A) First, do the same as (1) above in order make the public_html and cgi-bin directories.

    (B) You now edit the file httpd.conf. This file is found in the directory /etc/apache2. It would be wise to make a copy of httpd.conf before editing. Now insert the following:

    Click here for my complete http.conf file to see where I inserted the lines. Look about 2/3 of the way down for the line # Begin added by C Baxter.

    (C) Now restart the apache2 server. Remember that the cygwin server (see below) must also be running for apache2 to function.

    Local-User cgi-bin Directory

    The procedure is the same for unix (Ubuntu) and cygwin.

    Go into /home/user/public_html and do mkdir cgi-bin. This makes the cgi-bin directory as a sub-directory of public_html. We now have to set the permissions of the cgi-bin directory. While still in /home/user/public_html do chmod a+xr cgi-bin or chmod 755 cgi-bin. Remember to set all the perl scripts in the cgi-bin directory to the same permissions. That's it!

    Cygwin Server

    To ensure you have a cygwin server installed, enter cygwin-config in the cygwin bash shell. You will be asked:
      Do you want to install cygserver as service?
      (Say "no" if it's already installed as service) (yes/no)
    Enter yes. I have never found it necessary to change the cygserver configuration options from their default settings.

    In the past, you had to set the system environment CYGWIN to server. This is no longer necessary with Cygwin 1.7.

    To start the cygwin server enter net start cygserver. This is a C:\WINDOWS\system32 program so that directory has to be in the path if you enter net start in a bash shell. Alternatively, you can start the cygwin server with the /bin program cygrunsrv -S cygserver.

    To stop the cygwin server, use either net stop cygserver or cygrunsrv -E cygserver.