erdfisch Blog

How to install Apache, PHP, MySQL, drush, Drupal on FreeBSD 9

Single image: 

For sure, there are plenty enviroments on which Drupal can be run. But often it is not clear how to get started. Therefore I will explain a very common way to run drupal on a FreeBSD System. Most of the steps should be almost the same on a Linux system.

1. Installing a Apache 2.4 Webserver

First of all, switch the user to root:

# su root

Install apache24 from your ports collection

# cd /usr/ports/www/apache24


make install

The configuration file of teh Apache Server needs some adjustment before you can run your webserver properly.

Make a backup copy of your httpd.conf before you proceed with the following steps.

# cp /usr/local/etc/apache24/httpd.conf /path/to/backupfolder/

Now edit the /usr/local/etc/apache24/httpd.conf with a editor of your choice and set these settings:

These settings don't need to make any sense; just type in what you like if you set up a development environment only.
It will be displayed when a server error or similar occurs.

DocumentRoot "/usr/local/www/data"
This defines the folder which will be availeble over http.

To start The apache server add the following line to your /etc/rc.conf:


and execute

# hash -r

apachectl start

2. Installing the php interpreter

Install the port

# cd /usr/ports/lang/php5


make install

You might get a notice that you have to add some lines to your /usr/local/etc/apache24/httpd.conf. If that's the case, just follow the instructions. A very useful feature of Drupal is that it can use clean urls. This feature needs the mod_rewrite php-module. you can enable it by removing the comment marker in the corresponding line in your /usr/local/etc/apache24/httpd.conf

You will also need some modules which are available in the lang/php5-extensions port. Make sure to check that you have MySQL support before proceeding with the installation process

Install the port:

# cd /usr/ports/lang/php5-extensions


make install

3. Installing MySQL

Install the port

# cd /usr/ports/databases/mysql55-server/


make install

To be able to start the MySQL server add the following to your /etc/rc.conf


Now start the server:

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

You should change the mysql server's root password. In order to do so, please enter

# mysql -u root

SET PASSWORD FOR root@localhost=PASSWORD('newPassword');

To grant Drupal access to your mysql databases, you have to install this port too:

# cd /usr/ports/databases/php5-pdo_mysql


make install

Now you will have to restart your apache server

# apachectl restart

4. Creating a Database and user for drupal

You are free to use any MySQL management tool out there to do this. Just create a database and a user with all privileges for the database or tables Drupal should use. If you don't use a tool, just perform these commands:

# mysql -p

CREATE DATABASE drupal_database;
CREATE USER 'drupal_user'@'localhost' IDENTIFIED BY 'mypass';
GRANT ALL PRIVILEGES ON drupal_database . * TO 'drupal_user'@'localhost' WITH GRANT OPTION;

5. Installing drush and Drupal

I recommend to use drush to manage your Drupal installation. It makes it much more comfortable for recurring operations like downloading or enabling or updating modules, clear caches and more.

For setting up drush, first you have to get a copy on and extract the archive into an empty directory.

# unzip -d /usr/local

After this, set up a link onto the drush folder in /usr/local/bin/ so that you don't need to enter the entire folder path all the time when you want to use it.

# ln -s /usr/local/drush-master/drush /usr/local/bin/drush

Drush needs some libraries, it will automatically download them by simply running

# drush

6. Installing Drupal

You won't need root previleges anymore so switch back to your user.

# exit

Now switch to the DocumentRoot of your apache configuration.

$ cd /usr/local/www/data
$ drush dl drupal
$ mv drupal-7.* drupal && cd drupal
$ drush si --db-url=mysql://drupal_user:mypass@localhost/drupal_database
$ chmod 777 sites/default/files

After this you should be able to visit your Drupal site for the first time:

7. Congratulations you have a running Drupal installation now on your computer!

You may notice that you run into problems if you have a large amount of content in your database. Therefore you have to increase some memory limitations of your PHP and MySQL server config.