Setup Wordpress

Introduction #

This guide will help you setup Wordpress on OpenBSD. WordPress is the most dominant content management system (CMS) on the internet. You can do pretty much anything with it: from blogs to complex websites with dynamic content. This tutorial will help you get WordPress up and running on OpenBSD (6.4).

Before we can begin the actual setup, we first need to take a few a steps in preperation. These steps are necessary because the OpenBSD HTTPD server runs in a chroot. If you skip these steps you will probably get some weird errors.

All steps assume you are root.

Preparation #

DNS config #

Create a directory /var/www/etc and keep the default permissions.

mkdir /var/www/etc

Create a new file named ‘hosts’ in the /var/www/etc directory and add the entries below. Due to the chroot, DNS issues may occur. This will allow WordPress to download updates, themes, rss-feeds, and plugins.

vi /var/www/etc/hosts

127.0.0.1       localhost
198.143.164.251 api.wordpress.org
198.143.164.250 downloads.wordpress.org

Package installation #

Install the required packages

pkg_add php php-cgi fcgi php-curl php-mysqli php-zip mariadb-server mariadb-client

pkg_add wget unzip

PHP config #

Copy the sample ini files from /etc/php-8.2.sample to /etc/php-8.2/.

cp /etc/php-8.2.sample/* /etc/php-8.2/

At the time of writing, 7.2 is the newest version available in packages. Replace the 7.2 with the version you choose in case it differs.

The standard php fpm installation does not create a working pool configuration. So let’s create one.

mkdir /etc/php-fpm.d/
vi /etc/php-fpm.d/www.conf

Paste the following simple configuration in the file, save, and exit.

; Simple config: start a pool with name www, listen on a unix socket,
; and chroot to /var/www
[www]
user = www
group = www

;listen = 127.0.0.1:9000
listen = /var/www/run/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0660

;listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
chroot = /var/www

With the config in place, we can now start php fpm.

rcctl start php82_fpm

And configure the daemon to start on startup

rcctl enable php82_fpm

httpd config #

For this tutorial, we’ll be using the default OpenBSD HTTPD server and create a webserver config that handles all traffic. If you’re planning to run multiple websites on this server then you need to create multiple entries per website. For now we’ll go with the simplest setup and configuration.

For an SSL enabled webserver, follow this tutorial. The quick and non-SSL setup is to create a file called httpd.conf in /etc.

vi /etc/httpd.conf

Paste the following in the httpd config file.

types { include "/usr/share/misc/mime.types" }

server "default" {
    listen on egress port 80
    root "/wordpress"
    directory index index.php

    location "*.php*" {
            fastcgi socket "/run/php-fpm.sock"
    }
}

Now we can start the webserver.

rcctl start httpd

And configure the daemon to start on startup

rcctl enable httpd

MySQL config #

As the database, we’ll use MariaDB. The packages are already installed but we still need to configure the database itself.

mysql_install_db
rcctl start mysqld
mysql_secure_installation

You can copy the password you set during the mysql_secure_installation into the /etc/my.cnf file and create an entry like this.

# The following options will be passed to all MariaDB clients
[client]
user            = root
password        = your_password
port            = 3306
socket          = /var/run/mysql/mysql.sock

To make sure the database starts again when the server is restarted, execute the following command.

rcctl enable mysqld

Wordpress Installation #

Download WordPress, then move it into /var/www and set the correct permissions.

cd /tmp
wget https://wordpress.org/latest.zip
unzip latest.zip
mv wordpress /var/www/
chown -R www:www /var/www/wordpress/

Create the WordPress database. Make certain to replace Password with the password that you intend to use. You’ll need the password in the next step.

mysql -u root -p <password goes here>
CREATE DATABASE wordpress;
CREATE USER 'wordpress'@'localhost' identified by 'Password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'Password'; 
FLUSH PRIVILEGES;
EXIT;

You can now go to the hostname or ip address of the server but the file permissions don’t allow you to finish the installation from a browser. So we’ll finish it from the commandline.

First, copy the sample config and make it the production config.

cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

Now edit the file to make it look like this. Pay special attention to the MySQL Hostname.

vi /var/www/wordpress/wp-config.php

In this case, 127.0.0.1 and localhost are not interchangeable since /usr/local/bin/resolveip is located outside of the chroot and is not accessible
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpress');

/** MySQL database password */
define('DB_PASSWORD', 'your_mysql_password');

/** MySQL hostname */
define('DB_HOST', '127.0.0.1');

Finishing up #

You can now visit your new blog. You’ll be asked to create a new user and then you’re ready to start blogging.