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:
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.
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
Open your domain in a browser. The WordPress installer launches automatically:
wordpress), username (wordpressuser), password, and leave the host as localhostOnce 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.