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.
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:
$ sudo apt install nginx -yStart the Nginx service:
$ sudo systemctl start nginxEnable Nginx to launch at system boot:
$ sudo systemctl enable nginxCheck the service status to confirm Nginx is running:
$ sudo systemctl status nginxSample Output:
● 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:
$ sudo ufw statusAllow HTTP and HTTPS using the Nginx Full profile:
$ sudo ufw allow "Nginx Full"Reload UFW to apply changes:
$ sudo ufw reloadVerify the updated firewall rules:
$ sudo ufw statusExpected Output:
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:
$ sudo apt install mysql-server -yCheck that MySQL was installed properly:
$ mysql --versionSample Output:
mysql Ver 8.0.36 for Linux on x86_64 (MySQL Community Server - GPL)Start the MySQL service:
$ sudo systemctl start mysqlEnable MySQL to launch at startup:
$ sudo systemctl enable mysqlVerify that the service is active and running:
$ sudo systemctl status mysqlSample Output:
● 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:
$ sudo mysql_secure_installationCreate 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:
$ sudo mysqlCreate the database for WordPress:
mysql> CREATE DATABASE wordpressdb;Create a dedicated MySQL user with a strong password:
mysql> CREATE USER 'wordpressdbuser'@'localhost' IDENTIFIED BY 'strongpassword';Grant all privileges on the WordPress database to this user:
mysql> GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressdbuser'@'localhost';Apply the new privileges:
mysql> FLUSH PRIVILEGES;Verify the database creation:
mysql> SHOW DATABASES;Sample Output:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| wordpressdb |
+--------------------+Check that the user was created:
mysql> SELECT User, Host FROM mysql.user WHERE User = 'wordpressdbuser';Sample Output:
+-----------------+-----------+
| User | Host |
+-----------------+-----------+
| wordpressdbuser | localhost |
+-----------------+-----------+Confirm the privileges assigned to the user:
mysql> SHOW GRANTS FOR 'wordpressdbuser'@'localhost';Sample Output:
+--------------------------------------------------------------------------+
| Grants for wordpressdbuser@localhost |
+--------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `wordpressdbuser`@`localhost` |
| GRANT ALL PRIVILEGES ON `wordpressdb`.* TO `wordpressdbuser`@`localhost` |
+--------------------------------------------------------------------------+Exit the MySQL shell:
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:
$ 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 -yCheck the installed PHP version:
$ php -vSample Output:
PHP 8.3.X (cli) (built: ...)Confirm php-fpm is active and running:
$ sudo systemctl status php8.3-fpmDownload and Install WordPress
Now, download and prepare WordPress:
Download the latest WordPress release:
$ wget http://wordpress.org/latest.tar.gzExtract the downloaded archive:
$ sudo tar -xvzf latest.tar.gzMove WordPress files to the Nginx web root directory:
$ sudo mv wordpress/* /var/www/html/Set file ownership to the Nginx user:
$ sudo chown -R www-data:www-data /var/www/htmlSwitch to the web root directory:
$ cd /var/www/html/Remove default Nginx placeholder files:
$ sudo rm index.html index.nginx-debian.htmlRename the sample WordPress configuration file:
$ sudo mv wp-config-sample.php wp-config.phpVerify WordPress files are in place:
$ ls -lEnsure 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:
$ sudo nano wp-config.phpUpdate the following lines with the database information:
// 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:
$ ls /var/run/phpSample Output:
php8.3-fpm.pid php8.3-fpm.sock php-fpm.sockNote the correct socket filename, e.g., php8.3-fpm.sock.
Edit the default Nginx configuration file:
$ sudo nano /etc/nginx/sites-available/defaultReplace its content with the following configuration (adjust domain and socket path as needed):
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:
$ sudo nginx -tSample Output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulRestart Nginx to apply changes:
$ sudo systemctl restart nginxAccess 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.
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.