Grav CMS on OpenBSD: Install in a subdirectory

Table of contents

Summary Summary

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 (opens in a new tab) CMS in a subdirectory on OpenBSD (opens in a new tab) is to configure two files: Grav’s user/config/system.yaml and OpenBSD’s /etc/httpd.conf.

Tutorial Tutorial

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 Grav&rsquo;s user/config/system.yaml

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

console
$ nvim user/config/system.yaml

to add custom_base_url whose default value is blank:

diff
+ custom_base_url: '/<root-dir>'

Besides, according to the official Grav Configuration (opens in a new tab), “you should never change” system/config/system.yaml.

OpenBSD’s /etc/httpd.conf OpenBSD&rsquo;s /etc/httpd.conf

Edit httpd.conf (opens in a new tab):

console
$ doas nvim /etc/httpd.conf

to modify location definition:

diff
  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:

console
$ doas rcctl restart httpd

Conclusion Conclusion

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

installed in a subdirectory

More on: Run PHP applications

OBSD Solutions

OBSD Solutions: OpenBSD consulting and support by Scqr, Reflerd Inc. (opens in a new tab)

Comments and feedback are welcome.