oliverdavies.uk/source/_daily_emails/2024-12-09.md

103 lines
2.2 KiB
Markdown
Raw Permalink Normal View History

---
title: Running Drupal on devenv
date: 2024-12-09
permalink: daily/2024/12/09/drupal-devenv
tags:
- software-development
- drupal
- php
- nix
- devenv
cta: ~
snippet: |
Here's an example of how I'm running Drupal applications locally with Nix and devenv.
---
I recently said that [I've been using devenv to run Drupal applications locally][0].
Here's the `devenv.nix` file I used for [my recent talk for the Drupal London meetup][1]:
```nix
{ pkgs, ... }:
let
drupal.root = "web";
in
{
packages = [ pkgs.git ];
dotenv.disableHint = true;
languages = {
php = {
enable = true;
version = "8.2";
ini = ''
memory_limit = 256M
'';
fpm.pools.web = {
listen = "127.0.0.1:9000";
settings = {
"pm" = "dynamic";
"pm.max_children" = 75;
"pm.max_requests" = 500;
"pm.max_spare_servers" = 20;
"pm.min_spare_servers" = 5;
"pm.start_servers" = 10;
};
};
};
};
processes = { };
services = {
caddy = {
enable = true;
config = ''
{
http_port 8080
}
localhost:8080 {
root * ${drupal.root}
encode gzip
php_fastcgi localhost:9000
file_server
}
'';
};
mysql = {
enable = true;
initialDatabases = [ { name = "drupal_london"; } ];
};
};
enterShell = ''
if [[ ! -d vendor ]]; then
composer install
fi
'';
enterTest = ''
phpunit --testdox
'';
}
```
It installs the required version of PHP for this project, creates a web server (Caddy) and configures MariaDB with a default database.
I've also added commands to run `composer install` to download dependencies when entering the shell and `phpunit` for tests.
With this approach, there's no need for containers as everything is run locally and I can view the site at <http://localhost:8080> (or whatever port is defined).
All of my current development projects are using this approach and I think it'll be my default method for future projects.
[0]: {{site.url}}/daily/2024/11/30/using-nix-for-local-application-development
[1]: {{site.url}}/presentations/tdd-test-driven-drupal