Grav CMS on OpenBSD: Install in a subdirectory

( modified )



Installing in a subdirectory here means a website is accessed as http(s)://<root-dir>/<TARGET> instead of http(s)://<TARGET>. All what to do in order to install Grav CMS in a subdirectory on OpenBSD is to configure two files: Grav’s user/config/system.yaml and OpenBSD’s /etc/httpd.conf.


Assumed that: Grav CMS has been already installed in <root-dir (as a subdirectory)>/<grav-dir>.

Here is an example about how to install it.

Grav’s user/config/system.yaml

Go to <grav-dir>. Edit user/config/system.yaml:

$ nvim user/config/system.yaml

to add custom_base_url whose default value is blank:

+ custom_base_url: '/<root-dir>'

Besides, according to the official Grav Configuration, “you should never change” system/config/system.yaml.

OpenBSD’s /etc/httpd.conf

Edit httpd.conf:

$ doas nvim /etc/httpd.conf

to modify location definition:

  server "<fqdn>" {
-     root "/(...)/<grav-directory>"
+     root "/(...)/<root-dir>" # (optional, up to env)
-     location "*" {
+     location "/<grav-directory>/*" {
-         root "/(...)/<grav-directory>/index.php"
+         root "/(...)/<root-dir>/<grav-directory>/index.php"
          fastcgi socket "/run/php-fpm.sock"

Then restart the server:

$ doas rcctl restart httpd


You will perhaps see the Grav site running in a subdirectory :)

installed in a subdirectory


Grav CMS
  1. Grav CMS on OpenBSD 6.9: Install via Composer
  2. Grav CMS on OpenBSD: Install in a subdirectory

Comments or feedbacks are welcomed and appreciated.