Ever since finding I could put stuff,
any stuff, on the Internet, simply by putting it in a certain directory in my university file space and tweaking some permissions, I've been interested in playing with web things (more detail is on my
website). More recently I found I needed a local testing server as uploading stuff only to find it didn't work got very tedious. As a windows user I grabbed
XAMPP, which is great - you get a nice installer and a small GUI that turns it on and off, but you do get introduced to having to edit config files manually (I used
notepad2 for this).
Eventually I found I needed to repeat this in
Ubuntu which, for those who don't know, is a distribution of
Linux (you really should give it a go!). However for Linux I found a plethora of guides on how to get apache up and running, but they only answered some of my questions, so I'm having a go partly so I can remember what I found works!
To install you'll want to grab the following packages from the repo manager (Synaptic in Ubuntu):
- apache2
- This is the main package for the webserver, and the only essential one, dependencies should be taken care of automatically
- php5
- PHP enable your server to dynamically change the pages that it serves (At the time of writing PHP5 is the most current, but PHP6 is due out soon)
- mysql
- MySQL is a database query language and this package enable you to host databases that you can use MySQL to grab data from
- phpmyadmin
- PHPMyAdmin is a tool written in PHP that enables easy MySQL database management
- ssh
- ssh enables you to remotely login to the host computer from another (
ssh user@host
from a terminal in linux or I use PuTTY from windows.
Once you have installed apache you should go ahead and set a name for the server (this is partly to get rid of an error message you get when you restart it). You'll need to add
ServerName localhost
to the apache.conf file. In Ubuntu this is
/etc/apache2/apache2.conf
, but in other linux distros it can be found elsewhere.
The default place for apache to look for files to serve is
/var/www/html/
though I believe that you can change this by editing the configuration file (however I've never had cause to do so).
Some commands you'll probably find useful (these all need to be run as root or sudo):
- apache2ctl restart
- Restart the webserver - this needs to be done when you want a configuration change to take effect
- a2enmod module
- Enable an apache module whose name is module
- a2dismod module
- Disable an apache module whose name is module
Some modules you might find useful (use a2enmod, above):
- UserDir
- This module allows users to put stuff in a directory (public_html by default) within their home directory that they want to be served by the server at their user-url (/~username by default). See below for config details.
- Proxy
- Proxy another server, be this another local server or one from the net. See the apache Proxy documentation for more.
- Proxy_http
- This is the module that actually allows http proxying. It depends on the Proxy module.
I use the UserDir module as I find it simpler to edit stuff in my home directory rather than navigate to
/var/www/html/
. I use the Proxy module to aid development of a web application for
Student Robotics which is written in python, using turbogears, and so has its own server built in.
Configuring the UserDir module:
In a httpd.conf file (
/etc/apache2/httpd.conf
in Ubuntu) you could have the following lines:
UserDir disabled
UserDir enabled sam
Which enables UserDir for the user called sam but no-one else. That is
/~sam
will serve files in
/sam/home/public_html
(provided persmissions are set appropriately), but
/~anything-else
won't work. See the
apache UserDir documentation for more.