DEV Community

nabbisen
nabbisen

Posted on • Updated on • Originally published at obsd.solutions

Grav CMS: Install in a subdirectory (on OpenBSD)

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

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

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

$ nvim user/config/system.yaml
Enter fullscreen mode Exit fullscreen mode

to add custom_base_url whose default value is blank:

+ custom_base_url: '/<root-dir>'
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
      }
      (...)
  }
Enter fullscreen mode Exit fullscreen mode

Then restart the server:

$ doas rcctl restart httpd
Enter fullscreen mode Exit fullscreen mode

Conclusion

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

installed in a subdirectory

Top comments (0)