Monday, September 10, 2007

Creating a FAMP server

What is a FAMP server?
A FAMP server is a FreeBSD web server containing the following applications:
FAMP = FreeBSD + Apache + MySQL + Perl/PHP


  1. You will need a basic install of FreeBSD, for more information on how to install FreeBSD please see: Installing FreeBSD
  2. You will need a copy of the ports, for more information please see: Using the Ports Collection.
Installing apache
I like using apache 1.3, I find it secure and stable, so I'll install it here. If you wish to use apache 2+ please see:
# cd /usr/ports/www/apache13 && make install && make clean
# echo 'apache_enable="YES"' >> /etc/rc.conf

Installing PHP
This is the way I install PHP and needed PHP modules.
# cd /usr/ports/lang/php5 && make config
# cd /usr/ports/lang/php5 && make install && make clean
# cd /usr/ports/lang/php5-extensions && make install && make clean

If you are unsure which modules you will need check the system requirements of each application you will be using on the web-server (e.g. wordpress or mediawiki).

Installing MySQL
I will install MySQL 5.0 if you would like information on other MySQL versions please see: MySQL Home Page
# cd /usr/ports/databases/mysql50-server && make install && make clean
# echo 'mysql_enable="YES"' >> /etc/rc.conf

Installing Perl DBI and DBD support
Many programs which run using both Apache and MySQL will require the following Perl modules:
# cd /usr/ports/databases/p5-DBI && make install && make clean
# cd /usr/ports/databases/p5-DBD-mysql50 && make install && make clean

It is important to add the web servers IP address to its hosts file. This suppresses errors from Apache and MySQL.
# edit /etc/hosts
adding: Hostname.domainname.tld Hostname

Configuring Apache
Before editing any file on my system I like to make a backup of it.
# cp /usr/local/etc/apache/httpd.conf /usr/local/etc/apache/httpd.conf.orig
# edit /usr/local/etc/apache/httpd.conf

In httpd.conf you will need to change the following:
*Note: These options may not suit your needs for more information please see: FreeBSD Handbook - Apache HTTP Server, or
#If your web server is inside a jail it is important to change the Listen address:
# from:
# to (Changing to the IP address of the web server):

# Change the email address of the ServerAdmin (You)
ServerAdmin you@your.address

# Change the ServerName option,
# *Note: if you don't have a fully qualified domain name
# please change this to the servers IP address
# From:
# To:

# Add a DirectoryIndex option:
DirectoryIndex index.php index.html index.htm index.php3 index.php4

# In the AddType section add the following for PHP:
AddType application/x-httpd-php .php .htm .html
AddType application/x-httpd-php-source .phps

I like to do a diff on the original httpd.conf file and my changes, so that later I can see what I changed, especially if problems arise:
# diff --suppress-common-lines /usr/local/etc/apache/httpd.conf.orig /usr/local/etc/apache/httpd.conf > /root/.apache.conf-diff

Configuring php:
# cp /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini
To Test php5
# echo "<?php phpinfo() ?>" > /usr/local/www/data-dist/phptest.html

Configuring MySQL:
# cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
Start MySQL to add root passwords:
# /usr/local/etc/rc.d/ start
# /usr/local/bin/mysqladmin -u root -h Hostname.domainname.tld password 'YourPassword'
# /usr/local/bin/mysqladmin -u root password 'YourPassword'

Now you need to reboot your web-server to startup all of your new services.

Testing your new Web Server
Once your server is up and running go to the web servers address either on the server (if it has a browser) or on your desktop box.

E.g. Open your browser and type the IP address of your server:

To test your php install type the following into your browser (changing to the IP address of the server):

If you have problems check your firewall rules, if that doesn't help check your logs, and see if they shed some light on the problem.
Have Fun!!!


Anonymous said...

i'd like to say thanks for this tutorial. i'm new to freebsd and this helped out a ton. i now have my FAMP server up-and-going. thanks again!

Kris said...

Thank you for your kind comment. We are all new at some stage, and I'm really glad that you have decided to come and join the BSD party. I really hope you enjoy your new server.
FreeBSD is a wonderful system, and although the learning curve is great I believe the experience is worth it.
Have fun, and I hope you enjoy FreeBSD.

holms said...

for those you will decide to use apache22, the rc.conf variable will be apache22_enable =) And the only way I could manage to change mysql root password is this:

mysqladmin -u root -p password "mypassword"

thnx Kris =)

holms said...

btw in php shortags are turned off by default =) so turn them on, because half scripts in the internet uses them.

Katsuke said...

thanks bro this helped a lot ^^

even though , my mysql part needed to remove the .sh and worked fine afterwards

Anonymous said...

thanks for this tutorial.. it really helps me setting up freeBSD webserver
.. thanks