Tutorials  /  Ubuntu

Install WordPress on Ubuntu 24.04 with LEMP Stack

Ccentron Redaktion · August 2025 ·9 min read ·Ubuntu, Tutorial

WordPress is an open-source content management system (CMS) developed with PHP and supported by MySQL or MariaDB. Originally a blogging tool, it has evolved into one of the most popular website platforms, powering more than 22% of the top one million websites as of December 2024.

This guide details the process of installing and setting up WordPress on an Ubuntu 24.04 server with the LEMP stack (Linux, Nginx, MySQL, PHP). You will install the required software, secure your setup, and configure WordPress to serve dynamic sites from your own server.

Prerequisites

Before proceeding, ensure you meet the following requirements:

  • Access to an Ubuntu 24.04 server using a non-root user with sudo privileges.
  • A domain A record pointing to your server IP (for example, www.example.com) if using a custom domain.
VM

Matching infrastructure at centron

Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Install Nginx Web Server

First, install Nginx on your system:

Console
$ sudo apt install nginx -y

Start the Nginx service:

Console
$ sudo systemctl start nginx

Enable Nginx to launch at system boot:

Console
$ sudo systemctl enable nginx

Check the service status to confirm Nginx is running:

Console
$ sudo systemctl status nginx

Sample Output:

YAML
● nginx.service - nginx - high performance web server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
     Active: active (running) since Sat 2025-04-26 13:18:09 WAT; 9min ago
       Docs: https://nginx.org/en/docs/
   Main PID: 1629 (nginx)
...

Configure the Firewall

Next, adjust the firewall settings with UFW (Uncomplicated Firewall) to allow HTTP and HTTPS traffic.

Check the current firewall status:

Console
$ sudo ufw status

Allow HTTP and HTTPS using the Nginx Full profile:

Console
$ sudo ufw allow "Nginx Full"

Reload UFW to apply changes:

Console
$ sudo ufw reload

Verify the updated firewall rules:

Console
$ sudo ufw status

Expected Output:

Code
To                         Action      From
--                         ------      ----
Nginx Full                 ALLOW       Anywhere
Nginx Full (v6)            ALLOW       Anywhere (v6)

Install MySQL Database

Next, install and configure the MySQL database server for WordPress.

Install the MySQL server package:

Console
$ sudo apt install mysql-server -y

Check that MySQL was installed properly:

Console
$ mysql --version

Sample Output:

Code
mysql  Ver 8.0.36 for Linux on x86_64 (MySQL Community Server - GPL)

Start the MySQL service:

Console
$ sudo systemctl start mysql

Enable MySQL to launch at startup:

Console
$ sudo systemctl enable mysql

Verify that the service is active and running:

Console
$ sudo systemctl status mysql

Sample Output:

YAML
● mysql.service - MySQL Community Server
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled)
     Active: active (running) since Sat 2025-04-26 13:42:56 WAT; 2min ago
   Main PID: 43442 (mysqld)
...

For security, run the built-in script to strengthen your MySQL installation:

Console
$ sudo mysql_secure_installation

Create a WordPress Database and User

WordPress needs a separate MySQL database to store content, settings, and user data. Follow these steps to create one:

Log into the MySQL shell as the root user:

Console
$ sudo mysql

Create the database for WordPress:

Code
mysql> CREATE DATABASE wordpressdb;

Create a dedicated MySQL user with a strong password:

Code
mysql> CREATE USER 'wordpressdbuser'@'localhost' IDENTIFIED BY 'strongpassword';

Grant all privileges on the WordPress database to this user:

Code
mysql> GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressdbuser'@'localhost';

Apply the new privileges:

Code
mysql> FLUSH PRIVILEGES;

Verify the database creation:

Code
mysql> SHOW DATABASES;

Sample Output:

Code
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wordpressdb        |
+--------------------+

Check that the user was created:

Code
mysql> SELECT User, Host FROM mysql.user WHERE User = 'wordpressdbuser';

Sample Output:

Code
+-----------------+-----------+
| User            | Host      |
+-----------------+-----------+
| wordpressdbuser | localhost |
+-----------------+-----------+

Confirm the privileges assigned to the user:

Code
mysql> SHOW GRANTS FOR 'wordpressdbuser'@'localhost';

Sample Output:

Code
+--------------------------------------------------------------------------+
| Grants for wordpressdbuser@localhost                                     |
+--------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `wordpressdbuser`@`localhost`                      |
| GRANT ALL PRIVILEGES ON `wordpressdb`.* TO `wordpressdbuser`@`localhost` |
+--------------------------------------------------------------------------+

Exit the MySQL shell:

Code
mysql> EXIT;

Install PHP and Extensions

WordPress requires PHP to generate dynamic content and connect with the MySQL database. Begin by installing PHP and the necessary modules:

Install PHP and required packages:

Console
$ sudo apt install php php-cli php-common php-imap php-fpm php-snmp php-xml php-zip php-mbstring php-curl php-mysqli php-gd php-intl -y

Check the installed PHP version:

Console
$ php -v

Sample Output:

Code
PHP 8.3.X (cli) (built: ...)

Confirm php-fpm is active and running:

Console
$ sudo systemctl status php8.3-fpm

Download and Install WordPress

Now, download and prepare WordPress:

Download the latest WordPress release:

Console
$ wget http://wordpress.org/latest.tar.gz

Extract the downloaded archive:

Console
$ sudo tar -xvzf latest.tar.gz

Move WordPress files to the Nginx web root directory:

Console
$ sudo mv wordpress/* /var/www/html/

Set file ownership to the Nginx user:

Console
$ sudo chown -R www-data:www-data /var/www/html

Switch to the web root directory:

Console
$ cd /var/www/html/

Remove default Nginx placeholder files:

Console
$ sudo rm index.html index.nginx-debian.html

Rename the sample WordPress configuration file:

Console
$ sudo mv wp-config-sample.php wp-config.php

Verify WordPress files are in place:

Console
$ ls -l

Ensure files such as wp-config.php, wp-login.php, and the wp-admin folder are present.

Configure the wp-config.php File

Update the WordPress configuration file with your database credentials so it can connect to MySQL.

Open wp-config.php with a text editor:

Console
$ sudo nano wp-config.php

Update the following lines with the database information:

Code
// The name of the database for WordPress 
define( 'DB_NAME', 'wordpressdb' );

// MySQL database username 
define( 'DB_USER', 'wordpressdbuser' );

// MySQL database password 
define( 'DB_PASSWORD', 'strongpassword' );

// MySQL hostname 
define( 'DB_HOST', 'localhost' );

Save and close the file. Ensure the values match those set earlier when creating the database and user.

Create an Nginx Server Block for WordPress

Configure Nginx with a server block to properly handle WordPress traffic and PHP requests.

Locate the active PHP-FPM socket:

Console
$ ls /var/run/php

Sample Output:

Code
php8.3-fpm.pid  php8.3-fpm.sock  php-fpm.sock

Note the correct socket filename, e.g., php8.3-fpm.sock.

Edit the default Nginx configuration file:

Console
$ sudo nano /etc/nginx/sites-available/default

Replace its content with the following configuration (adjust domain and socket path as needed):

Code
server {
    listen 80;
    server_name www.example.com;

    root /var/www/html;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; # adjust if your PHP version differs
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location = /favicon.ico {
        access_log off;
        log_not_found off;
        expires max;
    }

    location = /robots.txt {
        access_log off;
        log_not_found off;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    location /wp-content/uploads/ {
        location ~ \.php$ {
            deny all;
        }
    }
}

Check the configuration syntax:

Console
$ sudo nginx -t

Sample Output:

Code
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart Nginx to apply changes:

Console
$ sudo systemctl restart nginx

Access the WordPress Dashboard

Open a browser and navigate to http://www.example.com. You should see the WordPress installation page.

Select your preferred language and click Continue. Fill in your Site Title, Username, Password, and Email, then click Install WordPress. Once completed, log in with the credentials you set to reach the WordPress dashboard.

Conclusion

In this tutorial, you installed and configured WordPress on Ubuntu 24.04 using the LEMP stack (Linux, Nginx, MySQL, PHP). You set up Nginx, created a secure MySQL database, configured PHP with the necessary extensions, and deployed WordPress for production use.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren