This article covers how to setup and configure WordPress on FreeBSD 13. WordPress is a popular Content Management System (CMS) used for website and blogging platforms. You can easily customize your website using WordPress by adding content such as text, images, video, GIF, etc.

FreeBSD is a Unix operating system that is used to power servers, embedded systems and desktops.

To have a WordPress site running on FreeBSD you will need a FEMP stack. This means that you need to have FreeBSD,Nginx, MySQL and PHP configured as a stack.

This guide shall cover how to have this done. Let’s dive right in!. We shall start by setting up FEMP on our FreeBSD 13 server.

Step 1: Setup and Configure PHP on FreeBSD 13

Before you can install PHP, make sure the system is updated.

freebsd-update fetch
freebsd-update install

Install PHP and PHP extensions with the command below:

pkg install php74 php74-mysqli php74-mbstring php74-zlib php74-curl php74-gd php74-json php74-composer php74-extensions

Configure PHP-FPM on FreeBSD 13

PHP-FPM is required to parse php files to Nginx.

Copy the sample PHP config file:

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

Uncomment the line ;cgi.fix_pathinfo=1 in the /usr/local/etc/php.ini file and set the value to 0.

vi /usr/local/etc/php.ini

cgi.fix_pathinfo=0

Edit the configuration file at /usr/local/etc/php-fpm.d/www.conf and make the following changes:

vi /usr/local/etc/php-fpm.d/www.conf

Uncomment the following lines:

listen.owner = www
listen.group = www
listen.mode = 0660

Comment the line listen = 127.0.0.1:9000 and add the php-fpm socket as below:

;listen = 127.0.0.1:9000
listen = /var/run/php74-fpm.sock;

Enable and start PHP-FPM

service php-fpm enable
service php-fpm start

Step 2: Setup and Configure Nginx on FreeBSD 13

Nginx will be used as the webserver for our WordPress site.

Install Nginx from FreeBSD repositories using pkg command.

pkg install nginx

Start and enable Nginx

service nginx enable
service nginx start

You might want to check status of Nginx service:

$ service nginx status
nginx is running as pid 1195.

Configure Nginx on FreeBSD 13

Nginx default configuration files for FreeBSD reside at /usr/local/etc/nginx. Edit the nginx.conf file in that directory and add the following configuration:

vim /usr/local/etc/nginx/nginx.conf

Uncomment the line #user nobody and change the value to:

user www;

Change the value of worker_processes to 2.

worker_processes 2;

Uncomment the erro_log and create the access_log directives:

error_log /var/log/nginx/error.log info;
access_log /var/log/nginx/access.log;

Set the server name to an appropriate server name of your domain.

sever_name example.com;

Configure Nginx document root directory and allow it to recognize .php files:

server {
        listen       80;
        server_name  example.com www.example.com;
        root /usr/local/www/wordpress;
        index index.php index.html index.htm;
location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }

Configure PHP-FPM

 location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php74-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $request_filename;
                include fastcgi_params;

A complete configuration file will look like this below:

user  www;
worker_processes  2;
error_log /var/log/nginx/error.log info;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    access_log /var/log/nginx/access.log;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  example.com www.example.com;
        root /usr/local/www/wordpress;
        index index.php index.html index.htm;

        location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page      500 502 503 504  /50x.html;
        location = /50x.html {
            root /usr/local/www/nginx-dist;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php74-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $request_filename;
                include fastcgi_params;
        }
    }
}

You can alternatively copy the above config file and replace it with your /usr/local/etc/nginx/nginx.conf file.

Test if nginx configuration is okay:

nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

Restart Nginx service

service nginx restart

Step 3: Install and Configure MariaDB on FreeBSD 13

The next step is to install and configure MariaDB.

MariaDb can be installed from FreeBSD repo with the command below:

pkg install mariadb105-server mariadb105-client

Configure MariaDB

Start and enable MySQL server

service mysql-server enable
service mysql-server start

Run the command below for MySQL server hardening:

mysql_secure_installation

Run through the configuration to setup a secure and hardened MySQL server:

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

You can now login with the password you provided above:

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 59
Server version: 10.5.9-MariaDB FreeBSD Ports

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

[email protected] [(none)]> 
Enable MariaDB Password Authentication

MariaDB comes with Unix socket authentication as the default authentication method and mysql_native_password as a failover mechanism. To make password authentication as the default mechanism, we need to alter the user to use the native plugin:

ALTER USER [email protected] IDENTIFIED VIA mysql_native_password USING PASSWORD("[email protected]");
FLUSH PRIVILEGES;
Setup WordPress Database and user

We will then be required to setup the WordPress database and user:

  1. Create database
[email protected] [(none)]> create database wordpress;

2. Create user

[email protected] [(none)]> create USER [email protected] IDENTIFIED VIA mysql_native_password USING PASSWORD("[email protected]");

3. Grant user permissions to the wordpress database:

[email protected] [(none)]> grant all privileges on wordpress.* to [email protected] with grant option;
[email protected] [(none)]> flush privileges;

In the above steps, we have created a database (wordpress), user (wpuser) and passsword([email protected]). You should choose your appropriate username and password. We have also granted database user (wpuser) permissions to the database(wordpress).

Step 4: Install WordPress on FreeBSD 13

Download the latest version of WordPress from the WordPress projects site.

cd /usr/local/www
fetch http://wordpress.org/latest.tar.gz

Extract the downloaded file. This creates a directory called wordpress.

tar xzvf latest.tar.gz

Set permissions to the extracted directory

sudo chown -R www:www /usr/local/www/wordpress

Remember we had set the document root in nginx.conf file as /usr/local/www/wordpress.

Configure WordPress on FreeBSD 13

We will then proceed to configure WordPress from the web interface.

Navigate to http://<your-IP> to proceed with configuration:

Proceed with the installation by inputting the correct database, username and password. The host remains as localhost:

Upon successful configuration of the database credentials, you will get to this point below:

Proceed with the installation and setup site details like Admin credentials and email address in the next interface:

Upon successful setup:

You can now login to your wp-admin interface using the credentials you created above:

Then you will be presented with the admin interface where you can now edit your posts and publish your content:

You then will have created your WordPress server and have a WordPress website up and running!

That’s all needed to setup a WordPress on FreeBSD 13. I hope this was helpful. Cheers!