DevOps
Installing WordPress on Ubuntu 24.04
Sanskriti Harmukh DEV Community
2 views
WordPress is a free, open-source content management system (CMS) built with PHP and backed by MySQL or MariaDB. It began as a blogging tool and has since grown into one of the most widely used platforms for building websites, powering over 22% of the top one million websites as of December 2024. This guide walks through installing and configuring WordPress on a server running Ubuntu 24.04 with the LEMP stack (Linux, Nginx, MySQL, PHP). By the end, you'll have a hardened LEMP environment with WordPress deployed and ready to serve dynamic websites from your own server.
Before you begin, you need access to an Ubuntu 24.04 instance as a non-root sudo user, and, if using a custom domain, a domain A record configured with your DNS provider pointing to your server IP (e.g., www.example.com).
1. Install Nginx Web Server
1. Install Nginx:
$ sudo apt install nginx -y
2. Start the Nginx service:
$ sudo systemctl start nginx
3. Enable Nginx to start automatically on boot:
$ sudo systemctl enable nginx
4. Check the service status to verify Nginx is running:
$ sudo systemctl status nginx
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)
...
2. Configure the Firewall
Use UFW (Uncomplicated Firewall) to allow HTTP and HTTPS traffic.
1. Check the current firewall status:
$ sudo ufw status
2. Allow both HTTP and HTTPS through the firewall using the Nginx Full profile:
$ sudo ufw allow "Nginx Full"
3. Reload UFW to apply the rule:
$ sudo ufw reload
4. Verify that the rule has been applied:
$ sudo ufw status
Output:
To Action From
-- ------ ----
Nginx Full ALLOW Anywhere
Nginx Full (v6) ALLOW Anywhere (v6)
3. Install MySQL Database
1. Install the MySQL server package:
$ sudo apt install mysql-server -y
2. Verify that MySQL was installed successfully:
$ mysql --version
Output:
mysql Ver 8.0.36 for Linux on x86_64 (MySQL Community Server - GPL)
3. Start the MySQL service to activate the database server:
$ sudo systemctl start mysql
4. Enable MySQL to start on boot:
$ sudo systemctl enable mysql
5. Verify that MySQL is running correctly by checking its service status:
$ sudo systemctl status mysql
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)
...
6. Harden your MySQL setup by running the built-in security script:
$ sudo mysql_secure_installation
4. Create a WordPress Database and User
WordPress requires a dedicated MySQL database to store its content, settings, and user information.
1. Log in to the MySQL shell as the root user:
$ sudo mysql
2. Create the WordPress database:
mysql> CREATE DATABASE wordpressdb;
3. Create a dedicated user for WordPress with a strong password:
mysql> CREATE USER 'wordpressdbuser'@'localhost' IDENTIFIED BY 'strongpassword';
4. Grant full privileges to the new user on the WordPress database:
mysql> GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressdbuser'@'localhost';
5. Apply the changes by reloading the privileges:
mysql> FLUSH PRIVILEGES;
6. Verify that the database was created successfully:
mysql> SHOW DATABASES;
Output:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| wordpressdb |
+--------------------+
7. Check that the user was created:
mysql> SELECT User, Host FROM mysql.user WHERE User = 'wordpressdbuser';
Output:
+-----------------+-----------+
| User | Host |
+-----------------+-----------+
| wordpressdbuser | localhost |
+-----------------+-----------+
8. Confirm the privileges granted to the user:
mysql> SHOW GRANTS FOR 'wordpressdbuser'@'localhost';
Output:
+--------------------------------------------------------------------------+
| Grants for wordpressdbuser@localhost |
+--------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `wordpressdbuser`@`localhost` |
| GRANT ALL PRIVILEGES ON `wordpressdb`.* TO `wordpressdbuser`@`localhost` |
+--------------------------------------------------------------------------+
9. Exit the MySQL shell:
mysql> EXIT;
5. Install PHP and Extensions
WordPress uses PHP to process dynamic content and connect to the MySQL database.
1. Install PHP and all required modules:
$ 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
2. Verify the installed PHP version:
$ php -v
Output:
PHP 8.3.X (cli) (built: ...)
3. Confirm that php-fpm is running:
$ sudo systemctl status php8.3-fpm
The output should show active (running).
6. Download and Install WordPress
1. Download the latest WordPress release:
$ wget http://wordpress.org/latest.tar.gz
2. Extract the archive:
$ sudo tar -xvzf latest.tar.gz
3. Move the contents to the Nginx web root:
$ sudo mv wordpress/* /var/www/html/
4. Set ownership to the Nginx user:
$ sudo chown -R www-data:www-data /var/www/html
5. Change to the web root:
$ cd /var/www/html/
6. Remove default Nginx placeholders:
$ sudo rm index.html index.nginx-debian.html
7. Rename the sample config:
$ sudo mv wp-config-sample.php wp-config.php
8. Verify the WordPress files are in place:
$ ls -l
Ensure files like wp-config.php, wp-login.php, and the wp-admin folder exist.
Configure the WordPress wp-config.php File
To allow WordPress to connect to your MySQL database, update the wp-config.php file with the database credentials created earlier.
1. Open the configuration file in a text editor:
$ sudo nano wp-config.php
2. Find and update the following lines with your 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' );
Ensure the values for DB_NAME, DB_USER, and DB_PASSWORD match what you used in Create a WordPress Database and User. Leave DB_HOST as localhost if the database is hosted on the same server.
7. Create an Nginx Server Block for WordPress
To serve your WordPress site, configure Nginx with a server block that handles PHP requests and routes domain traffic to your WordPress directory.
1. Identify the active PHP-FPM socket on your system:
$ ls /var/run/php
Output:
php8.3-fpm.pid php8.3-fpm.sock php-fpm.sock
Note the exact .sock filename, such as php8.3-fpm.sock. You'll need this for the fastcgi_pass directive in the next step.
2. Open the default Nginx server block configuration file:
$ sudo nano /etc/nginx/sites-available/default
3. Replace the contents of the file with the following configuration. Replace www.example.com with your domain name or server IP, and update the PHP socket path if 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;
}
}
}
4. Test the Nginx configuration for syntax correctness:
$ sudo nginx -t
Output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
5. Restart Nginx to apply the updated configuration:
$ sudo systemctl restart nginx
8. Access the WordPress Dashboard
1. Open your web browser and visit http://www.example.com. You should see the WordPress installation screen. Select your preferred language and click Continue.
2. Fill in the required details, including your Site Title, Username, Password, and Email, then click Install WordPress.
3. Once installation completes, log in with the credentials you just set.
4. You'll be redirected to the WordPress dashboard, where you can begin customizing your website.
Next Steps
Install an SSL certificate (for example, via Certbot) and redirect HTTP traffic to HTTPS.
Set up automated backups for your WordPress files and MySQL database.
Install caching and security plugins to improve performance and hardening.
Configure a CDN or object storage integration for media uploads if your site grows.
For the full guide with additional tips, visit the original article on Vultr Docs.
Read original: https://dev.to/vultr/installing-wordpress-on-ubuntu-2404-f1n
← Previous
Setting Up Nginx Ingress Controller with SSL on Kubernetes
Next →
Installing OpenVPN on Ubuntu 24.04
Related
Comments0
No comments yet — be the first