Setting up your local web development environment – Apache

Setting up your local web development environment – Apache

This is the first on in the series of tutorials on how to set up your local web development environment on linux (I’m using Ubuntu). It is targeting those people, who don’t know their way around linux, but don’t want to use generic packages. It’s more fun. 🙂

Download and prepare

First, you go to the apache homepage. You download apache, check sha1, because it can get corrupted!

$ sha1sum httpd-2.2.22.tar.gz | grep 'bf3bbfda967ac900348e697f26fe86b25695efe9'

If a line is returned, the file is OK, we can proceed, else, return to step 1.

Extract the archive.

$ tar xzf httpd-2.2.22.tar.gz

Move into the directory of the extracted archive.

$ cd httpd-2.2.22

Configure for compiling

Next, we have to configure apache, before we compile it.

$ ./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=all --enable-mod-rewrite

  • –prefix=/usr/local/apache2 tells apache where to install all the files needed. In this case we are installing apache to /usr/local/apache2 directory.
  • –enable-mods-shared=all tells apache to compile all modules as dynamic shared modules. We can then enable these modules in httpd.conf file, via the LoadModule directive.
  • –enable-mod-rewrite tells apache to enable mod rewrite.

Troubleshoot

If you get this error during the configuration:

mod_deflate has been requested but can not be built due to prerequisite failures

This happened because we enabled all mods by default, one of which is the mod_deflate that uses the zlib library. You can simply install its headers on ubuntu.

# apt-get install zlib1g-dev

The dependencies should pass.

Compile

$ make

Next one must be executed as super user.

# make install

Test it

Now, apache should be working. Let’s test it.

# /usr/local/apache2/bin/apachectl -k start

Go to: http://localhost

You should see a “It works!” on your screen.

But when we started apache, it threw out an error:

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

Configure it

It’s time to configure it, so it won’t throw errors at us. You can use different text editor than gedit (vi, nano, mcedit … )

# gedit /usr/local/apache2/conf/httpd.conf

ServerAdmin → change it to your email, just for a clean configuration file.

Uncomment ServerName directive (remove # in front of it) and change www.example.com to localhost. With this, we got rid of that error from before.

DocumentRoot → change to directory in which you want to have your html, php etc. files.

<Directory “/usr/local/apache2/htdocs”> → change if you changed the DocumentRoot in the previous step.

Here we must change the line AllowOverride None to AlloweOverride All if we want mod_rewrite to function properly.

Check if the syntax of the configuration file is OK.

$ /usr/local/apache2/bin/apachectl -t

If everything is OK, restart apache.

# /usr/local/apache2/bin/apachectl -k restart

You’re good to go!

Post updated on February 1st, 2012 to reflect latest apache version.

2 Responses so far.

  1. Abhilash says:

    Hi,

    thank you for the information, i am able to run html file but i am not able to run perl script…please provide the details