How to Install WordPress on FreeBSD 11.0

Motivation

WordPress is a free and open source content management system written on PHP and MySQL which powers most of the websites running. WordPress powers more than 28% of the top 10 million websites as of July 2017, supporting more than 76.5 million websites on the web. It is developed and maintained by the WordPress Foundation and is released under GNU GPLv2 or later. Running websites and blogs on WordPress is very easy task which doesn't require expertise in programming. FreeBSD is a free and open source Unix-like operating system derived from Research Unix via the Berkeley Software Distribution (BSD). It is similar to Linux but with two major differences in scope and licensing. FreeBSD develops and maintains a complete operating system (from kernel, device drivers, and utilities) and is released under a permissive BSD license which opposes the copyleft GPL used by Linux. It is widely used across desktop, workstation, server and embedded systems. Here, we'll install WordPress on the latest FreeBSD 11 with a complete FAMP Stack (FreeBSD with Apache as web server, MySQL for database system and PHP modules).

1) Installing Apache Web Server

To install Apache web server on FreeBSD, we can use its default package manager ie pkg which allows us to install the Apache web server from the official FreeBSD package repository. To install apache using pkg, we'll need to run the following command.

%pkg install apache24

2) Installing MySQL

Once Apache Web Server is installed, we'll go further on installing MySQL database server so that we can use it for managing data for our wordpress instance. To install MySQL server, we'll need to run the following command in the console which will install mysql server version 5.6.

% pkg install mysql57-server

3) Enabling Apache and MySQL services

To enable Apache and MySQL services, we'll run the following sysrc command. Enabling the services will run the daemons automatically on every system boot.

%  sysrc apache24_enable=yes mysql_enable=yes

Once done, we'll start the daemons by running the following command.

%  service apache24 start
%  service mysql-server start

4) Configuring MySQL

Now, as we haven’t assigned a root password for our MySQL server, we’ll configure a root password for it. To do so, we'll need to run the following command.

%  mysql_secure_installation

It will ask us to enter the root password for our MySQL server but as we haven’t set any password before and it’s our first time we’ve installed mysql, we’ll simply hit enter button from keyboard and move ahead. Then, we’ll be asked to set password for our MySQL root user, here we’ll hit Y and enter it. Then, we’ll simply strike enter button on keyboard to set the default values for the further settings.

5) Creating Database for WordPress

As our MySQL server has been configured successfully, we'll now create a new database for our WordPress installation. To do so, we'll first need to login to the root user of the mysql server by running the following command.

%  mysql -u root –p

Then, we'll be asked to enter the password which we had set just above. Once login is success, we'll be welcomed into the MySQL console environment. Here, we'll need to run the following commands to create database and set a user and password for it:

> CREATE DATABASE wordpressdb;
> CREATE USER wordpressuser@localhost IDENTIFIED BY M4sterS1ave ';
> GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressuser'@'localhost';
> FLUSH PRIVILEGES;
> EXIT;

Here, in this tutorial, we are creating a new database, user and password as wordpressdb, wordpressuser and M4sterS1ave respectively.

6) Installing PHP 7.0 Modules

Next, we'll install all the required PHP 7.0 modules so that our wordpress which is written in PHP can execute. So, in order to install the required PHP modules, we'll need to run the following command.

%  pkg install mod_php70 php70-mysqli php70-xml php70-hash php70-gd php70-curl php70-tokenizer php70-zlib php70-zip

We'll then copy the production php configuration ie /usr/local/etc/php.ini-production to /usr/local/etc/php.ini by executing the following command.

%  cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Then, we'll need to run rehash command in order to regenerate the system's cache information about our installed executable files.

% rehash

7) Configuring Apache

Once PHP is installed on our FreeBSD 11, we'll now need to configure Apache so that it can handle and execute PHP files. To do so, we'll need to edit /usr/local/etc/apache24/Includes/php.conf using a text editor.

%  vi /usr/local/etc/apache24/Includes/php.conf

Once the text editor open the file, we'll need to make changes to the file as shown below:

<IfModule dir_module>
    DirectoryIndex index.php index.html
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
</IfModule>

Once done, we'll save and exit it. Then we'll need to restart the apache web server in order to apply the above changes.

%  service apache24 restart

8) Downloading and Extracting WordPress

Once our FAMP stack is up and ready, we'll now move ahead towards the installation of WordPress on our machine running FreeBSD 11. Here, we'll download the latest release of WordPress inside a /tmp/ directory, to do so, we'll need to execute the following command on the console.

% cd /tmp/
% fetch http://wordpress.org/latest.tar.gz

Once the latest release of wordpress tarball is downloaded, we'll then extract the file inside the /tmp/ directory.

% tar xvf latest.tar.gz

Then, we'll copy the extracted files to the webroot of Apache Web server ie /usr/local/www/apache24/data/ . To do so, we'll use the cp command as shown below.

% cd /tmp/wordpress/
%  rm -rf /usr/local/www/apache24/data/index.html
%  cp -pr /tmp/wordpress/* /usr/local/www/apache24/data/

Next, we'll need to recursively apply the files and directories ownership as www:www using chown so that Apache will have full read and write access over the directory.

%  chown -R www:www /usr/local/www/apache24/data/

Conclusion

WordPress can be easily installed into our machine running FreeBSD by following this tutorial as above. WordPress is widely used Content Management System which is best known for its easy and rapid website and blogs development and its varieties of thousands of plugins and tools available on the internet. Moreover, WordPress on top of Apache, MySQL and PHP 7.0 running in very stable Unix-like operating system FreeBSD 11 makes it fast, secure and stable. This setup combination is very well known for the speed, stability, security and reliability. We can even make the use of Nginx as reverse proxy for enhancing the speed and efficiency of the site and system.