How to set up a WordPress environment in FreeBSD

Assumptions
I'm assuming you're on FreeBSD 9.1 and want the latest stable versions of MySQL(5.6), Apache(2.4), and PHP(5.5). Feel free to change the version numbers as necessary.

Software installation
To get WordPress up and running, first we need MySQL, Apache, and PHP. Preferably, in that order so we can manually install which version of each software we want to install. Otherwise, portsnap will automatically download the dependencies, but it doesn't always grab the latest version.

MySQL 5.6
Download and install.
cd /usr/ports/databases/mysql56-server/
make install clean

Apache 2.4
Download and install.
cd /usr/ports/www/apache24/
make install clean

PHP 5.5 and extensions
Download and install. Make sure to select "Build Apache module".
cd /usr/ports/lang/php55/
make install clean

Download and install. Make sure to select "MySQL database support", "PHP Data Objects Interface", "PDO MySQL driver", and any other extensions you may want.
cd /usr/ports/lang/php55-extensions/
make install clean

Software configuration
Now that the webserver software is installed, it's time to configure and hook everything up.

MySQL 5.6
Create or edit the MySQL configuration file at this location.
/usr/local/etc/my.cnf

Put the following configuration inside to make sure MySQL can fully support UTF-8 encoded Unicode characters.
Code:
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

Add to startup programs.
echo 'mysql_enable="YES"' >> /etc/rc.conf

Start MySQL server.
service mysql-server start

Apache 2.4
Edit the Apache configuration file at this location.
/usr/local/etc/apache24/httpd.conf

Change the server root, if you want. This is the default setting.
ServerRoot "/usr/local"

Make sure these settings are not commented out.
LoadModule php5_module libexec/apache24/libphp5.so
LoadModule rewrite_module libexec/apache24/mod_rewrite.so

Set the server name to localhost or else Apache will complain.
ServerName localhost:80

Allow .htaccess to override derectives so that mod_rewrite will work. Default value is set to none, change it to all.
Code:
<Directory "/usr/local/www/apache24/data">
  ...
  AllowOverride All
</Directory>

Have Apache run PHP scripts.
Code:
<IfModule mod_php5.c>
  DirectoryIndex index.php index.html
  AddType application/x-httpd-php .php
</IfModule>

Add to startup programs.
echo 'apache24_enable="YES"' >> /etc/rc.conf

Start MySQL server.
service apache24 start

Download WordPress
Switch to the website's directory, download the latest version of WordPress, and extract the compressed file.
cd /usr/local/www/apache24/data/
curl -O [url=http://wordpress.org/latest.tar.gz]http://wordpress.org/latest.tar.gz[/url]
tar -xvf latest.tar.gz

The rest should be easy, just visit your website in a browser and complete WordPress's famous 5-minute install process. You should be able to connect to a database with PHP and user permalinks.

***Bonus MySQL statements
In case, that you don't know very much MySQL, the following two statements is all you need to get started with WordPress.

Create a new database.
Code:
CREATE DATABASE dbname;

Create a user with a password and grant that user all database privileges.
Code:
GRANT ALL PRIVILEGES ON dbname.* 
TO 'username'@'localhost' 
IDENTIFIED BY 'password';

FLUSH PRIVILEGES;
 
Back
Top