Installing Apache, PHP, MySQL and MemCached on FreeBSD

This is my note on how to to install Apache, PHP, MySQL and MemCached on a FreeBSD 7 Box.

1. MySQL

Go to the mysql52-server port directory by typing the command:

cd /usr/ports/databases/mysql51-server

Build the port by typing:

make BUILD_OPTIMIZED=yes BUILD_STATIC=yes

Using these two options will speed up the execution time.

Install the port by typing:

make install clean

Open the configuration file: ”’/etc/rc.conf”’ and add the following at the end of the file:

mysql_enable="YES"

Copy the default configuration file:

cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf

Start mysql manually to avoid having to reboot now by typing:

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

Setup the a master password for root user:

/usr/local/bin/mysqladmin -u root password 'new-password'

2. Apache

Go to the apache22 port directory by typing the command:

cd /usr/ports/www/apache22

Install the port by typing:

make install clean

Open the configuration file: ”’/etc/rc.conf”’ and add the following at the end of the file:

apache22_enable="YES"

Add the following in: ”’/boot/loader.conf”’

accf_http_load=YES

3. PHP

3.1 PHP5

Go to the php5 port directory by typing the command:

cd /usr/ports/lang/php5

Install the port by typing:

make install clean

Make sure the APACHE (Build Apache module) option is checked.

3.2 PHP5 Extentions

Note: If you need to install PDF-Lite, please do the following:

fetch ftp://ftp.swin.edu.au/gentoo/distfiles/PDFlib-Lite-7.0.2.tar.gz
sudo mv PDFlib-Lite-7.0.2.tar.gz /usr/ports/distfiles/

Go to the php5 extensions port directory by typing the command:

cd /usr/ports/lang/php5-extensions

Make sure sockets is selected.

Install the port by typing:

make install clean

Install the php.ini file:

cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini

3.3 Enable PHP in Apache

3.3.1 httpd.conf

Edit the Apache configuration file ”’/usr/local/etc/apache22/httpd.conf”’ and add the following lines to the end of the file:

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

Replace this line:

DirectoryIndex index.html

by the following:

DirectoryIndex index.php index.html
3.3.2 httpd-languages.conf

Edit the Languageconfiguration file ”’/usr/local/etc/apache22/extra/httpd-languages.conf”’ and add the following lines to the end of the file:

AddDefaultCharset On

Startup the Apache:

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

4. MEMCached

Go to the pecl-memcache port directory by typing the command:

cd /usr/ports/databases/pecl-memcache

Install the port by typing:

make install clean

Go to the memcached port directory by typing the command:

cd /usr/ports/databases/memcached

Install the port by typing:

make install clean

Open the configuration file: ”’/etc/rc.conf”’ and add the following at the end of the file:

memcached_enable="YES"

To start using MemCached without rebooting, type:

/usr/local/bin/memcached -d -u nobody

–Derrick

Our sponsors: