There is a nice guide on the web from Ubuntu (here), and some simple instructions are here, and the Apache docs are here. I could have started by grabbing the Server version of Ubuntu, but instead I did:
As easy as that. Start and stop commands:
To test it, just use Firefox and point it at
127.0.0.1. The index page is at
/var/www/index.html(the "document root" is
/var/www). If you want to get a little fancier, you can grab PHP:
And put this in
localhost/test.phpand it should print a bunch of details about your setup.
I spent a lot of time working on access control (Apache docs here). I should probably have read the VirtualBox guide first (here):
A virtual machine with NAT enabled acts much like a real computer that connects to the Internet through a router. The "router", in this case, is the VirtualBox networking engine, which maps traffic from and to the virtual machine transparently. The disadvantage of NAT mode is that, much like a private network behind a router, the virtual machine is invisible and unreachable from the outside internet; you cannot run a server this way unless you set up port forwarding (described below).
Actually, we will want to do this later. A lot of time was wasted because I followed the "simple" instructions (e.g. Apache's) and couldn't figure out why stuff didn't work.
It turns out that although
/etc/apache2/httpd.confhave relevant settings there are a bunch of other files (in directories under
/etc/apache2/). If you want to change access to the document root or scripts, you have to modify
/etc/apache2/sites-available/default. Guess I should have read the first page (here) of the Ubuntu Server docs. It's right there!
Here is part of the file in the original form:
I'm not sure what all of this does, but using ScriptAlias means that (Apache docs again):
The ScriptAlias directive tells Apache that a particular directory is set aside for CGI programs. Apache will assume that every file in this directory is a CGI program, and will attempt to execute it, when that particular resource is requested by a client.
I just modified
And, since we will ultimately care about access permissions, you should read (at least) this page of the docs, which explains that
is explained as:
First, all Allow directives are evaluated; at least one must match, or the request is rejected. Next, all Deny directives are evaluated. If any matches, the request is rejected. Last, any requests which do not match an Allow or a Deny directive are denied by default.
First, all Deny directives are evaluated; if any match, the request is denied unless it also matches an Allow directive. Any requests which do not match any Allow or Deny directives are permitted.
I copied from further down in the file (about access to
/usr/share/docs) to the ScriptAlias directive above:
The subnet masking stuff will need an explanation of its own.
So now, I can put the first script from the second part of this post (that prints data from
cgi-binunder my home directory, and it works.