In this post we'll start going into the famous Apache web server.

Some prerequisites:

Make sure that you have set up your VirtualBox to use 'Bridged Adapter' for your network adapter. In case you don't know how to do this, look in my tutorial for a step by step guide on setting up VirtualBox in Windows XP. - This applies to all other versions of Windows as far as I know.

This is really important, as it will make it a lot easier to set up port forwarding for those of you who are accessing the internet through a router (I would guess almost everyone). So in this tutorial I'll do a step by step on how I did it on my system, and chances are the settings you need to change in your router are almost the same.

Start by accessing your router's web interface. If you don't know how to get to the router do this (this tutorial was written on a PC with Windows Vista, but should be the same for all versions of Windows).

1. Click Start, then type 'cmd'.

2. Type 'ipconfig' to get information about your network. What you are looking for is the 'Default Gateway' – in most cases this is your router.

3. Fire up your browser (in this case Firefox) and type http://your-router where 'your-router' is the address you got for the default gateway. In this case I type : http://192.168.2.1 , press enter

4. Every router is different. In my Belkin router, Port forwarding is called 'Virtual Servers'. It's the same thing. Click on 'Virtual Servers'.

5. In the next screen we can define 'Virtual Servers' –

a. Type in a description of the type of service you're setting up – in our case http

b. Type in (or complete rather), the IP Address for your LAN. I chose a random number in purpose – remember, this cannot be over 254 as that's reserved. In my case as you can see I typed in 101. Leave the protocol type to TCP.

c. LAN and Public Ports. The public port is the port that the outside world can see. It's good practice to go with the internet standards defined by IANA (link to http://www.iana.org/assignments/port-numbers). Remember: STANDARDS ARE A GOOD THING. Don't break standards unless you have a good reason. The reason you can also set the LAN port is in case you're running more than one web servers in the same local network – in which case you may want to break a standard. We're keeping things simple here so just go with 80 and 80 for standard web servers.

d. Finally just tick 'Enable' and click 'Set' to activate your Virtual Server setting.

The following screenshot shows what the final result should look like for a simple configuration.

Now that our router is ready for fun, let's go back to FreeBSD.

Boot up your system and let's go ahead and check some things. The first thing we want to be sure about is that FreeBSD is set on the same IP Address we have told our Router to do the port forwarding to. I.e.

Router : Port 80 to 192.168.2.101 -> Hence FreeBSD's IP address must be 192.168.2.101. Anything else will make the server inaccessible to the outside world.

In FreeBSD type : ifconfig (Note!: In Windows it's ipconfig, in Linux/FreeBSD it's ifconfig, the functionality however is pretty much the same) and press Enter.

As you can see our FreeBSD system is set to 192.168.2.6. Last time I checked 192.168.2.6 is NOT the same as 192.168.2.101 . Seems we have to change that.

The easiest way to change the IP address is to run sysinstall. Sysinstall is the FreeBSD installer that we used in (put link to original installation) to install our FreeBSD. Back then we set it to DHCP (Dynamic Host Configuration Protocol) so that FreeBSD would pick the next available IP address by the router. We can't have that anymore though, since now we need a static IP address.

Type sysinstall

Use the arrow keys to go to 'Configure' and press Enter

Keep going down until you find 'Networking', press Enter

Go to Interfaces, press Enter

You'll get the question 'Do you want to try Ipv6 configuration of the interface?' - Select 'No' and press Enter

You'll get the question 'Do you want to try DHCP configuration of the interface?' - Select 'No' and press Enter

In the next screen you'll have to manually enter all configuration for your networking interface for FreeBSD. This isn't as bad as it sounds, since we can get all we need from Windows!

From this screen we have almost all we need:

For host use: basically whatever you like, this isn't really important at this step

Domain: let BSD fill that for you, just press TAB to move on

IPv4 Gateway: You guessed it – the same IP address as the router: 192.168.2.1 in my case.

Name server: Unless you know better, again this is the same as your router. 192.168.2.1

IPv4 address: This is where we tell FreeBSD to use the IP address of 192.168.2.101

Netmask: Most usually 255.255.255.0 for class D networks.

Extra options to ifconfig (usually empty): Yup, just leave it empty.

HINT: To navigate around here use TAB. When you're done with the settings go to 'OK' and press Enter, it should look like this.

You'll get the question 'Do you want to bring the em0 interface up right now?' - Select 'Yes' and press Enter

Then follow the prompts to exit Sysinstall.

When you exit, type 'ifconfig'. You'll see that the IP address is still the same.

Let's have a look at our /etc/rc.conf and see what settings Sysinstall put there.

ee /etc/rc.conf

As you can see, we can see both the old DHCP setting, and the new ones.

We won't be needing the DHCP setting anymore, so go ahead and comment out the whole line and also the old hostname. To comment out just put a # in front of the line.

Should look like this after the changes:

Save and exit.

However this only takes place when rc.conf is used – i.e. When FreeBSD starts up. Time for a restart to activate the changes.

Reboot the machine by typing reboot now and press Enter.

Once the machine reboots, type ifconfig again.

As you can see, the changes are now active. We're good to go.

Install Apache from ports. (If you don't have the ports already on your computer look at my post, or just type portsnap fetch;portsnap extract)

Let's go ahead and install Apache. We're going to install Apache from ports.

Type cd /usr/ports/www/apache13-modssl

Then type make install clean

When this is done you should see something like this

Start apache:

/usr/local/sbin/apachectl start

This is what you should get when it starts:

In your web browser, on your Windows system type:

http://192.168.2.101

You should see the following

This means Apache is accessible from within the LAN.

Let's try the same with the external IP Address. If you don't know what your external IP Address is , go to http://www.whatismyip.com

You should see something like this ..

So in your browser you'd have to type:

http://replace-with-your-ip

You should be getting the same screen as before, meaning apache is running succesfully.

To stop Apache type:

/usr/local/sbin/apachectl stop

to make Apache start on boot, edit your /etc/rc.conf

add the line

apache_enable="YES"

The apache files themselves are in /usr/local/www/data

For more information remember, the handbook is your friend:

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/network-apache.html

On the next chapter we'll add SSL support to Apache.