How to setup a FAMP (FreeBSD, Apache, MySQL & PHP) server
Software installed and functioning by the end of this walk through :
- FreeBSD 7.1
- Apache 2.2
- PHP 5.2.8
- MySQL 6.0.9
First off grab a copy of FreeBSD 7.1 from http://www.freebsd.org/where.html
Once you have FreeBSD installed we can start.
Disk Mirroring
I decided to setup the hardware RAID in the new Sun as 2 x RAID5’s, originally i was going to have MySQL on one and everything else on the other but then after a bit of thought it occurred to me it would be cool to do RAID 51
So once you have booted into your new FreeBSD we need to setup mirroring at the terminal type:
sysctl kern.geom.debugflags=16
gmirror label -b gm0 ad0
gm0 is the name of the mirror device (geom) and ad0 is what I assume your primary disk will be called
With that done we need to make sure that the mirror modules will be loaded at boot, so type:
echo "geom_mirror_load=\"YES\"" >> /boot/loader.conf
After this is done you need to setup /etc/fstab so that it mounts the right things at boot below is my before and after – yours will be similar
Before
# Device Mountpoint FStype Options Dump Pass#
/dev/ad0s1b none swap sw 0 0
/dev/ad0s1a / ufs rw 1 1
/dev/ad0s1e /tmp ufs rw 2 2
/dev/ad0s1f /usr ufs rw 2 2
/dev/ad0s1d /var ufs rw 2 2
After
# Device Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0s1b none swap sw 0 0
/dev/mirror/gm0s1a / ufs rw 1 1
/dev/mirror/gm0s1e /tmp ufs rw 2 2
/dev/mirror/gm0s1f /usr ufs rw 2 2
/dev/mirror/gm0s1d /var ufs rw 2 2
Protip
To make the above changes in microseconds in vi do this : ": % s/\/ad0/\/mirror\/gm0/g"
You now need to reboot, once the box is back up login and issue this command :
gmirror insert gm0 ad1
Again you may not use am1 it could be different on your boxes
At this stage you now have a RAID1 that is rebuilding in the background (or in my case a 51)
Installing AMP
Firstly you need to update your port’s so issue these commands at the terminal :
portsnap fetch
portsnap extract
The order of installation isnt terribly important but it does make it smoother if you install them in alphabetical order.
First up we need to install Apache, I chose 2.2 as its what I use daily at work.
cd /usr/ports/www/apache22/
make install clean
Let it do its thing, I am going to leave all configuration changes untill we have the rest of the software installed as it makes no sense to be opening files over and over.
Once Apache is installed we can get onto MySQL, for MySQL I chose version 6 mainly because I could – but so far it seems really stable
cd /usr/ports/databases/mysql60-server/
make install clean
At this stage go out for a beer, as MySQL compiles have a habit of taking ages.
Once we have MySQL in place we can get on with PHP5, this one requires a bit more attention than the rest mailny due to its modularity
cd /usr/ports/lang/php5
make install clean
cd /usr/ports/lang/php5-extensions
make install clean
cd /usr/ports/database/php5-mysqli
make install clean
Tying it all together
At this stage everything should be installed and that’s all well and good – but none of it is actually capable of talking to each other.
Firstly we will edit apache’s config – this lives in /usr/local/etc/apache22/
Open /usr/local/etc/apache22/httpd.conf in your favroute editior (or nano while your learning to love vi)
Look for this line : LoadModule rewrite_module libexec/apache22/mod_rewrite.so
directly underneath this line add the following 3
LoadModule php5_module libexec/apache22/libphp5.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Then find this line : DirectoryIndex index.html and change it to DirectoryIndex index.html index.php
After this is done we need to give php an ini – the easiest way to do this is to copy the dist one into place
cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini
open /usr/local/etc/php/extensions.ini in your favroute editor and look for this line : extension=mysql.so if it isnt there, add it.
one last change and we are good to go!
open /etc/rc.conf in your text editor of choice and add these lines :
mysql_enable="YES"
apache2_enable="YES"
once your done reboot and enjoy!







