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

Install Anaconda on Ubuntu 18.04: Python Data Science Setup Guide

Anaconda is the most widely used Python distribution for data science and machine learning. It bundles…

4 minutes ago

Install Magento 2 on Ubuntu 18.04 with Composer and Nginx

Magento is an enterprise-class, open-source e-commerce platform written in PHP. It is built for merchants who…

54 minutes ago

Install WildFly on Ubuntu 18.04: Java App Server Setup Guide

Install WildFly on Ubuntu 18.04: Java App Server Setup GuideWildFly (formerly JBoss) is an open-source,…

1 hour ago

Install OpenCart on Ubuntu 18.04 with Nginx and PHP 7.2

OpenCart is a free, open-source PHP e-commerce platform used by hundreds of thousands of merchants worldwide.…

1 hour ago

Install Drupal on Ubuntu 18.04 with Composer, Nginx, and PHP

Drupal is one of the most widely used open-source CMS platforms in the world. Written in…

1 day ago

Set Up an FTP Server on Ubuntu 18.04 with vsftpd and SSL

FTP (File Transfer Protocol) is a standard network protocol for transferring files between a local client…

1 day ago