We may earn a referral fee at no additional cost to you when you shop through the links on this page.
This comprehensive guide walks you through building a secure, production-ready LEMP stack on Ubuntu 24.04 LTS (Noble Numbat), a long-term support release supported until May 2029.
Using native repository packages, you’ll install Nginx 1.24, PHP 8.3, MariaDB 10.11, and secure the site with a free Let’s Encrypt SSL certificate. All optimized for Ubuntu’s latest LTS.
Step 1 – Install Nginx
The following steps cover installing the Nginx web server, configuring UFW firewall rules for web traffic, verifying the service, and setting up a server block for your domain.
Installing Nginx
Update the local package index to ensure the package manager has the latest information about available software versions, then install the nginx package:
sudo apt update && sudo apt install -y nginx
This installs Nginx 1.24 from the Ubuntu 24.04 (Noble Numbat) repositories. The server starts automatically after installation.
Adjusting the Firewall
Before testing Nginx, configure a firewall to allow external access to web ports while restricting other traffic. This guide uses UFW (Uncomplicated Firewall), which works identically on Ubuntu and Debian.
Allow Nginx through the firewall:
sudo ufw allow 'Nginx Full'
Verify the status:
sudo ufw status
You should see Nginx listed as well as OpenSSH if you’re using it.
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx Full ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
Verifying the Installation
Nginx starts automatically after installation. Confirm the service is active:
sudo systemctl status nginx
You should see active (running) in the output.
Test locally or from a remote machine:
hostname -I for your local IP, or curl -4 icanhazip.com for your public IP on a VPS. curl http://localhost
# or from remote:
curl http://your_server_ip
If you see HTML output in the response, the install was successful.
If you have access to a browser, you should see the default Nginx welcome page displaying ‘Welcome to nginx!’.
The default Nginx welcome page is located at /var/www/html/index.nginx-debian.html.
Managing the Nginx Service
Essential systemd commands for managing Nginx:
| Action | Command | Notes |
|---|---|---|
| Stop | sudo systemctl stop nginx | Halts the service completely |
| Start | sudo systemctl start nginx | Starts if stopped |
| Restart | sudo systemctl restart nginx | Full restart (brief downtime) |
| Reload | sudo systemctl reload nginx | Graceful reload (preferred for config changes) |
| Enable on boot | sudo systemctl enable nginx | Auto-start after reboot |
| Test config | sudo nginx -t | Validate config before reload |
sudo nginx -t before reloading. A config syntax error will prevent Nginx from starting, potentially taking your site offline. Important File Locations
Key paths to know for managing Nginx on Ubuntu 24.04 (Noble Numbat):
- Default Web Root:
/var/www/html— Your web content goes here. - Main Configuration:
/etc/nginx/nginx.conf— Global configuration file. - Server Blocks:
/etc/nginx/sites-available/— Per-site configurations. - Enabled Sites:
/etc/nginx/sites-enabled/— Symlinks to active configurations. - Access Log:
/var/log/nginx/access.log— All requests to your server. - Error Log:
/var/log/nginx/error.log— Errors and diagnostics.
Setting Up a Server Block
To serve content for your domain instead of the default page, configure a server block (Nginx’s equivalent of Apache’s virtual host).
/etc/hosts file on your client machine. Create a Directory for Your Site
sudo mkdir -p /var/www/example.com
Create a Sample Page
echo '<html><head><title>Success</title></head><body><h1>Success! The Server Block is working.</h1><p>You can now replace this file with your own content.</p><p>Return to <a href="https://devanswers.net/series/lemp-stack/">LEMP Stack Documentation</a></p></body></html>' | sudo tee /var/www/example.com/index.html
Set Permissions
Assign ownership to the web server user and configure group permissions:
sudo chown -R www-data:www-data /var/www/example.com
sudo chmod -R 775 /var/www/example.com
sudo chmod -R g+s /var/www/example.com
Add your user to the www-data group so you can modify files without sudo:
sudo usermod -aG www-data $USER
id. Create the Server Block Configuration
sudo nano /etc/nginx/sites-available/example.com
Paste the following configuration (replace example.com with your domain):
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
access_log /var/log/nginx/example.com-access.log;
error_log /var/log/nginx/example.com-error.log;
}
Save and exit (press CTRL + X, press Y, then press ENTER)
try_files directive tells Nginx to look for the exact URI first, then a directory, and return a 404 if neither exists. This prevents directory listing and handles clean URLs. Enable the Site and Reload Nginx
Create a symlink to enable your server block, remove the default site symlink, and reload Nginx:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t && sudo systemctl reload nginx
a2ensite or a2dissite commands. You manage sites by creating and removing symlinks in /etc/nginx/sites-enabled/ manually. Test It
Visit http://example.com in your browser. As long as your domain’s A record points to your server’s IP, you should see the sample page.

Conclusion
You now have Nginx 1.24 running on Ubuntu 24.04 (Noble Numbat) with a configured server block.
Step 2 – Install MariaDB
The following steps cover installing and securing MariaDB 10.11, creating a dedicated database and application user with scoped privileges, and verifying network security settings.
MariaDB vs MySQL: The two are functionally interchangeable for nearly all web applications. This guide defaults to MariaDB (fully open source and native on Debian/Ubuntu). If you need Oracle MySQL on Ubuntu, see the alternative section below.
Installing MariaDB
Start by refreshing your package index, then install the MariaDB server:
sudo apt update
sudo apt install -y mariadb-server
This installs MariaDB 10.11 from the Ubuntu 24.04 (Noble Numbat) repositories. The server starts automatically after installation.
Verifying the Installation
Confirm the service is running:
sudo systemctl status mariadb
You should see active (running) in the output. If the service is not running, start it manually:
sudo systemctl start mariadb
Verify the installed version:
mariadb --version
Understanding the Default Security Model
Modern MariaDB installations use unix socket authentication for the root database user. The database root account can only be accessed by the Linux root user (or via sudo), so no password is required for local administrative access.
This approach is more secure than traditional password authentication: there’s no password to guess, leak, or brute-force, and remote root access is impossible by design.
To access the database shell as administrator:
sudo mariadb
You’ll enter the MariaDB prompt immediately without a password prompt. This is expected behavior.
Running the Security Script
MariaDB includes a hardening script that removes insecure defaults. While recent versions ship with secure settings already applied, running this script confirms your configuration:
sudo mariadb-secure-installation
The script asks several questions. Here’s how to answer each:
Switch to unix_socket authentication? Answer Yes. This ensures the most secure local access method: only the Linux root user (via sudo) can log into the MariaDB root account, with no password needed or accepted. On some cloud provider images, unix socket may not be active yet, so answering Yes here guarantees it is enabled.
Change the root password? Answer No for most setups. With unix socket authentication, the root password is irrelevant for local access. You can set one as an emergency backup, but it’s not required.
Remove anonymous users? Answer Yes. Anonymous users could allow unintended access.
Disallow root login remotely? Answer Yes. The root database user should only connect locally. For remote access, create a dedicated user with limited privileges.
Remove test database? Answer Yes. The test database is accessible to anyone and serves no production purpose.
Reload privilege tables? Answer Yes. This applies your changes immediately.
MariaDB 10.11 on Ubuntu 24.04 ships with secure defaults. Some cloud provider images (e.g. DigitalOcean) may use password authentication for root initially; the security script’s unix_socket prompt corrects this. If the script skips certain prompts, it means those settings are already secure.
Creating a Database and Application User
Never use the root database account for application connections. Instead, create a dedicated database and user with only the privileges that application needs.
Access the database shell:
sudo mariadb
Create a new database (replace example_db with your application’s name):
CREATE DATABASE example_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
The utf8mb4 character set supports the full Unicode range, including emoji, which is essential for modern web applications.
Create a user and grant privileges on that database only (replace the placeholders with your values):
CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'your_secure_password_here';
GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
FLUSH PRIVILEGES;
The 'localhost' host restriction means this user can only connect from the local server, not remotely. For applications running on the same machine, this is exactly what you want.
Need remote database access? Replace 'localhost' with the specific IP address that needs to connect (e.g., '192.168.1.50'), or use '%' for any host (less secure). You’ll also need to modify the bind-address setting in the MariaDB configuration.
Exit the database shell:
EXIT;
Testing the Application User
Verify your new user can connect and access only the intended database:
mariadb -u example_user -p
Enter the password you set. Once connected, verify access:
SHOW DATABASES;
You should see only example_db and information_schema (a read-only system database). The user cannot see or access other databases.
Verifying Network Security
By default, MariaDB listens only on localhost (127.0.0.1), meaning it accepts connections only from the local machine. Verify this:
sudo ss -tlnp | grep 3306
You should see output showing 127.0.0.1:3306 or [::1]:3306 (IPv6 localhost). If you see 0.0.0.0:3306 or *:3306, the database is exposed to all network interfaces, which is a security risk unless you specifically need remote connections.
The bind address is configured in /etc/mysql/mariadb.conf.d/50-server.cnf. Look for the bind-address directive. Leave it as 127.0.0.1 unless you specifically need remote connections.
Connecting Applications
Your applications can connect to MariaDB using either a TCP connection or a Unix socket. For applications on the same server, the socket connection is slightly faster.
Socket connection (recommended for local applications):
$pdo = new PDO(
'mysql:unix_socket=/run/mysqld/mysqld.sock;dbname=example_db',
'example_user',
'your_secure_password_here'
);
TCP connection (works for local or remote):
$pdo = new PDO(
'mysql:host=127.0.0.1;port=3306;dbname=example_db',
'example_user',
'your_secure_password_here'
);
Both examples use mysql: as the DSN prefix. MariaDB uses the MySQL protocol, so PHP’s PDO MySQL driver works without modification.
Common connection issues:
- Access denied: Verify username, password, and host. Remember that
'user'@'localhost'and'user'@'127.0.0.1'are treated as different accounts. - Can’t connect to socket: Ensure MariaDB is running (
sudo systemctl status mariadb) and the socket path is correct. - Connection refused: Check if the server is listening on the expected interface with
ss -tlnp | grep 3306.
Alternative: Installing MySQL (Ubuntu)
Ubuntu’s repositories include both MariaDB and MySQL. If you specifically need Oracle MySQL for enterprise tooling, specific replication features, or organizational requirements, the installation process is similar.
Install MySQL instead of MariaDB:
sudo apt install -y mysql-server
This installs MySQL 8.0.37 from the Ubuntu repositories. The server starts automatically.
MySQL uses the same unix socket authentication model as MariaDB on modern Ubuntu. Access the shell with:
sudo mysql
Run the security script:
sudo mysql_secure_installation
MySQL’s security script asks similar questions to MariaDB’s, with one addition: it may prompt you to configure the VALIDATE PASSWORD component, which enforces password complexity rules. For production servers, enabling this at MEDIUM or STRONG level is recommended.
Database and user creation follows identical SQL syntax. The socket path for PHP connections is /var/run/mysqld/mysqld.sock.
The commands in the main guide work with MySQL without modification. The only difference is the service name (mysql instead of mariadb) and the shell command (mysql instead of mariadb).
Conclusion
You have successfully installed and secured MariaDB on Ubuntu 24.04 (Noble Numbat) and created a dedicated database with a least-privilege application user.
Step 3 – Install PHP-FPM
The following steps cover installing PHP-FPM and essential extensions, configuring Nginx to pass PHP requests to the FPM process manager, tuning PHP settings for production, and verifying the installation.
Installing PHP-FPM
Unlike Apache’s embedded mod_php, Nginx does not process PHP natively. Instead, it delegates PHP requests to PHP-FPM (FastCGI Process Manager), a separate service that manages a pool of PHP worker processes. Nginx communicates with PHP-FPM through a Unix socket, passing each request and receiving the rendered output.
Install PHP-FPM and the CLI tools:
sudo apt update && sudo apt install -y php-fpm
This installs PHP 8.3 from the Ubuntu 24.04 (Noble Numbat) repositories along with the FPM process manager. The php8.3-fpm service starts automatically after installation.
Verify the PHP-FPM service is running:
sudo systemctl status php8.3-fpm
You should see active (running) in the output. PHP-FPM is now listening on a Unix socket at /run/php/php8.3-fpm.sock, ready to accept requests from Nginx.
Verifying the Installation
Check the installed PHP version:
php -v
You should see output similar to:
PHP 8.3.x (cli) (built: ...)
Copyright (c) The PHP Group
Zend Engine v4.x.x, Copyright (c) Zend Technologies
with Zend OPcache v8.3.x, Copyright (c), by Zend Technologies
Configuring Nginx for PHP
Nginx needs to be told how to handle PHP files. Open the server block you created in the Nginx installation guide:
sudo nano /etc/nginx/sites-available/example.com
Replace the contents with the following configuration, which adds PHP processing and sets index.php as the default file:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Save and exit (press CTRL + X, press Y, then press ENTER)
Here’s what each block does:
| Directive | Purpose |
|---|---|
index index.php ... | Tells Nginx to look for index.php first when serving a directory. |
location ~ \.php$ | Matches any request ending in .php and passes it to PHP-FPM. |
include snippets/fastcgi-php.conf | Loads standard FastCGI parameters (document root, script filename, path info handling). |
fastcgi_pass unix:... | Sends the request to PHP-FPM via the Unix socket. |
location ~ /\.ht | Blocks access to .htaccess and other dotfiles for security. |
Test the configuration and reload Nginx:
sudo nginx -t && sudo systemctl reload nginx
Testing PHP Processing
Create a PHP test file to verify Nginx passes requests to PHP-FPM correctly:
echo '<?php phpinfo(); ?>' | sudo tee /var/www/example.com/info.php
Open your browser and navigate to:
http://example.com/info.php
You should see the PHP information page. Look for the Server API row, which should show FPM/FastCGI, confirming that Nginx is correctly communicating with PHP-FPM.
phpinfo() page exposes sensitive server configuration details. Remove it after testing:sudo rm /var/www/example.com/info.php - The
location ~ \.php$block is present in your server block - The socket path in
fastcgi_passmatches your PHP version:/run/php/php8.3-fpm.sock - PHP-FPM is running:
sudo systemctl status php8.3-fpm - You ran
sudo nginx -t && sudo systemctl reload nginxafter editing the config
Installing Common PHP Extensions
Most web applications require additional PHP extensions. The following command installs a robust set of extensions needed by WordPress, Laravel, Drupal, and other popular frameworks:
sudo apt install -y php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl php-bcmath
Here’s what each extension provides:
| Extension | Purpose | Required By |
|---|---|---|
php-mysql | MySQL/MariaDB database connectivity | WordPress, Laravel, Drupal, most CMS |
php-curl | HTTP requests, API integrations | WordPress plugins, payment gateways |
php-gd | Image processing and manipulation | WordPress media, image galleries |
php-mbstring | Multibyte string handling (UTF-8) | Any multilingual application |
php-xml | XML parsing (RSS, sitemaps, SOAP) | WordPress, Drupal, API integrations |
php-zip | Archive compression/extraction | Plugin/theme installers |
php-intl | Internationalization (i18n) | Symfony, Laravel, Magento |
php-bcmath | Arbitrary precision mathematics | E-commerce, financial applications |
Restart PHP-FPM to load the new extensions:
sudo systemctl restart php8.3-fpm
Verify the extensions are loaded:
php -m | grep -iE 'mysql|curl|gd|mbstring|xml|zip|intl|bcmath'
You should see each extension listed in the output.
apt search php- | grep ^php Configuring PHP
PHP-FPM has its own php.ini file, separate from the CLI version. The primary configuration file for PHP-FPM is:
/etc/php/8.3/fpm/php.ini
Common Configuration Changes
Open the PHP-FPM configuration file:
sudo nano /etc/php/8.3/fpm/php.ini
Here are recommended settings for most web applications. Find each directive (use Ctrl + W to search) and modify as needed:
; Maximum memory a script can consume (increase for large applications)
memory_limit = 256M
; Maximum file upload size (adjust for media-heavy sites)
upload_max_filesize = 64M
; Maximum size of POST data (should be >= upload_max_filesize)
post_max_size = 64M
; Maximum script execution time in seconds
max_execution_time = 300
; Maximum time for parsing input data
max_input_time = 300
; Server timezone (important for date/time functions)
date.timezone = UTC
Save and exit (press CTRL + X, press Y, then press ENTER)
128M memory; WooCommerce and page builders often require 256M or more. Restart PHP-FPM to apply configuration changes:
sudo systemctl restart php8.3-fpm
Production Error Handling
In production, disable error display to prevent exposing sensitive information while still logging errors for debugging:
; Disable error display in browser (security)
display_errors = Off
; Log errors to file instead
log_errors = On
; Error log location (check Nginx's error log or set custom path)
; error_log = /var/log/php_errors.log
Save and exit (press CTRL + X, press Y, then press ENTER)
display_errors = On temporarily to see errors in your browser. Always switch back to Off before going live. About PHP-FPM pools: PHP-FPM runs as a separate service from Nginx, managing a pool of PHP worker processes. The default pool (www) is configured in /etc/php/8.3/fpm/pool.d/www.conf. For most single-site setups, the defaults are fine. For high-traffic sites, you can tune pm.max_children, pm.start_servers, and related directives based on available memory.
Important File Locations
Key paths for managing PHP-FPM on Ubuntu 24.04 (Noble Numbat):
- PHP Configuration (FPM):
/etc/php/8.3/fpm/php.ini— Primary settings file for web requests. - PHP Configuration (CLI):
/etc/php/8.3/cli/php.ini— Settings for command-line scripts (separate from FPM). - FPM Pool Configuration:
/etc/php/8.3/fpm/pool.d/www.conf— Worker process settings (pm.max_children, etc.). - Additional Configuration:
/etc/php/8.3/fpm/conf.d/— Drop-in config files for extensions. - FPM Socket:
/run/php/php8.3-fpm.sock— Unix socket for Nginx-to-FPM communication. - PHP-FPM Error Log:
/var/log/php8.3-fpm.log— FPM process manager log.
Creating a Complete Test
Create a simple PHP script to verify your setup works end-to-end. This replaces the Nginx test page you created earlier:
sudo nano /var/www/example.com/index.php
Add the following content:
<?php
$hostname = gethostname();
$php_version = phpversion();
$server_software = $_SERVER['SERVER_SOFTWARE'];
$document_root = $_SERVER['DOCUMENT_ROOT'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Test - <?php echo $hostname; ?></title>
<style>
body { font-family: system-ui, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }
h1 { color: #4F5D95; }
.info { background: #f4f4f4; padding: 15px; border-radius: 5px; margin: 10px 0; }
.success { color: #28a745; }
code { background: #e9ecef; padding: 2px 6px; border-radius: 3px; }
</style>
</head>
<body>
<h1>✓ PHP is Working!</h1>
<div class="info">
<p><strong>PHP Version:</strong> <code><?php echo $php_version; ?></code></p>
<p><strong>Server:</strong> <code><?php echo $server_software; ?></code></p>
<p><strong>Hostname:</strong> <code><?php echo $hostname; ?></code></p>
<p><strong>Document Root:</strong> <code><?php echo $document_root; ?></code></p>
</div>
<p class="success">Your LEMP stack's PHP component is configured correctly.</p>
<p><small>Return to <a href="https://devanswers.net/series/lemp-stack/">LEMP Stack Documentation</a></small></p>
</body>
</html>
Save and exit (press CTRL + X, press Y, then press ENTER)
Visit http://example.com in your browser to see the test page. If you see the PHP version and server details, your LEMP stack’s PHP layer is working correctly.
Conclusion
You now have PHP 8.3 running as PHP-FPM with Nginx on Ubuntu 24.04, complete with essential extensions for modern web applications.
Step 4 – Secure with SSL
The following steps cover installing Certbot, obtaining a free Let’s Encrypt SSL certificate for your domain, configuring Nginx for HTTPS with automatic HTTP redirection, enabling HSTS security headers, and setting up automatic certificate renewal.
Installing Certbot
Certbot is the official Let’s Encrypt client that automates certificate issuance and Nginx configuration. Install it along with the Nginx plugin:
sudo apt update && sudo apt install -y certbot python3-certbot-nginx
Verify the installation:
certbot --version
You should see the Certbot version number in the output, confirming a successful installation.
Obtaining an SSL Certificate
Before requesting a certificate, verify that your domain resolves to your server’s IP address:
host example.com
The output should show your server’s public IP. If it doesn’t, update your DNS A record at your domain registrar and wait for propagation before continuing.
Run Certbot with the Nginx plugin to obtain and install your certificate. Replace example.com with your actual domain:
sudo certbot --nginx -d example.com -d www.example.com
www subdomain), omit the second -d flag. You can also secure multiple subdomains by adding additional -d flags (e.g., -d blog.example.com). Certbot will prompt you for the following:
- Email address — for certificate expiry notifications and account recovery. Enter a valid email.
- Terms of Service — you must agree (Y) to proceed.
- EFF mailing list — optional. Enter Y or N based on your preference.
If successful, you will see output confirming the certificate was issued and deployed:
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/example.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/example.com/privkey.pem
This certificate expires on 2026-05-20.
Deploying certificate
Successfully deployed certificate for example.com
Successfully deployed certificate for www.example.com
Congratulations! You have successfully enabled HTTPS on
https://example.com and https://www.example.com
- Obtained a trusted certificate from Let’s Encrypt via an HTTP-01 challenge
- Added
listen 443 ssland certificate paths to your Nginx server block - Configured HTTP-to-HTTPS redirection with a separate
serverblock on port 80 - Applied recommended TLS settings from
/etc/letsencrypt/options-ssl-nginx.conf - Reloaded Nginx to apply all changes
- Domain not resolving: Verify your DNS A record points to this server’s IP
- Port 80 blocked: Ensure
sudo ufw statusshowsNginx Fullallowed - No matching server block: Certbot needs an Nginx server block with a
server_namematching your domain - Nginx config error: Run
sudo nginx -tto check for syntax errors before retrying - Rate limit exceeded: Let’s Encrypt allows 5 duplicate certificates per domain per week. Wait and retry later.
Verifying HTTPS
Open your browser and visit https://example.com. You should see your site served over HTTPS with a padlock icon in the address bar.
From the command line, verify the HTTPS response headers:
curl -sI https://example.com
You should see HTTP/2 200 (or HTTP/1.1 200 OK) at the top of the response.
Next, verify that HTTP requests are automatically redirected to HTTPS:
curl -sI http://example.com
You should see a 301 Moved Permanently response with a Location header pointing to https://example.com/. This confirms that all HTTP traffic is being redirected to the secure HTTPS version.
Strengthening SSL Security
Certbot’s default configuration provides solid SSL security, including modern TLS protocols and cipher suites managed via /etc/letsencrypt/options-ssl-nginx.conf. To further protect your site, enable HTTP Strict Transport Security (HSTS), which instructs browsers to always use HTTPS even if a user types http:// in the address bar.
Open the Nginx server block that Certbot modified:
sudo nano /etc/nginx/sites-available/example.com
Find the server block that listens on port 443 (the one Certbot added the SSL directives to) and add the HSTS header inside it:
server {
listen 443 ssl; # managed by Certbot
server_name example.com www.example.com;
root /var/www/example.com;
# HSTS — force browsers to use HTTPS for one year
add_header Strict-Transport-Security "max-age=31536000" always;
# ... rest of your configuration ...
}
Save and exit (press CTRL + X, press Y, then press ENTER)
Test the configuration and reload Nginx:
sudo nginx -t && sudo systemctl reload nginx
Verify the HSTS header is present:
curl -sI https://example.com | grep -i strict
You should see:
strict-transport-security: max-age=31536000
max-age=31536000 value tells browsers to remember the HTTPS-only policy for one year (31,536,000 seconds). Once your site is stable on HTTPS, you can optionally add includeSubDomains and submit your domain to the HSTS preload list for browser-level enforcement. Only do this when you are certain all subdomains support HTTPS. Automatic Certificate Renewal
Let’s Encrypt certificates are valid for 90 days. Certbot installs a systemd timer that automatically checks for renewal twice daily and renews any certificate within 30 days of expiry.
Verify the renewal timer is active:
sudo systemctl status certbot.timer
You should see active (waiting) in the output, along with the next scheduled run time.
Test the renewal process with a dry run (simulates renewal without making any changes):
sudo certbot renew --dry-run
If the dry run completes without errors, automatic renewal is working correctly. You should see Congratulations, all simulated renewals succeeded in the output.
Important File Locations
Key paths for managing SSL certificates on Ubuntu 24.04 (Noble Numbat):
- Certificate (full chain):
/etc/letsencrypt/live/example.com/fullchain.pem— The complete certificate chain sent to browsers. - Private Key:
/etc/letsencrypt/live/example.com/privkey.pem— Your certificate’s private key. Keep this secure. - Nginx Server Block:
/etc/nginx/sites-available/example.com— Your site configuration with Certbot’s SSL additions. - Renewal Configuration:
/etc/letsencrypt/renewal/example.com.conf— Settings used for automatic renewal. - SSL Options:
/etc/letsencrypt/options-ssl-nginx.conf— Certbot-maintained TLS protocol and cipher settings. - Certbot Log:
/var/log/letsencrypt/letsencrypt.log— Detailed log for troubleshooting certificate operations.
Conclusion
Your Ubuntu 24.04 (Noble Numbat) server is now secured with a free Let’s Encrypt SSL certificate, automatic HTTP-to-HTTPS redirection, HSTS security headers, and automated 90-day certificate renewal.
Summary – What You Now Have
Congratulations! You now have a complete, production-ready LEMP stack running on Ubuntu 24.04 with Nginx 1.24, PHP 8.3, MariaDB 10.11, and a free Let’s Encrypt SSL certificate securing all traffic over HTTPS.
With security support until 2029 (extendable to 2034 with Ubuntu Pro), this is an excellent foundation for web applications that demand long-term stability.
Comments