Ubuntu Linux 24.04 LTS (Noble Numbat) - From Zero to Drupal 11 Setup
2025-05-01
廣告
This guide walks you through the process of setting up a production-ready Drupal 11 site on a clean Ubuntu 24.04 LTS system. It includes installing Nginx, PHP 8.3 FPM, MySQL, SSL with Certbot, and optimizing your environment.
Step 1: Initial Setup
sudo apt update && sudo apt upgrade -y
sudo apt install nginx php8.3-fpm php8.3-cli php8.3-mysql php8.3-gd php8.3-xml php8.3-mbstring php8.3-curl php8.3-zip unzip curl git mysql-server -y
Step 2: Enable and Configure UFW Firewall
sudo ufw allow 'OpenSSH'
sudo ufw allow 'Nginx Full'
sudo ufw enable
(Optional) Limit SSH (port 22) to specific IP addresses:
sudo ufw allow from YOUR.IP.ADDRESS to any port 22
Step 3: Set Up Nginx Server Block
sudo nano /etc/nginx/sites-available/drupal
Sample Nginx config:
server {
listen 80;
server_name example.com;
root /var/www/drupal/web;
index index.php index.html;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}
}
Enable the site:
sudo ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
Step 4: Enable SSL with Certbot
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx
Test auto-renewal:
sudo certbot renew --dry-run
Step 5: Configure PHP Opcache (Performance)
sudo nano /etc/php/8.3/fpm/php.ini
Ensure the following settings:
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2
opcache.validate_timestamps=1
Restart PHP FPM:
sudo systemctl restart php8.3-fpm
Step 6: Composer & Drupal Installation
cd /var/www/
sudo mkdir drupal && sudo chown $USER:www-data drupal
cd drupal
composer create-project drupal/recommended-project .
After installation:
cd /var/www/drupal/
composer require drush/drush
composer update
Then run:
drush updatedb
drush cr
Step 7: Set Directory Permissions
sudo chown -R www-data:www-data /var/www/drupal
sudo find /var/www/drupal -type d -exec chmod 755 {} \;
sudo find /var/www/drupal -type f -exec chmod 644 {} \;
Notes
- The web root is
/var/www/drupal/web
- Manage Drupal using Drush inside
/var/www/drupal
- Keep Composer dependencies up-to-date regularly
- Consider adding Redis or Varnish for further optimization