Running WordPress on OpenBSD 6.5 with OpenBSDs HTTPD

Introduction

The closer you keep your OpenBSD install to the default and without as many added packages, the more secure it will be. While the more common setup for WordPress is to use Apache and PHP, it is definitely possible (and preferable) to use OpenBSD's built-in httpd. This tutorial will get you started with a complete setup of a Let's Encrypt certificate, a web server, and WordPress. You will need root access in order to be able to do this.

Initial Configuration

If you have not already done so, you will need to create a /etc/doas.conf file. The doas command is OpenBSD's easy replacement for sudo.

su -
echo "permit nopass keepenv :wheel" > /etc/doas.conf

We have to tell OpenBSD where the packages are located. This happens in the /etc/installurl file.

doas su
echo "https://cdn.openbsd.org/pub/OpenBSD" > /etc/installurl
exit

Now we have to add PHP and some extra modules that WordPress will need in order to handle things like images and encryption. When prompted, choose to install the newest package of PHP. One thing you have to do is to copy the module ini files from the sample directory to the main one. This has to be done in order to enable the additional PHP modules.

doas pkg_add -r mariadb-client mariadb-server php php-curl php-mysqli pecl73-mcrypt pecl73-imagick 
doas su -
cp /etc/php-7.3.sample/* /etc/php-7.3/.

Obtain Let's Encrypt Certificates

OpenBSD has a great application called acme-client. This little innovation is what will generate your account key, private key, and obtain a certificate for you. The acme-client depends upon having a web server in place so we define a quick default server definition.

With your favorite editor, create /etc/httpd.conf. We will add the other server definitions to the file later. What we need to do now is prepare httpd to perform the challenge-response to obtain a free, valid SSL certificate.

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

server "default" {
    listen on egress port 80
    root "/htdocs"
    directory index "index.html"

    location "/.well-known/acme-challenge/*" {
        request strip 2
        root "/acme"
    }
}

Also using your favorite editor, create /etc/acme-client.conf.

authority letsencrypt {
    api url "https://acme-v01.api.letsencrypt.org/directory"
    account key "/etc/acme/letsencrypt-privkey.pem"
}

authority letsencrypt-staging {
    api url "https://acme-staging.api.letsencrypt.org/directory"
    account key "/etc/acme/letsencrypt-staging-privkey.pem"
}

domain example.com {
    alternative names { www.example.com }
    domain key "/etc/ssl/private/example.com.key"
    domain full chain certificate "/etc/ssl/example.com.fullchain.pem"
    sign with letsencrypt
}

Enable and start httpd, then get a certificate issued. You will see that a certificate has been issued.

doas rcctl enable httpd php73_fpm
doas rcctl start httpd
doas acme-client -ADFv example.com
doas rcctl stop httpd

Adding the Server Definitions

Add the following configuration lines to /etc/httpd.conf, just after the Let's Encrypt definitions. Setup httpd to perform a redirect from http to https because you have a free SSL certificate and you never want to risk sending a login and password over an insecure link. Take note of the line, location "/posts/*" This is the piece that makes the WordPress permalinks look pretty. Also, this config contains a way to help prevent brute-force attempts to login to the WordPress admin site.

server "example.com" {
    listen on egress port 80
    alias "www.example.com"
    block return 302 "https://$SERVER_NAME$REQUEST_URI"
}

server "example.com" {
    listen on egress tls port 443
    alias "www.example.com"
    root "/htdocs/example.com
    directory index "index.php"

     location "/posts/*" {
        fastcgi {
             param SCRIPT_FILENAME "/htdocs/example.com/index.php"
             socket "/run/php-fpm.sock"
        }
     }

     location "/wp-json/*" {
        fastcgi {
           param SCRIPT_FILENAME "/htdocs/example.com/index.php"
            socket "/run/php-fpm.sock"
        }
     }

    location "/wp-login.php*" {
        authenticate "WordPress" with "/htdocs/htpasswd"
        fastcgi socket "/run/php-fpm.sock"
     }

    #Uncomment the following lines to disable xmlrpc. You increase security 
    #at the expense of being able to use to use 
    #the Android and iPhone WordPress App.
    #location "xmlrpc.php*" {
    #    block return 404
    #}        

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

    tls {
        certificate "/etc/ssl/example.com.fullchain.pem"
        key "/etc/ssl/private/example.com.key"
    }
}

Create the username and password file for an additional level of security to the WordPress admin site. Choose a good password. This will prompt you for a username and password in order to run the wp-login.php script.

doas su
cd /var/www/htdocs
htpasswd htpasswd wp_user
chown www:www htpasswd
chmod 0640 htpasswd

Prepare and Configure MariaDB

MariaDB is a drop-in replacement fork of MySQL. We need to do some initial configuration and database preparation work for WordPress.

Before we can use MariaDB effectively, we need to allow the mysql daemon to use more resources than the default. In order to do this, make the following changes to/etc/login.conf by adding this entry at the bottom.

mysqld:\
    :openfiles-cur=1024:\
    :openfiles-max=2048:\
    :tc=daemon:

Enable and start MariaDB. This procedure will set a root password and optionally drop the test database. It's a good idea to follow the suggestions in the secure installation stage.

 doas mysql_install_db
 doas rcctl enable mysqld
 doas rcctl start mysqld
 doas mysql_secure_installation

Create the WordPress database and database user.

mysql -u root -p 
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost' IDENTIFIED BY '<password>';
FLUSH PRIVILEGES;
EXIT

Install and Configure WordPress

WordPress has not had an official OpenBSD port for quite some time because it pretty much works right out of the box. Download, extract, and move the WordPress installation folder.

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xvfz latest.tar.gz
doas mv wordpress /var/www/htdocs/example.com
chown -R www:www /var/www/htdocs/example.com

We have to copy /etc/resolve.conf and /etc/hosts to /var/www/etc. This is so that WordPress can successfully reach the marketplace. You will need this in order to download plugins and themes via the WordPress admin site.

doas mkdir /var/www/etc
doas cp /etc/hosts /var/www/etc/.
doas cp /etc/resolv.conf /var/www/etc/.

Start httpd and php73_fpm.

doas rcctl start httpd php73_fpm

Browse to the url that you used in your server definition. You will see the WordPress installation wizard. For the Database server option, replace localhost with 127.0.0.1.

Once WordPress has been installed, it's time to set up the permalinks so that they look more SEO friendly. From the WordPress admin screen, go to Settings -> Permalinks. Click on Custom Structure and type /posts/%postname%. After making this change, click the Save Changes button. You now have much nicer looking links. For example, a permalink will look like this: https://example.com/posts/example-blog-post



Leave a Comment

Cómo instalar Blacklistd en FreeBSD 11.1

Cómo instalar Blacklistd en FreeBSD 11.1

Introducción Cualquier servicio que esté conectado a Internet es un objetivo potencial para ataques de fuerza bruta o acceso injustificado. Hay herramientas como fail2ba

How To Install Apache, MySQL and PHP (FAMP) Stack on FreeBSD 12.0

How To Install Apache, MySQL and PHP (FAMP) Stack on FreeBSD 12.0

Introduction A FAMP stack, which is comparable to a LAMP stack on Linux, is a collection of open-source software that is typically installed together t

Configurar OpenBSD 5.6 con cifrado de disco completo

Configurar OpenBSD 5.6 con cifrado de disco completo

Este tutorial le mostrará cómo configurar OpenBSD 5.6 con un disco completamente encriptado en su Vultr VPS. Una nota sobre la parte de cifrado: la mayoría de los centros de datos alrededor de

Cómo usar Sudo en Debian, CentOS y FreeBSD

Cómo usar Sudo en Debian, CentOS y FreeBSD

Usar un usuario sudo para acceder a un servidor y ejecutar comandos a nivel raíz es una práctica muy común entre Linux y Unix Systems Administrator. El uso de un sud

Cómo instalar osTicket en FreeBSD 12

Cómo instalar osTicket en FreeBSD 12

¿Usando un sistema diferente? osTicket es un sistema de tickets de soporte al cliente de código abierto. El código fuente de osTicket está alojado públicamente en Github. En este tutorial

How to Install Osclass on FreeBSD 12

How to Install Osclass on FreeBSD 12

Using a Different System? Osclass is an open source project that allows you to easily create a classified site without any technical knowledge. Its sourc

How to Install Wiki.js on FreeBSD 11

How to Install Wiki.js on FreeBSD 11

Using a Different System? Wiki.js is a free and open source, modern wiki app built on Node.js, MongoDB, Git and Markdown. Wiki.js source code is publicl

How to Install Lychee 3.1 Photo Album on a FreeBSD 11 FAMP VPS

How to Install Lychee 3.1 Photo Album on a FreeBSD 11 FAMP VPS

Using a Different System? Lychee 3.1 Photo Album is a simple and flexible, free and open source photo-management tool which runs on a VPS server. It install

Installing Fork CMS on FreeBSD 12

Installing Fork CMS on FreeBSD 12

Using a Different System? Fork is an open source CMS written in PHP. Forks source code is hosted on GitHub. This guide will show you how to install Fork CM

Crear archivo de intercambio en FreeBSD 10

Crear archivo de intercambio en FreeBSD 10

Fuera de la caja, los servidores Vultr FreeBSD no están configurados para incluir espacio de intercambio. Si su intención es una instancia de nube desechable, probablemente no necesite

Cómo cambiar el tamaño de un disco en FreeBSD

Cómo cambiar el tamaño de un disco en FreeBSD

El sistema operativo FreeBSD utiliza UFS (Sistema de archivos Unix) para su sistema de archivos de particiones raíz; también conocido como freebsd-ufs en caso de una actualización

How to Install Selfoss RSS Reader on a FreeBSD 11 FAMP VPS

How to Install Selfoss RSS Reader on a FreeBSD 11 FAMP VPS

Using a Different System? Selfoss RSS Reader is a free and open source self-hosted web-based multipurpose, live stream, mashup, news feed (RSS/Atom) reade

How to Install Matomo Analytics on FreeBSD 11

How to Install Matomo Analytics on FreeBSD 11

Using a Different System? Matomo (formerly Piwik) is an open source analytics platform, an open alternative to Google Analytics. Matomo source is hosted o

How to Enable TLS 1.3 in Nginx on FreeBSD 12

How to Enable TLS 1.3 in Nginx on FreeBSD 12

Using a Different System? TLS 1.3 is a version of the Transport Layer Security (TLS) protocol that was published in 2018 as a proposed standard in RFC 8446

How to Install Craft CMS on FreeBSD 12

How to Install Craft CMS on FreeBSD 12

Using a Different System? Introduction Craft CMS is an open source CMS written in PHP. Craft CMS source code is hosted on GitHub. This guide will show yo

Cómo instalar Backdrop CMS en un FreeBSD 11 FAMP VPS

Cómo instalar Backdrop CMS en un FreeBSD 11 FAMP VPS

¿Usando un sistema diferente? Backdrop CMS 1.8.0 es un sistema de administración de contenido (CMS) simple y flexible, amigable para dispositivos móviles, gratuito y de código abierto que nos permite

Cómo instalar ImpressPages CMS 5.0 en un FreeBSD 11 FAMP VPS

Cómo instalar ImpressPages CMS 5.0 en un FreeBSD 11 FAMP VPS

¿Usando un sistema diferente? ImpressPages CMS 5.0 es un sistema de gestión de contenido (CMS) simple y efectivo, gratuito y de código abierto, fácil de usar y basado en MVC

How to Install NodeBB forum on FreeBSD 12

How to Install NodeBB forum on FreeBSD 12

Using a Different System? NodeBB is a Node.js based forum software. It utilizes web sockets for instant interactions and real-time notifications. The NodeB

Install eSpeak on FreeBSD 12

Install eSpeak on FreeBSD 12

Using a Different System? ESpeak can generate text-to-speech (TTS) audio files. These can be useful for many reasons, such as creating your own Turin

Instalar TaskServer (taskd) en FreeBSD 11

Instalar TaskServer (taskd) en FreeBSD 11

¿Usando un sistema diferente? TaskWarrior es una herramienta de gestión de tiempo de código abierto que es una mejora en la aplicación Todo.txt y sus clones. Debido a th

ZPanel y Sentora en CentOS 6 x64

ZPanel y Sentora en CentOS 6 x64

ZPanel, un panel de control de alojamiento web popular, se bifurcó en 2014 a un nuevo proyecto llamado Sentora. Aprende a instalar Sentora en tu servidor con este tutorial.

Cómo instalar Vtiger CRM Open Source Edition en CentOS 7

Cómo instalar Vtiger CRM Open Source Edition en CentOS 7

Aprende cómo instalar Vtiger CRM, una aplicación de gestión de relaciones con el cliente, en CentOS 7 para aumentar tus ventas y mejorar el servicio al cliente.

Cómo instalar el servidor Counter-Strike 1.6 en Linux

Cómo instalar el servidor Counter-Strike 1.6 en Linux

Esta guía completa le mostrará cómo configurar un servidor Counter-Strike 1.6 en Linux, optimizando el rendimiento y la seguridad para el mejor juego. Aprende los pasos más recientes aquí.

¿Puede la IA luchar con un número cada vez mayor de ataques de ransomware?

¿Puede la IA luchar con un número cada vez mayor de ataques de ransomware?

Los ataques de ransomware van en aumento, pero ¿puede la IA ayudar a lidiar con el último virus informático? ¿Es la IA la respuesta? Lea aquí, sepa que la IA es una bendición o una perdición

ReactOS: ¿Es este el futuro de Windows?

ReactOS: ¿Es este el futuro de Windows?

ReactOS, un sistema operativo de código abierto y gratuito, está aquí con la última versión. ¿Puede satisfacer las necesidades de los usuarios de Windows de hoy en día y acabar con Microsoft? Averigüemos más sobre este estilo antiguo, pero una experiencia de sistema operativo más nueva.

Manténgase conectado a través de la aplicación de escritorio WhatsApp 24 * 7

Manténgase conectado a través de la aplicación de escritorio WhatsApp 24 * 7

Whatsapp finalmente lanzó la aplicación de escritorio para usuarios de Mac y Windows. Ahora puede acceder a Whatsapp desde Windows o Mac fácilmente. Disponible para Windows 8+ y Mac OS 10.9+

¿Cómo puede la IA llevar la automatización de procesos al siguiente nivel?

¿Cómo puede la IA llevar la automatización de procesos al siguiente nivel?

Lea esto para saber cómo la Inteligencia Artificial se está volviendo popular entre las empresas de pequeña escala y cómo está aumentando las probabilidades de hacerlas crecer y dar ventaja a sus competidores.

La actualización complementaria de macOS Catalina 10.15.4 está causando más problemas que resolver

La actualización complementaria de macOS Catalina 10.15.4 está causando más problemas que resolver

Recientemente, Apple lanzó macOS Catalina 10.15.4, una actualización complementaria para solucionar problemas, pero parece que la actualización está causando más problemas que conducen al bloqueo de las máquinas Mac. Lee este artículo para obtener más información

13 Herramientas comerciales de extracción de datos de Big Data

13 Herramientas comerciales de extracción de datos de Big Data

13 Herramientas comerciales de extracción de datos de Big Data

¿Qué es un sistema de archivos de diario y cómo funciona?

¿Qué es un sistema de archivos de diario y cómo funciona?

Nuestra computadora almacena todos los datos de una manera organizada conocida como sistema de archivos de diario. Es un método eficiente que permite a la computadora buscar y mostrar archivos tan pronto como presiona buscar.