Drupal 10
Use this git repo as a reference implementation.
The above repo contains a .sb.yml
file which is a specification of the entire app’s configuration. Check .sb.yml file for more information.
Preparing your code
You have to make the following changes to your code base:
PHP extensions to load
Create a folder in your top level directory called .php.ini.d
. Create a file with the name drupal.ini
with the following contents.
This configures the PHP extensions to be loaded in your application. The filename doesn’t matter, as long as it ends with .ini
.
The PHP buildpack loads only the extensions you want for performance reasons. So, you will have to create this file for any PHP app you deploy.
Here’s a reference implementation of the same: https://github.com/shapeblock/drupal-10/blob/main/.php.ini.d/drupal.ini.
Nginx configuration
All PHP buildpacks run PHP FPM served by Nginx. Drupal needs custom nginx configuration. Create a folder at the top level called .nginx.conf.d
and create a file with the following contents:
This is standard nginx configuration for running Drupal 8+. The clean URLs feature won’t work without this configuration. The filename doesn’t matter as long as it ends with .conf
.
Here’s a reference implementation. https://github.com/shapeblock/drupal-10/blob/main/.nginx.conf.d/drupal-server.conf
Update settings.php
Update Drupal’s settings.php
file by adding a custom settings.php which will pull database credentials from environment files.
Please add this in the end before your local setup settings(if any). Reference implementation: https://github.com/shapeblock/drupal-10/blob/main/web/sites/default/settings.php
Next, we have to add the settings.shapeblock.php
file in the same folder.
The name of the file is arbitrary. It can even be settings.prod.php
.
Reference: https://github.com/shapeblock/drupal-10/blob/main/web/sites/default/settings.shapeblock.php
Permissions
The Drupal installer rewrites settings.php
file during installation, even when we provide one. For this, we need to provide explicit write access to settings.php
.
The default container runtime in ShapeBlock is a readonly filesystem for security reasons. We have to provide explicit access to the settings.php
file.
For this, we have to create a chmod.sh
and give a list of file(s) and what permissions to give. In this case, the file will look like this:
MySQL client (optional)
If we want to run drush
, some drush commands require the mysql-client package to be installed in the container. This is not installed by default.
We have to create a new file in the top level directory called Aptfile
and add the apt package name there.
Reference: https://github.com/shapeblock/drupal-10/blob/main/Aptfile
If your application needs any other packages, it can be added to this file.
Services
Drupal needs a MySQL database to store the content generated by users. You have to create a service og type “MySQL” and attach it to the app before deploying it.
Build variables
You have to specify the docroot of your drupal installation using the BP_PHP_WEB_DIR
variable. For the above repo, it will be web
.
For any PHP app, the default docroot is the top level directory of your code. If you want this to be something else, you have to set the BP_PHP_WEB_DIR
relative to the directory structure of your code base.
Variable Name | Value | Notes |
---|---|---|
BP_PHP_SERVER | nginx | Indicates what web server we will be using. |
BP_RUN_COMPOSER_INSTALL | 1 | A Drupal specific build variable which tells not to wipe out composer installed packages in the code base, i.e. the contrib modules and themes. Not needed for other PHP frameworks. |
BP_PHP_ENABLE_CACHE_CONTROL | false | Disable nginx cache control, which messes with Nginx serving aggregated and compressed Drupal static files. |
BP_PHP_VERSION | Latest version of PHP | Optional. Supports 8.1 and 8.2 |
Runtime variables
When you attach a service, it creates environment variables which contain service information and credentials.
Please ensure that the variable name matches the ones given in settings.php
. You can change either the variable names here or in the settings.php
file accordingly.
These should look something like this:
Variable Name | Value | Notes |
---|---|---|
DB_HOST | <service name>-mysql | Hostname of the mysql service which is attached. |
DB_NAME | shapeblock | Name of the database |
DB_USER | shapeblock | Name of the DB user who has access to the above database. |
DB_PASSWORD | shapeblock | Password for the DB user above |
Drupal also needs a HASH_SALT
secret to be provided.
Variable Name | Value | Notes |
---|---|---|
HASH_SALT | <some generated secret string> |
All secrets are readonly. Once created, they cannot be edited. You have to delete and recreate them.
Volumes
Drupal needs persistent storage to store user uploaded files. For this, we need to create a new volume mount.
Mount Name | Mount path | Size | Notes |
---|---|---|---|
public-files | /workspace/web/sites/default/files | 2GiB | The name of the mount is arbitrary and for your reference only. |
The mount path is the path you want to persist. This is an absolute path. All apps in ShapeBlock are deployed in the /workspace
directory of the container. In our Drupal app, the public files directory will be /workspace/web/sites/default/files
.
You can optionally create another mount for storing Drupal’s private files.
Once the app is deployed successfully, you should be able to view the Drupal site.