Alwina's open source efforts


Specialized in FreeBSD and CentOS

General purpose webserver on FreeBSD VPS

January 23rd, 2011 at 22:13

This article describes how to turn a FreeBSD Virtual Private Server (VPS) into a perfect general webserver. We will instal a software suite consisting of the Apache HTTP-server, the MySQL database server and PHP (AMP). These are essential software components for a general purpose webserver. This webserver will run lots of popular software like WordPress, Joomla and Drupal. In combination with Linux this software suite is called LAMP. In this case we have FreeBSD as the operating system and use the term FAMP. This article is based on FreeBSD 7.3. This version is very well tested and stable. It is likely to work on newer version without too much difficulty.

VPS provider and FreeBSD VPS hosting plan
First you need to select a proper FreeBSD VPS hosting plan from a hosting service provider. The  hosting plan needs to offer stability, full root access, good support, connectivity, a well configured ports collection and, of course, value for your money. This article is based on a lightweight FreeBSD VPS hosting plan offered by Fastup. This plan offers a standard FreeBSD “best practices” configuration. I expect that the steps described in this article will also work for other VPS providers offering similar FreeBSD VPS hosting plans. This articles assumes you have a working install of FreeBSD 7.3 for i386 logged in as root with the ports collection installed.

Before you begin

1. Order a proper FreeBSD hosting plan
2. Learn how to access your server with SSH and access your server (with SSH or PuTTY)
3. Update /usr/ports

# portsnap fetch
# portsnap update


1. Installing MySQL

a. Build MySQL from the ports

# cd /usr/ports/databases/mysql51-server
# make install clean -DBATCH

This may take a while. Please relax and enjoy life!

b. Edit /etc/rc.conf

# vi /etc/rc.conf

Add the following line to /etc/rc.conf:


This line will enable mysql and start mysql on boot.

c. Start MySQL manually

Now we will start mysql manually with the following command:

# /usr/local/etc/rc.d/mysql-server start

d. Set password for MySQL

Set the passwor for MySQL with the followingcommand (substitute your own password for ‘your-password’):

# rehash
# mysqladmin -uroot password ‘your-password’

Step 1 completed with success: MySQL is installed!

2. Installing Apache

a. Build Apache from the ports

# cd /usr/ports/www/apache22
# make install clean -DBATCH

b. Edit /etc/rc.conf

Add the following line:


3. Installing PHP

a. Build PHP from the ports

# cd /usr/ports/lang/php5
# make install clean

Make sure the APACHE option (Build apache module) option is ticked when configuring the build. All other options should not be changed. This take a lot of time, another coffee.

b. Install the php5-extensions

# cd /usr/ports/lang/php5-extensions
# make config

Make sure you enable (1) MySQL database support, (2) MySQLi database support, (3) GD library support and (4) ZLIB support. Leave the other default options untouched!

# make install clean -DBATCH

c. Install the php.ini file

# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

You could also take the development version php.ini-development if you prefer.

d. Edit your Apache configuration file httpd.conf

# vi /usr/local/etc/apache22/httpd.conf

Add the following lines to the end of the file, just before the include statement:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Search for the line that reads:

DirectoryIndex index.html

and add index.php so it reads

DirectoryIndex index.php index.html

Enable language settings by searching for the line

#Include etc/apache22/extra/httpd-languages.conf

and removing the # comment mark so it reads:

Include etc/apache22/extra/httpd-languages.conf

e. Edit your Apache configuration file httpd-languages.conf

# vi /usr/local/etc/apache22/extra/httpd-languages.conf

Add the following line to the end of the file:

AddDefaultCharset On

f. Add you hostname to /etc/hosts

# vi /etc/hosts

Add your ‘hostname’ and your ‘hostname’.localdomain this file, so it maps to the IP of your machine.

This leads, for instance, to the addition of the following line:    freebsdx_vm14     freebsdx_vm14.localdomain

In the example above the hostname is “freebsdx_vm14″ and the IP is

g. Restart sendmail

Restart sendmail for the changes of the hostfile to take effect

# /etc/rc.d/sendmail restart

h. Start Apache

# /usr/local/etc/rc.d/apache22 start

i. Check your connectivity

Start your favorite browser from a computer connected to the internet and visit the URL:


Now you should see: “It works!”.

If there are no errors: you’re done. Apache with PHP is installed!

Congratulations. Your perfect FAMP server is up and running!

Tags: , , , , , ,

One Response to “General purpose webserver on FreeBSD VPS”

  1. Joey Burgard Says:

    Does anyone know if this get fixed?