How to Install WordPress with Nginx on Ubuntu 24.04
Installing WordPress with Nginx on Ubuntu 24.04 gives you a fast, reliable site on a LEMP stack. LEMP is a bundle of free software: Linux as the operating system, Nginx (pronounced “engine-x”) as the web server, a MySQL-compatible database, and PHP to process the code. In this guide the database is MariaDB, which is a drop-in replacement for MySQL and is what Ubuntu installs by default.
Ubuntu 24.04 provides the stable base, and Nginx handles visitor traffic quickly. This guide walks you through installing each piece, connecting the database, and getting your site online. You need a user with sudo rights and an internet connection on the server. If a firewall is active, ports 80 (HTTP) and 443 (HTTPS) must be open.
Install Nginx, MariaDB, and PHP-FPM using apt commands. Then create a WordPress database and user within MariaDB. Finally, configure Nginx to serve your WordPress site.
Install Nginx HTTP server on Ubuntu
To install Nginx on Ubuntu 24.04 for your WordPress site, open your terminal and run the commands sudo apt update and sudo apt install nginx. The first command refreshes the package list so you get the current version. The second installs Nginx. Nginx is a fast web server that handles visitor traffic and displays your pages correctly.
To do that, open the Ubuntu terminal and run the commands below to install the Nginx web server. Press Y if apt asks you to confirm. When the command finishes you are back at the shell prompt with no errors showing.
sudo apt update
sudo apt install nginx
Once Nginx is installed, the commands below can start, stop, and enable the Nginx web server to start automatically when your server boots up. On Ubuntu, Nginx normally starts by itself right after installation, but it is still worth running the enable command so it survives a reboot.
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl enable nginx
You can test the Nginx web server by opening your web browser and browsing to the server’s localhost or IP address. If you are working on the server itself, use localhost. If you are connecting from another computer, use the server’s IP address.
http://localhost

When you see "Welcome to nginx!" the Nginx HTTP server has been installed. If the page does not load from another computer, check that Nginx is running and that your firewall allows port 80.
Additional help on installing Nginx on Ubuntu is in the link below.
Install MariaDB database server on Ubuntu
To install MariaDB on your Ubuntu 24.04 server, open your terminal and run the commands sudo apt update and sudo apt install mariadb-server. This sets up the database system that WordPress uses to store posts, pages, settings, and user data.
To install and use the MariaDB database server, use the instructions below.
Open the Ubuntu terminal and run the commands below to install the MariaDB database server.
sudo apt update sudo apt install mariadb-server
Once the MariaDB database server is installed, use the commands below to stop, start, and enable the MariaDB server to start automatically when the server boots. As with Nginx, the service usually starts on its own after installation, so "start" may change nothing. That is fine.
sudo systemctl stop mariadb sudo systemctl start mariadb sudo systemctl enable mariadb
Run the following commands to validate and test if the MariaDB database server is installed successfully.
sudo mariadb
Once you run the commands above, it will log you onto the MariaDB console and display a message similar to the one below. The prompt changes to the MariaDB prompt, which means you are now typing database commands, not shell commands.
Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 32 Server version: 10.11.2-MariaDB-1 Ubuntu 23.04 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [(none)]>
The message tells you that the server is installed successfully. Leave the MariaDB console when you are done checking it. The next section logs you back in to create the WordPress database.
Additional help on installing MariaDB.
- How to install MariaDB on Ubuntu Linux
- MariaDB without password prompt
Create a WordPress database
To create a WordPress database in MariaDB, log into the database shell using sudo mysql and run the SQL commands to create your database and user. On Ubuntu, the MariaDB root account is tied to the system root user, so sudo is enough and no database password is asked. This gives WordPress secure access to store and read your site data.
As part of the setup, we will create a database named wordpressdb and a corresponding user account called wordpressdbuser. WordPress will connect with this account, so it never needs the root account.
Finally, we'll grant the wordpressdbuser full access to the wordpressdb database. That access applies only to this one database, so other databases on the server stay protected.
All the database steps above can be done using the commands below:
But first, log on to the MariaDB database server:
sudo mariadb
Then run the commands below to complete the steps. Each SQL statement ends with a semicolon, and MariaDB reports a success message after each one.
CREATE DATABASE wordpressdb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER wordpressdbuser@localhost IDENTIFIED BY 'type_your_password_here';
GRANT ALL ON wordpressdb.* TO wordpressdbuser@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
Ensure to replace 'type_your_password_here' with your password. Pick a long, unique password and keep it somewhere safe, because you will type it into the WordPress setup screen later. If you change the database or user name, use the same names in the setup screen.
Install PHP-FPM on Ubuntu
PHP-FPM is needed to run WordPress because WordPress is built using PHP. Nginx cannot run PHP itself. It passes PHP requests to PHP-FPM, which runs the code and sends the result back.
Run the commands below to install PHP-FPM. Ubuntu 24.04 ships PHP 8.3 by default. Note the PHP version that gets installed, because the Nginx server block later in this guide must point to the matching PHP-FPM socket.
sudo apt install php-fpm php-intl php-mysql php-curl php-cli php-zip php-xml php-gd php-common php-mbstring php-xmlrpc php-json php-sqlite3 php-soap php-zip
Additional help on installing PHP
Download WordPress files
To download WordPress files on your Ubuntu server, switch to the /tmp/ directory and use the curl or wget command to grab the latest release package. Then, extract the files and move them to your web server folder so Nginx can load your site. Downloading to /tmp/ keeps the archive out of your web root.
First, navigate to the /tmp/ directory and download WordPress files. After unzipping the file, move the content into the WordPress folder in the Nginx root directory. Make sure the files end up directly inside that folder, not in a second nested "wordpress" folder, or Nginx will not find them.
The final step is to change the permissions. This will allow the Nginx web server to safely interact with the files, ensuring a secure environment for your WordPress installation. On Ubuntu, Nginx and PHP-FPM run as the www-data user, so that user needs to own the files. If the permissions are wrong, WordPress cannot write its configuration file and will later ask you to create it by hand.
cd /tmp/
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo mv wordpress /var/www/wordpress
sudo chown -R www-data:www-data /var/www/wordpress/
Once you have completed all the above steps, continue below to configure the Nginx web server to serve the WordPress content.
Run the commands below to create a Nginx virtual host file for WordPress. This opens a new, empty file in a text editor. You paste the server block into it in the next step.
sudo nano /etc/nginx/sites-available/wordpress.conf
Then, copy and paste the content block below into the Nginx server block. Before you save, check two values. Replace the server name with your own domain name or server IP address. Confirm that the PHP-FPM socket path matches the PHP version you installed (8.3 on a default Ubuntu 24.04 install).
server {
listen 80;
listen [::]:80;
root /var/www/wordpress;
index index.php;
server_name wordpress.example.com www.wordpress.example.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}Save the file.
To make your WordPress website accessible, run the commands to enable the virtual host configuration file and restart the Nginx web server. This action ensures Nginx loads your website's settings and begins serving your WordPress content correctly to visitors. If the restart fails, read the error message it prints. A typo in the server block is the most common cause, such as a missing semicolon or a wrong path.
sudo ln -s /etc/nginx/sites-available/wordpress.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service
Setup Let’s Encrypt SSL/TLS for WordPress
To set up Let's Encrypt SSL for WordPress on Ubuntu, install Certbot and run the Nginx plugin command to generate your free security certificate. This enables HTTPS, encrypts visitor data, and protects your site from common security threats. You need a real domain name that points to your server's public IP address, and ports 80 and 443 must be reachable from the internet. Let's Encrypt will not issue a certificate for a bare IP address or a local test setup. If you are only testing, you can skip this step and add HTTPS later.
Please read the post below for additional resources on installing and creating Let's Encrypt SSL certificates for Nginx.
How to set up Let’s Encrypt SSL certificate for Nginx on Ubuntu Linux
Once you have restarted the Nginx web server, open your browser and browse to the server hostname or IP address defined in the Nginx server block. Use the same name you put in the server block. A different name may land on the default Nginx page instead of WordPress.
http://wordpress.example.com
A WordPress installation wizard page should appear. Select the installation language and continue to the next page. If you see the default Nginx page, a "502 Bad Gateway" error, or a file download prompt instead, go back and check the server block and the PHP-FPM socket path.

Next, click the Let's go button to begin the installation process. WordPress shows a short list of the information it needs. That is the database name, user name, password, and host.

Type the database name, account name, and password on the next screen. Use the values you created earlier: wordpressdb, wordpressdbuser, and your password. Leave Database Host as localhost, since the database runs on the same server. Then, click Submit. If WordPress reports that it cannot connect to the database, recheck the name, user, and password for typos.

Next, click the "Run the installation" button to install WordPress files. A successful connection to the database brings up this button.

Next, type in the site title, admin account, email address, and password. Then, click "Install WordPress." Choose a strong password for the admin account, and use an email address you can reach, because WordPress uses it for password resets. You can change the site title later under Settings in the dashboard.

Your WordPress site should be set up and ready to use. A success message appears with a button to log in. Sign in with the admin account you just created to reach the dashboard.

That should do it!
Conclusion:
- WordPress with Nginx support on Ubuntu 24.04 enhances website performance, scalability, and security.
- Nginx's high performance, low memory usage, and customizable configuration make it an excellent choice for serving WordPress sites.
- Integrating Nginx with WordPress allows efficient management of tasks such as caching, load balancing, and SSL termination.
- The combination of Nginx, MariaDB, and PHP-FPM forms a reliable system for running WordPress on Ubuntu.
- Setting up Let's Encrypt SSL/TLS certificates for Nginx further enhances the security of the WordPress installation.
This guide offers a step-by-step approach to setting up WordPress with Nginx support on Ubuntu, ensuring a robust and secure foundation for your website. Once the site is running, keep Ubuntu and WordPress updated, and back up both the site files and the database on a regular schedule.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!