rset(1) : Formulas

Configuring WordPress

httpd

The following template can be used to configure wordpress as a FastCGI application

# Global Options
prefork 4

# Servers

server "default" {
  listen on "*" port 80
  log style combined
  root "/wordpress"
  directory index index.php

  # XML-RPC
  location "/wp-json/*" {
      fastcgi {
          param SCRIPT_FILENAME "wordpress/index.php"
          socket "/run/php-fpm.sock"
      }
  }

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

# Include MIME types instead of the built-in ones
types {
  nclude "/usr/share/misc/mime.types"
}

Similarly you can use SCRIPT_FILENAME to support other paths, for example

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

Then set up the chroot and restarting httpd if the server configuration changes.

execute_with=doas

httpd: wordpress/
   [ -f /var/www/etc/resolv.conf ] || {
       install -d -o www -g www /var/www/etc/
       install -m 644 -o www -g www /etc/resolv.conf /var/www/etc/
   }
   rcctl enable httpd
   ./rinstall wordpress/httpd.conf /etc/httpd.conf && rcctl restart httpd

PHP

Get the standard PHP configuration in place plus gd and mariadb

php_fpm:
   pkg_add mariadb-server mariadb-client php-mysqli%7.4 php-gd%7.4 php-zip%7.4
   ln -sf /usr/local/share/examples/php-7.4/php.ini-development /etc/php-7.4.ini
   ln -sf /usr/local/share/examples/php-7.4/mysqli.ini /etc/php-7.4/mysqli.ini
   ln -sf /usr/local/share/examples/php-7.4/gd.ini /etc/php-7.4/gd.ini
   ln -sf /usr/local/share/examples/php-7.4/zip.ini /etc/php-7.4/zip.ini
   cp /usr/local/share/examples/php-7.4/php-fpm.conf /etc/php-fpm.conf
   rcctl enable php74_fpm
   rcctl start php74_fpm

Database Initialization

Some frameworks provive extensive modules for managing the initialization of database roles and other features. This is not nessesary! Here is how one might simply initialize a new database with a new user

mysql:
   [ -d /var/mysql ] || /usr/local/bin/mysql_install_db
   rcctl enable mysqld
   rcctl start mysqld

   mysql <<-SQL
     CREATE DATABASE wordpress;
     CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'XXXXXXXX';
     GRANT ALL PRIVILEGES ON * . * TO 'wordpress'@'localhost';
     FLUSH PRIVILEGES;
   SQL

Install WordPress

Now untar the application!

wordpress:
   [ -f /var/www/wordpress/index.php ] || {
       mkdir -p /var/www/wordpress
       chown www:www /var/www/wordpress
       ./rinstall wordpress/latest.tar.gz latest.tar.gz
       tar -xzf latest.tar.gz -C /var/www
   }
   ./rinstall -o www wordpress/wp-config.php /var/www/wordpress/wp-config.php