DEV Community

Cover image for Installing WordPress on Ubuntu 24.04
Sanskriti Harmukh for Vultr

Posted on with Aashish Chaurasiya Originally published at docs.vultr.com

Installing WordPress on Ubuntu 24.04

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
Enter fullscreen mode Exit fullscreen mode

2. Start the Nginx service:

$ sudo systemctl start nginx
Enter fullscreen mode Exit fullscreen mode

3. Enable Nginx to start automatically on boot:

$ sudo systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

4. Check the service status to verify Nginx is running:

$ sudo systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

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)
...
Enter fullscreen mode Exit fullscreen mode

2. Configure the Firewall

Use UFW (Uncomplicated Firewall) to allow HTTP and HTTPS traffic.

1. Check the current firewall status:

$ sudo ufw status
Enter fullscreen mode Exit fullscreen mode

2. Allow both HTTP and HTTPS through the firewall using the Nginx Full profile:

$ sudo ufw allow "Nginx Full"
Enter fullscreen mode Exit fullscreen mode

3. Reload UFW to apply the rule:

$ sudo ufw reload
Enter fullscreen mode Exit fullscreen mode

4. Verify that the rule has been applied:

$ sudo ufw status
Enter fullscreen mode Exit fullscreen mode

Output:

To                         Action      From
--                         ------      ----
Nginx Full                 ALLOW       Anywhere
Nginx Full (v6)            ALLOW       Anywhere (v6)
Enter fullscreen mode Exit fullscreen mode

3. Install MySQL Database

1. Install the MySQL server package:

$ sudo apt install mysql-server -y
Enter fullscreen mode Exit fullscreen mode

2. Verify that MySQL was installed successfully:

$ mysql --version
Enter fullscreen mode Exit fullscreen mode

Output:

mysql  Ver 8.0.36 for Linux on x86_64 (MySQL Community Server - GPL)
Enter fullscreen mode Exit fullscreen mode

3. Start the MySQL service to activate the database server:

$ sudo systemctl start mysql
Enter fullscreen mode Exit fullscreen mode

4. Enable MySQL to start on boot:

$ sudo systemctl enable mysql
Enter fullscreen mode Exit fullscreen mode

5. Verify that MySQL is running correctly by checking its service status:

$ sudo systemctl status mysql
Enter fullscreen mode Exit fullscreen mode

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)
...
Enter fullscreen mode Exit fullscreen mode

6. Harden your MySQL setup by running the built-in security script:

$ sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

2. Create the WordPress database:

mysql> CREATE DATABASE wordpressdb;
Enter fullscreen mode Exit fullscreen mode

3. Create a dedicated user for WordPress with a strong password:

mysql> CREATE USER 'wordpressdbuser'@'localhost' IDENTIFIED BY 'strongpassword';
Enter fullscreen mode Exit fullscreen mode

4. Grant full privileges to the new user on the WordPress database:

mysql> GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressdbuser'@'localhost';
Enter fullscreen mode Exit fullscreen mode

5. Apply the changes by reloading the privileges:

mysql> FLUSH PRIVILEGES;
Enter fullscreen mode Exit fullscreen mode

6. Verify that the database was created successfully:

mysql> SHOW DATABASES;
Enter fullscreen mode Exit fullscreen mode

Output:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wordpressdb        |
+--------------------+
Enter fullscreen mode Exit fullscreen mode

7. Check that the user was created:

mysql> SELECT User, Host FROM mysql.user WHERE User = 'wordpressdbuser';
Enter fullscreen mode Exit fullscreen mode

Output:

+-----------------+-----------+
| User            | Host      |
+-----------------+-----------+
| wordpressdbuser | localhost |
+-----------------+-----------+
Enter fullscreen mode Exit fullscreen mode

8. Confirm the privileges granted to the user:

mysql> SHOW GRANTS FOR 'wordpressdbuser'@'localhost';
Enter fullscreen mode Exit fullscreen mode

Output:

+--------------------------------------------------------------------------+
| Grants for wordpressdbuser@localhost                                     |
+--------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `wordpressdbuser`@`localhost`                      |
| GRANT ALL PRIVILEGES ON `wordpressdb`.* TO `wordpressdbuser`@`localhost` |
+--------------------------------------------------------------------------+
Enter fullscreen mode Exit fullscreen mode

9. Exit the MySQL shell:

mysql> EXIT;
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

2. Verify the installed PHP version:

$ php -v
Enter fullscreen mode Exit fullscreen mode

Output:

PHP 8.3.X (cli) (built: ...)
Enter fullscreen mode Exit fullscreen mode

3. Confirm that php-fpm is running:

$ sudo systemctl status php8.3-fpm
Enter fullscreen mode Exit fullscreen mode

The output should show active (running).

6. Download and Install WordPress

1. Download the latest WordPress release:

$ wget http://wordpress.org/latest.tar.gz
Enter fullscreen mode Exit fullscreen mode

2. Extract the archive:

$ sudo tar -xvzf latest.tar.gz
Enter fullscreen mode Exit fullscreen mode

3. Move the contents to the Nginx web root:

$ sudo mv wordpress/* /var/www/html/
Enter fullscreen mode Exit fullscreen mode

4. Set ownership to the Nginx user:

$ sudo chown -R www-data:www-data /var/www/html
Enter fullscreen mode Exit fullscreen mode

5. Change to the web root:

$ cd /var/www/html/
Enter fullscreen mode Exit fullscreen mode

6. Remove default Nginx placeholders:

$ sudo rm index.html index.nginx-debian.html
Enter fullscreen mode Exit fullscreen mode

7. Rename the sample config:

$ sudo mv wp-config-sample.php wp-config.php
Enter fullscreen mode Exit fullscreen mode

8. Verify the WordPress files are in place:

$ ls -l
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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' );
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Output:

php8.3-fpm.pid  php8.3-fpm.sock  php-fpm.sock
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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;
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

4. Test the Nginx configuration for syntax correctness:

$ sudo nginx -t
Enter fullscreen mode Exit fullscreen mode

Output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Enter fullscreen mode Exit fullscreen mode

5. Restart Nginx to apply the updated configuration:

$ sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)