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

Requirments

  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: httpd.apache.org.
# 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


Configuration
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:
192.168.0.252 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 httpd.apache.org
#If your web server is inside a jail it is important to change the Listen address:
# from:
#Listen 12.34.56.78:80
# to (Changing 192.168.0.252 to the IP address of the web server):
Listen 192.168.0.252:80

# 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:
#ServerName www.example.com
# To:
ServerName 192.168.0.252

# 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/mysql-server.sh 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: http://192.168.0.252/

To test your php install type the following into your browser (changing 192.168.0.252 to the IP address of the server):
http://192.168.0.252/phptest.html

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!!!

Tuesday, September 04, 2007

Moveable Type 4.0

If you read my: Of Tea and Turtles blog; you'll know that I've been away from the real world, dealing with family reality for the past couple of weeks, yet I'm trying to get back on track.

I've been playing around with Moveable Type 4.0, for a couple of days now, and I'm really impressed. The company is currently moving towards an Open Source solution: Movable Type Open Source Project.

I've been using the free for personal use Moveable Type (MT4) on FreeBSD 5.5, and I'm really happy with it's performance. There are a number of programs needed, before installing MT4, and you need to change permissions on a number of MT4 files, yet once it is running it is very nice to use.

From what I've read there have been many changes since the last version, yet this is the first time I've used it. For information on MT4 please see: Moveable Type 4.

I'm going to write a tutorial on performing a Moveable Type installation, yet I thought I would write a FAMP (FreeBSD Apache Mysql and Perl/PHP) how to first. Then I can write a number of tutorials linking back to the main FAMP one.

Sunday, August 12, 2007

FreeBSD Tip: beastie boot menu

After installing FreeBSD 5.5 I like to change the beastie in the boot menu to colour instead of white. I think this adds a nice touch to the boot, plus it is really easy to do.

To add a splash of colour to beastie type the following:
# echo 'loader_color="YES"' >> /boot/loader.conf

By default the delay, before autobooting is 10 seconds. You can change this by adding the following:
# echo 'autoboot_delay="n"' >> /boot/loader.conf
Where "n" is the number of seconds before autobooting.

Note: you can set the autoboot to -1; if you don't want user to be allowed to interrupt autoboot process and escape to the loader prompt.

If you don't like the beastie menu you can disable it like this:
# echo 'beastie_disable="YES"' >> /boot/loader.conf

Have fun :)

Friday, August 10, 2007

Unhooked...

Our network has been down for the past few days, therefore no Internet.
I'm not 100% sure exactly what the problem was. It seems that it was partly our ISP's DNS server, partly a dodgy phone line, and partly an operating system which kept changing my settings back to it's settings (it knew what I "really" wanted :s).

Also as a separate issue; our firewall's hardware is dying.
I don't know what I'm going to do with it, I guess I'll have to find the money to buy another computer. That should be fun, what with the thousands of dollars we have coming in right now... (not)

I hate being offline, I forget how hooked I am till I can't get out...
I think at times we rely to much on technology. It kinda makes me wonder what we did before computers, before plastic...

Gee I feel cynical and sarcastic tonight, it must be all the fun I've been having...
Life what an interesting little mind fuck... ;)

Thursday, August 02, 2007

Zero Comes First

When I'm flicking through terminals (ttys), I find it frustrating that the keys start with the number 1 (F1), and not 0.
I use a simple trick remind myself where they are.

1. First I get some self adhesive labels, you can buy them from most newsagents.
2. Then I write out the numbers 0-9 and a-b, fairly neatly and about 5mm x 5mm big. (You could always print them out if you want them to be neater).
3. Cut them out, like in the image to the right.
4. Now place them on the keys.

Done, now next time you need to go to tty4 you can press F5 with out even thinking about it.

Adding OpenBSD to Grub

I added OpenBSD to my GRUB menu.lst config file today. After a bit of messing around, it still didn't boot. So I did a Google search and came across this file: GRUB's menu.lst config file, with examples for various OSes.

This file details where I was going wrong, and how to boot OpenBSD using GRUB. I have placed the relative information here for future reference:
# The OpenBSD section of the menu.lst config file, for GRUB.
#
## You would like to use:
# root (hd1,1,a)
# kernel --type=openbsd /bsd
#
# But OpenBSD passes bios & kernel parameters with its own bootloader,
# the first stage of which is installed in the partition boot record,
# and in turn calls /boot, which in turn loads kernel /bsd. So just
# use the GRUB chainloader instead:
#
## OpenBSD
title OpenBSD
root (hd1,1)
makeactive
chainloader +1

Wednesday, August 01, 2007

OpenBSD: From Release to Stable

Upon installing OpenBSD I like to update it from a release to a stable, which gives me all of the security patches since the release.
There are a number of ways of updating, yet I personally like to rebuild the system from source. That way I don't have to go through each patch and apply it. For more information please see: Building the System from Source

There are a number of different "flavours" of OpenBSD:

  • -release -- The version which is released on CD every 6 months
  • -stable -- Release plus security patches
  • -current -- The development branch
There are three steps we need to take to update the system:
  1. Download the latest Source code
  2. Compiling and installing a GENERIC kernel
  3. Rebuilding the system
Download the latest Source code
There are a number of ways to get the latest source, yet I use cvs.
First I need to find a anoncvs mirror: Available Anonymous CVS Servers
Once I've decided on a server I export the mirror path to CVSROOT and download the source, e.g.:
# export CVSROOT=anoncvs@anoncvs.openbsd.org:/cvs
# cd /usr; cvs checkout -P -rOPENBSD_4_1 src


Note: the CVSROOT variable will not be kept after next boot. To keep this setting add it to your /root/.profile file, e.g.:
# vi /root/.profile
adding:
export CVSROOT=anoncvs@anoncvs.openbsd.org:/cvs

Compiling and installing a GENERIC kernel
First backing up current kernel
# cp /bsd /bsd.old

Then configure the kernel
# cd /usr/src/sys/arch/i386/conf
# config GENERIC


Now Compile and Install the new Kernel
# cd /usr/src/sys/arch/i386/compile/GENERIC
# make clean && make depend && make && make install


Lastly reboot and test the new kernel
# reboot

Rebuilding the system
Now I just rebuild the system:
# rm -rf /usr/obj/*
# cd /usr/src; make obj
# cd /usr/src; make build


Now reboot
# reboot
When I first log back in the first thing I notice that my system name now says OpenBSD4.1-stable.

Now I have a stable system with all of the important security updates on it.