Apps & OS's Technology

Installing Apache, PHP and MySQL on FreeBSD 8.2

In this easy to follow tutorial I will show you how to install Apache, PHP and MySQL on FreeBSD, I have used FreeBSD 8.2 in this tutorial but should work for at least a couple of release’s later.

I will be installing the software using FreeBSD ‘Ports’ you can also install software on FreeBSD using the pkg_add system but this is not covered in this tutorial!

First of all we make sure that you have the latest snapshot of the FreeBSD ports collection, do this by running:-

portsnap fetch

and extract the infomation like so..

portsnap extract

If you already have the ports setup, you can just run portsnap update instead..

First up we are going to install MySQL, so lets begin with logging into your FreeBSD server and running this command:

cd /usr/ports/databases/mysql55-server


make install clean

The first command above changes the current directory to the MySQL server ports folder, the next adds some build parameters and the last command installs and cleans up any debris 🙂

Now we want to add MySQL as part of the startup process so when the server re-boots the MySQL daemon will run..

Open /etc/rc.conf with your editor and add the line shown below to enable starting mysql server on boot.


Now to start MySQL for the first time run this command:

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

We need to now set a password for the MySQL root user by executing..

/usr/local/bin/mysqladmin -uroot password ‘new-password’

MySQL is now installed and ready to be used!

Now we need to install and configure Apache..

cd /usr/ports/www/apache22

make install clean

..again, lets add Apache to the system startup process in the same way that we did for MySQL..


Thats it, the basic Apache22 package is now installed!

Now we install PHP5 and configure it for use with Apache..

Go to the php5 port directory by typing the command:

cd /usr/ports/lang/php5

Build and install the port by typing

make install clean

Make sure the APACHE (Build Apache module) option is ticked when configuring the build

cd /usr/ports/lang/php5-extensions

make install clean

Now, copy the default PHP.ini file so we can use it for our new installation..

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

Edit your Apache configuration file (/usr/local/etc/apache22/httpd.conf) and add this:

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

in the DirectoryIndex add the php extentions like:

DirectoryIndex index.php index.html

Edit the Languageconfiguration file (/usr/local/etc/apache22/extra/httpd-languages.conf) and add the following lines:

AddDefaultCharset On

Ok, now lets start Apache for the first time..

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

Your all done! – You should now have a fully working AMP install on your FreeBSD 8.2 server 🙂