From b02ff3c5b089a6992bb3a65f6ac595c11693065f Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 12 Dec 2024 17:19:09 +0000 Subject: [PATCH] Add daily email for 2024-12-09 Running Drupal on devenv --- run.local | 2 + source/_daily_emails/2024-12-09.md | 102 +++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 source/_daily_emails/2024-12-09.md diff --git a/run.local b/run.local index edc8da00..ab01f954 100755 --- a/run.local +++ b/run.local @@ -71,6 +71,8 @@ function npm:build:css { args=(--watch) fi + cd assets || exit + tailwindcss \ --config tailwind.config.ts \ --input css/tailwind.css \ diff --git a/source/_daily_emails/2024-12-09.md b/source/_daily_emails/2024-12-09.md new file mode 100644 index 00000000..fb914225 --- /dev/null +++ b/source/_daily_emails/2024-12-09.md @@ -0,0 +1,102 @@ +--- +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 (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