How To

Install WordPress on Ubuntu 18.04 with Nginx and PHP 7.2

WordPress is the most popular open-source CMS in the world, powering over 40% of all websites on the internet. It runs on PHP and MySQL and works with thousands of free and premium plugins and themes. With WordPress, you can build a personal blog, a business website, or a fully featured online store using WooCommerce.

This guide shows you how to install WordPress on Ubuntu 18.04 using Nginx, PHP 7.2, and MySQL on a LEMP stack with HTTPS.

Prerequisites:

  • A domain name pointing to your server’s public IP
  • Nginx installed with a Let’s Encrypt SSL certificate
  • Sudo access

Install WordPress on Ubuntu: Create the Database and Install PHP

Update the system packages:

bashsudo apt updatesudo apt upgrade

Set up the MySQL database. Log into MySQL and create the database, user, and permissions in one session:

bashmysql -u root -p
sqlCREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'change-with-strong-password';FLUSH PRIVILEGES;EXIT;

Using utf8mb4 instead of basic utf8 gives full Unicode support including emoji characters. This matters if your site allows comments or other user-generated content.

Install PHP 7.2 with the extensions WordPress requires. Nginx cannot process PHP natively, so we install PHP-FPM to handle PHP execution as a separate process:

bashsudo apt install php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

PHP-FPM starts automatically after installation.

Download WordPress and Configure Nginx

Create the document root and download the latest WordPress release:

bashsudo mkdir -p /var/www/html/example.comcd /tmpwget https://wordpress.org/latest.tar.gztar xf latest.tar.gzsudo mv /tmp/wordpress/* /var/www/html/example.com/sudo chown -R www-data: /var/www/html/example.com

WordPress always serves latest.tar.gz at that URL, so this downloads the current stable release automatically.

Create an Nginx server block at /etc/nginx/sites-available/example.com. The configuration needs three server blocks: one to redirect HTTP to HTTPS, one to redirect www to the non-www domain, and a main HTTPS block. The main block sets root to /var/www/html/example.com, uses try_files $uri $uri/ /index.php?$args so WordPress pretty permalinks work correctly, and passes PHP requests to unix:/run/php/php7.2-fpm.sock. Add a location block to serve static assets like images, CSS, and JavaScript directly without passing them to PHP.

Replace example.com with your domain and update the SSL certificate file paths.

Enable the site, test the configuration, and restart Nginx:

bashsudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl restart nginx

Complete the WordPress Installation via Web Wizard

Open your domain in a browser. The WordPress installer launches automatically:

  1. Select your language and click Continue
  2. Click Let’s go! on the database information page
  3. Enter your database name (wordpress), username (wordpressuser), password, and leave the host as localhost
  4. Click Run the Installation
  5. Enter a site title, admin username — avoid “admin” since it is the first username attackers try — a strong password, and your email address
  6. Click Install WordPress

Once complete, click Log In. You will be redirected to the WordPress administration dashboard, where you can install themes under Appearance > Themes, add plugins under Plugins > Add New, and create your first posts.

WordPress is now installed on your Ubuntu 18.04 server with Nginx. Visit First Steps with WordPress to learn how to start publishing. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

Change User Password in Ubuntu: Command Line and GNOME GUI

Using a strong, unique password for every account is one of the most effective security…

20 hours ago

Enable and Disable the Root Account in Ubuntu: Full Guide

Ubuntu locks the root account by default. New users often wonder what the root password…

20 hours ago

Configure Netplan on Ubuntu: DHCP, Static IP, Wi-Fi, and Bridges

Since Ubuntu 17.10, networking is configured with Netplan rather than the older /etc/network/interfaces file. You write a…

20 hours ago

Install Docker on Ubuntu 24.04: Repository, Compose, and Non-Root

Docker is an open-source containerization platform that packages an application and everything it depends on…

20 hours ago

update-alternatives on Ubuntu: Manage Default Program Links

When two or more installed programs provide the same command name, the system needs a…

1 day ago

Install Docker on Ubuntu 26.04: Official Repository Setup Guide

Install Docker on Ubuntu 26.04: Official Repository Setup GuideDocker is an open-source container platform that…

3 days ago