Skip to content

Installing Drupal 10 with Composer on Ubuntu

Operator-grade walkthrough for installing Drupal 10 on Ubuntu 22.04 using Composer, PHP-FPM, Nginx, and MariaDB — with TLS, file permissions, and trusted host config.

You inherited a Drupal site that was unpacked from a tarball into /var/www/html, has no Composer lock file, and shows “Update notifications” telling you twelve modules are behind. This article installs Drupal 10 the way operators run it: every dependency under Composer’s control, PHP-FPM as the application server, Nginx in front, MariaDB on the same host (or a private network), and a clear path from composer install to drush updb. We focus on the boring details — file ownership, trusted hosts, sites/default permissions — that determine whether the next maintenance release goes smoothly or breaks login.

How to verify

Once the installation is complete, the following should hold on the host:

sudo -u www-data php -d memory_limit=512M /var/www/drupal/vendor/bin/drush status
# Drupal version    : 10.x.x
# DB driver         : mysql
# DB hostname       : 127.0.0.1
# Default theme     : olivero
# Site URI          : https://example.org

curl -sI https://example.org/ | head -1
# HTTP/2 200

sudo -u www-data find /var/www/drupal/web/sites/default -maxdepth 1 -type f -printf '%m %p\n'
# 444 /var/www/drupal/web/sites/default/settings.php
# 444 /var/www/drupal/web/sites/default/services.yml

ss -lntp | grep -E ':(80|443|3306)\b'
# 0.0.0.0:80   nginx
# 0.0.0.0:443  nginx
# 127.0.0.1:3306 mariadbd     (NOT 0.0.0.0)

If MariaDB binds on 0.0.0.0:3306, fix bind-address = 127.0.0.1 in /etc/mysql/mariadb.conf.d/50-server.cnf before continuing.

What’s happening

Drupal 10 requires PHP 8.1 or newer, Composer 2.x, and a real database — SQLite is fine for tinkering, not production. Composer is not optional in modern Drupal: contrib modules, patches, and core itself all install through composer require, and the lock file is the only audit trail you have for what’s actually deployed. The recommended project template (drupal/recommended-project) puts the public webroot under web/ and keeps vendor/, composer.json, and drush outside the document root — so leaked stack traces cannot expose your dependency tree.

Nginx serves static files directly and forwards .php to PHP-FPM over a Unix socket. PHP-FPM runs as the www-data user; the codebase belongs to a deploy user (we’ll use deployer) with group www-data and g+r everywhere, plus g+w on the writable directories (sites/default/files, the Composer cache, and the translation cache). Two settings that get forgotten in every Drupal install: $settings['trusted_host_patterns'] (otherwise the site refuses requests with unknown Host headers, by design) and $settings['file_private_path'] (otherwise private files have no place to land).

The procedure

  1. Install PHP 8.2, Nginx, MariaDB, and the extensions Drupal needs.

    sudo apt update
    sudo apt install -y nginx mariadb-server \
      php8.2-fpm php8.2-mysql php8.2-gd php8.2-curl \
      php8.2-mbstring php8.2-xml php8.2-zip php8.2-intl \
      php8.2-bcmath php8.2-opcache php8.2-apcu \
      composer git unzip
  2. Create the database and a user with a long random password.

    DBPASS=$(openssl rand -hex 24)
    sudo mariadb <<SQL
    CREATE DATABASE drupal CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    CREATE USER 'drupal'@'127.0.0.1' IDENTIFIED BY '${DBPASS}';
    GRANT ALL ON drupal.* TO 'drupal'@'127.0.0.1';
    FLUSH PRIVILEGES;
    SQL
    echo "$DBPASS" | sudo tee /root/.drupal-dbpass >/dev/null
    sudo chmod 600 /root/.drupal-dbpass
  3. Create the project tree with Composer. Run as deployer, not root.

    sudo useradd -m -s /bin/bash deployer
    sudo usermod -aG www-data deployer
    sudo mkdir -p /var/www/drupal && sudo chown deployer:www-data /var/www/drupal
    sudo -u deployer -- bash -lc '
      cd /var/www/drupal
      composer create-project drupal/recommended-project:^10 .
      composer require drush/drush:^12 drupal/admin_toolbar drupal/pathauto
    '
  4. Run the installer non-interactively.

    cd /var/www/drupal
    sudo -u deployer ./vendor/bin/drush site:install standard \
      --db-url="mysql://drupal:${DBPASS}@127.0.0.1/drupal" \
      --account-name=admin \
      --account-pass="$(openssl rand -hex 12)" \
      --site-name='Example' \
      --yes
  5. Lock down settings.php and add trusted hosts. Append to web/sites/default/settings.php:

    $settings['trusted_host_patterns'] = ['^example\.org$', '^www\.example\.org$'];
    $settings['file_private_path'] = '/var/www/drupal/private';
    $settings['config_sync_directory'] = '/var/www/drupal/config/sync';

    Then:

    sudo mkdir -p /var/www/drupal/private /var/www/drupal/config/sync
    sudo chown -R deployer:www-data /var/www/drupal/private /var/www/drupal/config/sync
    sudo chmod 750 /var/www/drupal/private
    sudo chmod 444 /var/www/drupal/web/sites/default/settings.php
  6. Drop in the Nginx server block at /etc/nginx/sites-available/drupal:

    server {
      listen 443 ssl http2;
      server_name example.org www.example.org;
      root /var/www/drupal/web;
      index index.php;
      ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
      location / { try_files $uri /index.php?$query_string; }
      location ~ '\.php$|^/update.php' {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
      }
      location ~ /\.(?!well-known) { deny all; }
    }

    Issue the cert with certbot --nginx -d example.org -d www.example.org, then systemctl reload nginx.

  7. Wire up cron and OPcache. Drupal’s cron should run every 15 minutes from system cron (not the in-browser cron):

    echo '*/15 * * * * deployer cd /var/www/drupal && ./vendor/bin/drush cron --quiet' \
      | sudo tee /etc/cron.d/drupal

    Set opcache.revalidate_freq=60 and opcache.memory_consumption=256 in /etc/php/8.2/fpm/conf.d/10-opcache.ini, then systemctl reload php8.2-fpm.

Common pitfalls

  • The composer install --no-dev distinction matters in CI but not when you’re using Drush from vendor/bin — leave dev requirements in until you split the deploy pipeline.
  • Drupal refuses to render anything if the Host: header doesn’t match trusted_host_patterns — health checks that hit the IP will return 400 until you allow the load balancer’s probe hostname.
  • The sites/default directory has its mode reset to 755 on every config import; if you tightened it to 750, expect a warning in drush cim output.
  • APCu has to be enabled in CLI mode too (apc.enable_cli=1) for Drush’s container caches to work, otherwise every command rebuilds the bootstrap.
  • drush updb runs hook_update_N; drush cim imports config. Run them in that order after every composer update.

For clients running Drupal in production, Stack Harbor operates the full surface — Composer-pinned deploys, Drush-driven updates, OPcache tuning, MariaDB backups verified by restore — so the editorial team only sees the admin UI. That operating model is covered under managed operations, and you can keep reading about Drupal patterns in our knowledge base.