How to install WordPress on a VPS
From a fresh Ubuntu server to a live, secure WordPress site.
Before you start
You need a VPS with Ubuntu, at least 2 GB of RAM, a domain name pointed to the server and SSH access. Read how to point a domain to a VPS first if you have not done it yet.
Step 1: Update and secure the server
Log in with SSH, run apt update and apt upgrade, create a non-root user with sudo rights, set up SSH keys and enable the UFW firewall for SSH, HTTP and HTTPS.
Step 2: Install Nginx, PHP and MariaDB
Install nginx, php-fpm with the common extensions (mysql, curl, gd, mbstring, xml, zip, intl) and mariadb-server. Run mysql_secure_installation to set a root password and remove test data.
Step 3: Create a database
Open the MariaDB shell and create a database and a user for WordPress with a strong password. Grant the user all privileges on that database only, and flush privileges.
Step 4: Download WordPress
Download the latest WordPress archive from wordpress.org, extract it into /var/www/yourdomain.com, copy wp-config-sample.php to wp-config.php and enter the database details and fresh secret keys. Set file ownership to the web server user.
Step 5: Configure Nginx
Create a server block with your domain as server_name and the WordPress folder as root. Use try_files $uri $uri/ /index.php?$args and pass PHP requests to php-fpm. Test with nginx -t and reload.
Step 6: Add HTTPS
Install Certbot, run it for your domain and www, and let it redirect HTTP to HTTPS. Then complete the WordPress installer in your browser and choose an admin name that is not "admin".
Speed and security tips
Turn on PHP OPcache, add a page-cache plugin, use Redis for object caching on busy sites, keep WordPress, themes and plugins updated, limit login attempts and take daily backups. On an NVMe VPS with dedicated CPU, these steps give you a fast site.
Frequently asked questions
How much RAM does WordPress need?
A small site is fine on 2 GB. Shops and sites with heavy plugins are happier with 4 GB or more.
Nginx or Apache for WordPress?
Both work. Nginx with PHP-FPM is a popular choice for speed and low memory use.
How do I secure WordPress?
Keep core, themes and plugins updated, use strong passwords and two-factor login, limit login attempts and take regular backups.
Can I move an existing WordPress site?
Yes. Copy the files and the database, update wp-config.php, test with a hosts-file entry and then change DNS.
Related pages
Keep going with these pages.
Put it into practice
Deploy a VPS in the location closest to your users.