On this page
- What does Drupal 11 need?
- How do you install PHP, the database and Composer?
- How do you create the database?
- How do you create the project and install Drupal with Drush?
- How do you set trusted hosts and Nginx?
- How do you enable HTTPS?
- How do you run cron and send mail?
- How do you update Drupal and recover from problems?
- Questions
What does Drupal 11 need?
Drupal 11 requires PHP 8.3 or newer, Composer 2, and MariaDB 10.6+, MySQL 8.0+, PostgreSQL 16+ or SQLite. Ubuntu 24.04 (PHP 8.3, MariaDB 10.11) and Debian 13 (PHP 8.4, MariaDB 11.8) cover everything with stock packages. On Rocky Linux 9 and AlmaLinux 9, MySQL 8.0 from AppStream meets the database requirement, and PHP needs an 8.3 module stream.
Plan for 2 GB of RAM: Composer resolving dependencies alone can use more than 1 GB. Work as a sudo user such as deploy and point example.net at the server (see DNS records). Composer-based projects keep the vendor code outside the public folder, which is safer than the old tarball layout and makes updates repeatable.
How do you install PHP, the database and Composer?
Ubuntu 24.04 and Debian 13
sudo apt update
sudo apt install -y nginx mariadb-server php-fpm php-cli php-mysql php-gd php-xml php-mbstring php-curl php-zip php-opcache php-apcu unzip git
php -vRocky Linux 9 and AlmaLinux 9
sudo dnf module list php
sudo dnf module reset -y php
sudo dnf module enable -y php:8.3
sudo dnf install -y nginx mysql-server php-fpm php-cli php-mysqlnd php-gd php-xml php-mbstring php-pecl-zip php-opcache unzip git
sudo systemctl enable --now nginx mysqld php-fpmThen install Composer with the official installer, as described in the Composer guide:
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer --versionHow do you create the database?
Create an empty database and a user; Drush fills in the tables later.
sudo mariadb -e "CREATE DATABASE drupal CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
sudo mariadb -e "CREATE USER 'drupal'@'localhost' IDENTIFIED BY 'drupal-db-secret';"
sudo mariadb -e "GRANT ALL ON drupal.* TO 'drupal'@'localhost';"On Rocky and Alma with MySQL, run the same statements through sudo mysql -e after sudo mysql_secure_installation. Keep the password free of @ and : characters, since it goes into a database URL in the next step.
How do you create the project and install Drupal with Drush?
Create the codebase as your own user, add Drush as a project dependency and run the installer.
sudo mkdir -p /var/www/drupal
sudo chown deploy:deploy /var/www/drupal
cd /var/www/drupal
composer create-project drupal/recommended-project .
composer require drush/drush
vendor/bin/drush --version
vendor/bin/drush site:install standard --db-url=mysql://drupal:drupal-db-secret@localhost/drupal --site-name="Example Site" --account-name=siteadmin --account-pass=Long-admin-pass-2026 --account-mail=owner@example.net -yThe project root holds composer.json, vendor and the web folder; only web is public. Give the web server write access to the uploaded files folder and lock the settings file:
sudo chown -R deploy:www-data web/sites/default/files
sudo chmod -R 2775 web/sites/default/files
chmod 444 web/sites/default/settings.phpUse group nginx on Rocky and Alma. On those systems with SELinux enforcing, also run sudo chcon -R -t httpd_sys_rw_content_t web/sites/default/files.
How do you set trusted hosts and Nginx?
Drupal rejects requests for unknown host names once trusted_host_patterns is set, which blocks host header attacks. Append it to web/sites/default/settings.php (make the file writable briefly):
$settings['trusted_host_patterns'] = [
'^example\.net$',
'^www\.example\.net$',
];Then point Nginx at the web folder:
server {
listen 80;
listen [::]:80;
server_name example.net www.example.net;
root /var/www/drupal/web;
index index.php;
client_max_body_size 64m;
location ~ \..*/.*\.php$ { return 403; }
location ~ ^/sites/.*/private/ { return 403; }
location ~ ^/sites/[^/]+/files/.*\.php$ { deny all; }
location ~ (^|/)\. { return 403; }
location / { try_files $uri /index.php?$query_string; }
location @rewrite { rewrite ^ /index.php; }
location ~ /vendor/.*\.php$ { deny all; return 404; }
location ~ ^/sites/.*/files/styles/ { try_files $uri @rewrite; }
location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|webp|woff2)$ { try_files $uri @rewrite; expires max; log_not_found off; }
}The styles rule lets Drupal generate image derivatives on first request. Change the socket to your PHP version (/run/php-fpm/www.sock on Rocky and Alma), then run sudo nginx -t and reload.
How do you enable HTTPS?
Allow ports 80 and 443 and issue a certificate as shown in the Certbot and Let's Encrypt guide.
sudo ufw allow 'Nginx Full'
sudo certbot --nginx -d example.net -d www.example.net --redirect
curl -sI https://example.net/user/login | head -n 1On Rocky and Alma open the services with firewall-cmd and reload. A 200 on the login page proves Nginx, PHP and the database work together. Check the status report at /admin/reports/status afterwards; it lists anything Drupal considers misconfigured.
How do you run cron and send mail?
Drupal clears caches, indexes search and checks for updates during cron. Turn off the built-in automated cron module and call Drush from a system job instead:
vendor/bin/drush pm:uninstall automated_cron -y
crontab -e
*/15 * * * * cd /var/www/drupal && vendor/bin/drush cron --quietRun it under the deploy account that owns the code. For outgoing mail install the Symfony Mailer module with Composer and configure an SMTP transport on port 587 with authentication; SMTP relay for apps explains the relay side. Port 25 may not be open, so ask support through a ticket before relying on direct delivery.
How do you update Drupal and recover from problems?
Update core and modules with Composer, apply database changes with Drush and rebuild caches.
cd /var/www/drupal
vendor/bin/drush sql:dump --gzip --result-file=../backup-$(date +%F).sql
composer outdated "drupal/*"
composer update "drupal/core-*" --with-all-dependencies
vendor/bin/drush updatedb -y
vendor/bin/drush cache:rebuild
vendor/bin/drush statusCommit composer.json and composer.lock to Git so every server builds the same code. If a page shows "The website encountered an unexpected error", read the log with vendor/bin/drush watchdog:show. Memory errors during composer update mean the server needs swap (see adding a swap file) or a larger plan.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Drupal with Composer and Drush
Why use Composer instead of the tarball?
Contributed modules and their libraries are managed by Composer, and core updates become a single repeatable command. Mixing tarball installs with Composer modules causes conflicts.
Should Drush be installed globally?
No. Current Drush versions are installed per project with composer require drush/drush and run as vendor/bin/drush.
How do I reset the admin password?
Run vendor/bin/drush user:login for a one-time login link, or vendor/bin/drush user:password siteadmin 'NewPass'.
Why does the site say the host is not trusted?
The requested host name does not match trusted_host_patterns. Add the name, escaping each dot with a backslash.
How much RAM does Drupal need?
2 GB is a practical minimum because Composer is memory hungry; larger sites with many modules benefit from 4 GB.
More in Websites, CMS and shops
- WordPress on Nginx, PHP-FPM, MariaDB
- Fix common WordPress errors
- Back up WordPress (3-2-1 rule)
- WordPress caching with Redis
- WooCommerce shop setup
- Ghost publishing platform
- Moodle learning platform
- phpBB forum
- Flarum forum
- Discourse community forum
- MediaWiki on Nginx and MariaDB
- Magento Open Source with OpenSearch
- PrestaShop store on Nginx
- OpenCart shop on Nginx
- Matomo web analytics
- Static site with Nginx and rsync
- Joomla on Nginx and PHP-FPM
- Vanilla Forums open source