How to Install WordPress on Ubuntu 24.04 LTS with Nginx and PHP-FPM

WordPress Logo
This comprehensive guide provides a detailed walkthrough for installing WordPress on an Ubuntu 24.04 LTS server. Utilizing the powerful Nginx web server in conjunction with the efficient PHP-FPM processor and a robust MariaDB database, you will learn how to set up a highly performant and secure WordPress environment from scratch. We will cover everything from initial system updates and package installations to intricate database and Nginx configurations, ensuring your WordPress site is not only operational but also optimized for stability and speed. By following these step-by-step instructions, you will gain the knowledge and practical skills necessary to successfully deploy and manage your WordPress instance on a solid Ubuntu foundation.

Prerequisites

  • A server running Ubuntu 24.04 LTS (a fresh installation is recommended).
  • Sudo privileges or root access to the server.
  • A basic understanding of the Linux command line.
  • A domain name (optional, but recommended for production environments).
  • An internet connection to download necessary packages.

πŸ”Ή Step 1: Update and Upgrade Your Ubuntu System

Always keep your server updated with the latest packages and security patches:

sudo apt update
sudo apt upgrade -y

πŸ”Ή Step 2: Install Nginx Web Server 🌐

Nginx serves your WordPress site to visitors. Install it and enable it to start at boot:

sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx

πŸ”Ή Step 3: Install PHP-FPM and Essential PHP Extensions 🐘

WordPress is built with PHP, so install PHP-FPM and required extensions:

sudo apt install php-fpm php-mysql php-curl php-xml php-gd php-mbstring php-zip php-bcmath -y

βœ… PHP-FPM will process PHP requests efficiently alongside Nginx.


πŸ”Ή Step 4: Install MariaDB Server πŸ—„οΈ

MariaDB is the database engine for storing WordPress data. Install it:

sudo apt install mariadb-server mariadb-client -y

Then, secure your MariaDB installation:

sudo mysql_secure_installation

πŸ”Ή Step 5: Create a WordPress Database and User πŸ“‚

Create a dedicated database and user for WordPress:

sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

βœ… Replace your_strong_password with a secure password.


πŸ”Ή Step 6: Download and Set Up WordPress πŸ“

Navigate to your web root directory and download WordPress:

cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz

Extract and move the files:

sudo tar -xvzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz

Set the correct permissions for the WordPress files:

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

βœ… This ensures Nginx can access WordPress files.


πŸ”Ή Step 7: Configure wp-config.php βš™οΈ

Copy the sample configuration file and edit it:

cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Set the database configuration:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wordpressuser' );
define( 'DB_PASSWORD', 'your_strong_password' );
define( 'DB_HOST', 'localhost' );

πŸ” Adding WordPress Security Salts

Visit this WordPress Salt Generator and replace the salts in wp-config.php with the generated lines:

define('AUTH_KEY', 'your unique phrase');
define('SECURE_AUTH_KEY', 'your unique phrase');
define('LOGGED_IN_KEY', 'your unique phrase');
define('NONCE_KEY', 'your unique phrase');
define('AUTH_SALT', 'your unique phrase');
define('SECURE_AUTH_SALT', 'your unique phrase');
define('LOGGED_IN_SALT', 'your unique phrase');
define('NONCE_SALT', 'your unique phrase');

βœ… These salts help protect your site from security threats.


πŸ”Ή Step 8: Configure Nginx for WordPress πŸ›‘οΈ

Create a new Nginx configuration file for WordPress:

sudo nano /etc/nginx/sites-available/wordpress

Add the following configuration:

server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Enable the site configuration:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

βœ… Replace yourdomain.com with your actual domain name.


πŸ”Ή Step 9: Complete WordPress Setup in Browser 🌍

Open your browser and visit:

http://yourdomain.com

Complete the WordPress setup by filling in your site title, admin username, password, and email, then click Install WordPress.


πŸŽ‰ Success! WordPress Installed on Ubuntu 24.04! πŸŽ‰

You now have a fully functional WordPress site running on Ubuntu 24.04 with Nginx and PHP-FPM. πŸŽ‰
➑️ Next Steps: Secure your site with SSL, install themes and plugins, and start publishing your content!

Views: 5

Leave a Comment