Drupal: Difference between revisions
Created a simple set of configuration for the NixOS Drupal service. |
m Replace backticks with <code> blocks |
||
| Line 21: | Line 21: | ||
=== Configuration Using settings.php === | === Configuration Using settings.php === | ||
Drupal uses a file called settings.php to configure the application at a general level. If you use the NixOS-provided Drupal package instead of a custom package, you may want to change some of these settings. | Drupal uses a file called <code>settings.php</code> to configure the application at a general level. If you use the NixOS-provided Drupal package instead of a custom package, you may want to change some of these settings. | ||
You can do this by writing pure PHP into the | You can do this by writing pure PHP into the <code>services.drupal.sites.<name>.extraSettings</code> key<syntaxhighlight lang="nix"> | ||
services.drupal = { | services.drupal = { | ||
enable = true; | enable = true; | ||
| Line 49: | Line 49: | ||
==== How To Access Files In The State Directory As A Regular User ==== | ==== How To Access Files In The State Directory As A Regular User ==== | ||
At install time, a small set of user-editable files get copied to | At install time, a small set of user-editable files get copied to <code>/var/lib/drupal/<sitname></code> and are free to be changed by system users so long as they have been added to the webserver group. If the user has not been added to the webserver group, they will be denied access to any resources. | ||
The group name you must use depends on your currently configured webserver settings. Once you make your changes, you must log in and back out again, or change your current group using | The group name you must use depends on your currently configured webserver settings. Once you make your changes, you must log in and back out again, or change your current group using <code>newgrp</code>. | ||
===== For Nginx ===== | ===== For Nginx ===== | ||
| Line 64: | Line 64: | ||
=== Database Configuration === | === Database Configuration === | ||
The NixOS implementation of Drupal uses MySQL as the primary database, however you can [https://www.drupal.org/docs/7/creating-custom-modules/howtos/how-to-connect-to-multiple-databases-within-drupal#s-drupal-8 add other databases using settings.php]. Refer to the '''Configuration Using settings.php''' section above for instructions on how to add extra settings to settings.php. | The NixOS implementation of Drupal uses MySQL as the primary database, however you can [https://www.drupal.org/docs/7/creating-custom-modules/howtos/how-to-connect-to-multiple-databases-within-drupal#s-drupal-8 add other databases using settings.php]. Refer to the '''Configuration Using settings.php''' section above for instructions on how to add extra settings to <code>settings.php</code>. | ||
Using nix, you can configure the database that gets created in NixOS at install time by using this configuration interface:<syntaxhighlight lang="nix"> | Using nix, you can configure the database that gets created in NixOS at install time by using this configuration interface:<syntaxhighlight lang="nix"> | ||
| Line 88: | Line 88: | ||
== State Directory == | == State Directory == | ||
The state directory is a small set of user-editable files that gets installed into | The state directory is a small set of user-editable files that gets installed into <code>/var/lib/drupal/<sitename></code> when the Drupal service is first activated. It contains a truncated Drupal file tree where system users can upload and manage certain files that affect the state of the web application. | ||
This is the file structure you can find at a typical installation<syntaxhighlight lang="bash"> | This is the file structure you can find at a typical installation<syntaxhighlight lang="bash"> | ||
| Line 94: | Line 94: | ||
config modules private sites themes | config modules private sites themes | ||
</syntaxhighlight>Files in this directory, because of their tendency to change during run time, cannot live inside of | </syntaxhighlight>Files in this directory, because of their tendency to change during run time, cannot live inside of <code>/nix/store</code>, so they are placed here instead. | ||
The webserver is the default owner of all files in the state directory and regular users are not permitted to access this directory by default. However, users who belong to the webserver group may edit or upload files as needed. Refer to "'''How To Access Files In The State Directory As A Regular User"''' for more information on how to add users to the webserver group. | The webserver is the default owner of all files in the state directory and regular users are not permitted to access this directory by default. However, users who belong to the webserver group may edit or upload files as needed. Refer to "'''How To Access Files In The State Directory As A Regular User"''' for more information on how to add users to the webserver group. | ||
=== Uploading Modules and Themes === | === Uploading Modules and Themes === | ||
The | The <code>modules</code> and <code>themes</code> directories of the state directory are symlinked directly to the Drupal installation in the nix store. Users can upload both [https://www.drupal.org/docs/user_guide/en/extend-manual-install.html modules and themes] to these directories and Drupal will detect them. | ||
This is not the officially [https://www.drupal.org/docs/extending-drupal/installing-modules recommended method] for installing contributed modules and themes, or modules and themes that have third-party dependencies. However, this functionality has been preserved both as an escape hatch, and to provide an easy way to manage a simple Drupal install that doesn't rely on [https://getcomposer.org/ composer]. | This is not the officially [https://www.drupal.org/docs/extending-drupal/installing-modules recommended method] for installing contributed modules and themes, or modules and themes that have third-party dependencies. However, this functionality has been preserved both as an escape hatch, and to provide an easy way to manage a simple Drupal install that doesn't rely on [https://getcomposer.org/ composer]. | ||
Revision as of 02:37, 26 January 2026
Drupal is a self-hosted content management system with an eye towards enterprise usage, custom development, internationalization, accessibility, and open source software. It has a large ecosystem of user-contributed plugins and themes that can be used to extend its capabilities, the vast majority of of which are free to use and do not feature any standing subscription costs.
Installation
A simple installation can be implemented with the following setup
services.drupal.enable = true;
This will spin up a simple Drupal installation at http://localhost using nginx and MYSQL. This configuration is functionally identical to writing:
services.drupal = {
enable = true;
sites = {
"localhost" = {
enable = true;
};
};
};
Configuration
Configuration Using settings.php
Drupal uses a file called settings.php to configure the application at a general level. If you use the NixOS-provided Drupal package instead of a custom package, you may want to change some of these settings.
You can do this by writing pure PHP into the services.drupal.sites.<name>.extraSettings key
services.drupal = {
enable = true;
sites = {
"localhost" = {
enable = true;
extraConfig = ''
// These settings will be printed as pure PHP into a file visible to settings.php.
// These settings will be appended to, and thus override, any existing settings
// at the same namespace.
$config['user.settings']['anonymous'] = 'Visitor';
$settings['entity_update_backup'] = TRUE;
'';
};
};
};
Webserver Configuration
You can use either nginx or caddy as the webserver, but only one may be used at a time. All Drupal installations on NixOS will use the same configured webserver, though configuration may be customized for each installation.
Nginx is the default webserver, though you can use caddy by writing this configuration
services.drupal.webserver = "caddy";
How To Access Files In The State Directory As A Regular User
At install time, a small set of user-editable files get copied to /var/lib/drupal/<sitname> and are free to be changed by system users so long as they have been added to the webserver group. If the user has not been added to the webserver group, they will be denied access to any resources.
The group name you must use depends on your currently configured webserver settings. Once you make your changes, you must log in and back out again, or change your current group using newgrp.
For Nginx
users.users.<user>.extraGroups = ["nginx"];
For Caddy
users.users.<user>.extraGroups = ["caddy"];
Database Configuration
The NixOS implementation of Drupal uses MySQL as the primary database, however you can add other databases using settings.php. Refer to the Configuration Using settings.php section above for instructions on how to add extra settings to settings.php.
Using nix, you can configure the database that gets created in NixOS at install time by using this configuration interface:
services.drupal = {
enable = true;
sites = {
"localhost" = {
enable = true;
database = {
user = "database_user"; # Default is "drupal"
tablePrefix = "tblprfx_"; # Not set by default
socket = /path/to/mysqld/mysqld.sock; # Default is /run/mysqld/mysqld.sock
port = 3306; # Default is 3306
passwordFile = /path/to/password/file; # Not set by default
name = "database_name"; # Default is "drupal"
host = "database.host.local"; # Default is localhost
createLocally = true; # Set to false if you want to use a remote DB
};
};
};
};
State Directory
The state directory is a small set of user-editable files that gets installed into /var/lib/drupal/<sitename> when the Drupal service is first activated. It contains a truncated Drupal file tree where system users can upload and manage certain files that affect the state of the web application.
This is the file structure you can find at a typical installation
$ ls
config modules private sites themes
Files in this directory, because of their tendency to change during run time, cannot live inside of /nix/store, so they are placed here instead.
The webserver is the default owner of all files in the state directory and regular users are not permitted to access this directory by default. However, users who belong to the webserver group may edit or upload files as needed. Refer to "How To Access Files In The State Directory As A Regular User" for more information on how to add users to the webserver group.
Uploading Modules and Themes
The modules and themes directories of the state directory are symlinked directly to the Drupal installation in the nix store. Users can upload both modules and themes to these directories and Drupal will detect them.
This is not the officially recommended method for installing contributed modules and themes, or modules and themes that have third-party dependencies. However, this functionality has been preserved both as an escape hatch, and to provide an easy way to manage a simple Drupal install that doesn't rely on composer.