LinuxPublished on August 27, 202610 min read

How to install WordPress on a Linux VPS

A WordPress VPS puts you in charge of every layer of your site, from Nginx to PHP. This guide installs WordPress on a Linux VPS running Debian 13 or Ubuntu 24.04, with Nginx, PHP-FPM and MariaDB. It covers the database, WP-CLI, the Nginx vhost, HTTPS, OPcache and how to protect the admin area.

Prepare the VPS

The commands in this guide target Debian 13 and PHP 8.4. On Ubuntu 24.04, replace 8.4 with 8.3 everywhere, including in the PHP-FPM socket name. Log in over SSH with an account that has sudo rights. The guide Set up an SSH key on a Linux VPS secures that access.

PHP and MariaDB versions

According to its Requirements page, WordPress recommends PHP 8.3 or newer and MariaDB 10.11 or newer. MySQL 8.0 works too. Both systems in this guide ship these versions in their repositories.

ComponentRecommended by WordPressDebian 13Ubuntu 24.04
PHP8.3 or newer8.48.3
MariaDB10.11 or newer11.810.11

VPS resources

The table gives the recommended RAM for each traffic level. It assumes a typical site with a caching plugin, such as WP Super Cache or W3 Total Cache.

Monthly trafficRecommended RAM
Up to 10,000 visits4 GB
10,000 to 50,000 visits8 GB
Over 50,000 visits16 GB or more

A WooCommerce store, or a site with many visitors at once, needs more memory. Also keep enough disk space for media and backups.

Install Nginx, PHP and MariaDB

Install the three building blocks and the PHP extensions WordPress uses. The guide Install Nginx and PHP-FPM on a Linux VPS explains how to tune this stack.

# Nginx, MariaDB and curl
sudo apt update
sudo apt install -y nginx mariadb-server curl

# PHP-FPM and its WordPress extensions (Ubuntu 24.04: replace 8.4 with 8.3)
sudo apt install -y php8.4-fpm php8.4-cli php8.4-mysql php8.4-curl \
    php8.4-gd php8.4-imagick php8.4-mbstring php8.4-xml \
    php8.4-zip php8.4-intl php8.4-opcache
PackageWhat WordPress uses it for
php8.4-fpmRuns PHP for Nginx
php8.4-cliCommand-line PHP, used by WP-CLI
php8.4-mysqlConnection to MariaDB, required
php8.4-curlHTTP requests to other servers
php8.4-gd, php8.4-imagickResizing uploaded images
php8.4-mbstringUTF-8 text
php8.4-xmlRSS feeds and content import
php8.4-zipUnpacking plugins and themes
php8.4-intlLanguages and regional formats
php8.4-opcacheCache for compiled PHP code

Then check PHP and the three services. The first command must show PHP 8.4 along with Zend OPcache. The other must answer active three times.

php -v
systemctl is-active nginx mariadb php8.4-fpm

If you use a firewall, open ports 80 and 443 as shown in How to set up the UFW firewall on Ubuntu or Debian.

Point the domain to the VPS

The site needs a domain name. Create two A records pointing to the address shown under Main IP on the VPS page. One uses the name @ for the domain itself, the other the name www.

If your domain is with OuiHeberg, open the domain's DNS zone tab and click Add. In the Add a record window, pick Type A, then fill in Name and Value. The guide How to edit the DNS records of your domain explains each field.

Add a record window with the Type, Name, Value and TTL fields


Create the database

WordPress needs its own database and its own user. Don't use the MariaDB root account for the site.

On a fresh install, first run the MariaDB security script. Among other things, it removes the anonymous accounts and the test database if they exist.

sudo mariadb-secure-installation

Then log in to MariaDB. On Debian and Ubuntu, sudo is enough, with no password.

sudo mariadb -u root

Create the database, the user and its privileges. Change the example password. The command openssl rand -hex 24 generates a strong one.

CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

The utf8mb4 character set is the one recommended in the WordPress installation docs. It handles all of Unicode, emojis included.


Install WP-CLI

WP-CLI is the official command-line tool for WordPress. It installs, configures and updates a site without a browser. Here is the method from its documentation.

# Download WP-CLI
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

# Check that the file works
php wp-cli.phar --info

# Make it executable and install it as wp
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

# Check the installation
wp --info

The last command shows the WP-CLI version and the PHP version it runs on.

WP-CLI is optional. You can also download the archive from wordpress.org/download, unpack it into the site folder and fill in wp-config.php by hand. WP-CLI makes updates much easier, though.


Install WordPress with WP-CLI

Download WordPress

Create the site folder and give it to www-data, the user that runs Nginx and PHP-FPM. WP-CLI then runs under that account. Replace example.com with your domain in every command.

sudo mkdir -p /var/www/example.com
sudo chown -R www-data:www-data /var/www/example.com
cd /var/www/example.com
sudo -u www-data wp core download --locale=en_US

The --locale option sets the site language.

Create the wp-config.php file

Stay in the site folder. Use the database name, user and password you created earlier.

sudo -u www-data wp config create \
  --dbname=wordpress_db \
  --dbuser=wordpress_user \
  --dbpass=strong_password \
  --dbhost=localhost \
  --dbcharset=utf8mb4 \
  --locale=en_US

WP-CLI tests the database connection, then writes wp-config.php with fresh security keys.

To keep the password out of your shell history, replace --dbpass=… with --prompt=dbpass. WP-CLI then asks you for it.

Run the installation

This command creates the tables and the administrator account. Replace each value with your own.

sudo -u www-data wp core install \
  --url=https://example.com \
  --title="My site" \
  --admin_user=your_username \
  --admin_password=admin_strong_password \
  --admin_email=contact@example.com

Avoid admin as the username, since it is the first name bots try. Pick a password of at least 16 characters, with capitals, digits and symbols. The https:// address will answer once HTTPS is on, two steps further down.


Configure Nginx for WordPress

WordPress needs a few rules of its own in the Nginx vhost, for permalinks and security. Create the site file.

sudo nano /etc/nginx/sites-available/example.com

Paste this configuration. On Ubuntu 24.04, the socket becomes php8.3-fpm.sock.

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php;

    # Maximum upload size (keep it in line with PHP)
    client_max_body_size 64M;

    # WordPress permalinks
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # No PHP scripts in the media folder (keep it before the PHP block)
    location ~* ^/wp-content/uploads/.*\.php$ {
        deny all;
    }

    # PHP handled by PHP-FPM (Ubuntu 24.04: php8.3-fpm.sock)
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # Block access to sensitive files
    location ~ /\.(ht|git|env) {
        deny all;
    }

    # Block xmlrpc.php if you don't use it
    location = /xmlrpc.php {
        deny all;
    }

    # Browser cache for static files
    location ~* \.(css|js|jpg|jpeg|png|gif|webp|avif|ico|svg|woff|woff2)$ {
        expires 30d;
        add_header Cache-Control "public, no-transform";
    }
}
  • try_files $uri $uri/ /index.php?$args; makes permalinks work. Without it, every page except the home page returns a 404 error.

  • client_max_body_size sets the maximum upload size. Use the same value in PHP, further down.

  • The wp-content/uploads block refuses any PHP script dropped into the media folder.

  • The xmlrpc.php block closes a door that bots target a lot. Remove it if a plugin or service needs it, such as Jetpack.

Enable the site, test the configuration, then reload Nginx. The test must print "syntax is ok" and "test is successful".

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Enable HTTPS

Both A records must already point to the VPS. Certbot then gets a Let's Encrypt certificate and adds it to the vhost. If it offers to redirect HTTP to HTTPS, accept.

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

# Test the automatic renewal
sudo certbot renew --dry-run

The site now answers on https://example.com, and the admin area on https://example.com/wp-admin. The certificate renews by itself. The guide Certbot: install a Let's Encrypt SSL certificate on a VPS covers the other cases.


Tune PHP for WordPress

Tune OPcache

OPcache keeps compiled PHP code in memory. Each page is then built faster. Open its settings file.

sudo nano /etc/php/8.4/fpm/conf.d/10-opcache.ini

Below the zend_extension=opcache.so line, check these settings or add them.

opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2
opcache.validate_timestamps=1

These are the PHP defaults, according to the OPcache documentation. They are enough for one site. With several sites on the VPS, raise opcache.memory_consumption.

Keep opcache.validate_timestamps=1. WordPress rewrites its own PHP files during updates. With 0, PHP would keep running the old code.

Raise the upload size limit

Match the PHP upload limit to the client_max_body_size of the vhost.

sudo nano /etc/php/8.4/fpm/php.ini

Change these three lines, or add them.

upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120

Restart PHP-FPM to apply both files.

sudo systemctl restart php8.4-fpm

In the admin area, Tools › Site Health then flags any missing PHP extension.


Protect the WordPress admin

These settings target the WordPress login pages. The location blocks go inside the server block of the vhost. After each change, test and reload Nginx with the commands at the end of this section.

Restrict wp-admin to your IP address

This setting is optional. It helps if you manage the site from a fixed IP address. Any other address is then denied wp-admin, whatever the account. Replace 203.0.113.10 with yours.

# admin-ajax.php stays open, the public site uses it
location = /wp-admin/admin-ajax.php {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

# wp-admin restricted to your IP address, PHP scripts included
location ^~ /wp-admin/ {
    # Replace with your IP address
    allow 203.0.113.10;
    deny all;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

The ^~ modifier matters. Without it, PHP scripts in wp-admin would go through the general PHP block and escape the restriction. Some plugins also call admin-post.php from the public site. Open it the same way if a form stops working.

Limit login attempts on wp-login.php

First declare a rate-limiting zone. Files in /etc/nginx/conf.d/ are read inside the http block of nginx.conf.

sudo nano /etc/nginx/conf.d/wp-login-limit.conf

The file holds a single line.

limit_req_zone $binary_remote_addr zone=login:10m rate=1r/m;

Then add this block to the site vhost.

location = /wp-login.php {
    limit_req zone=login burst=3 nodelay;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Test the configuration, then reload Nginx.

sudo nginx -t
sudo systemctl reload nginx

An IP address can send a few requests in a row, then only one per minute. Beyond that, Nginx answers with a 503 error. The Fail2ban nginx-limit-req jail can then ban the addresses that keep trying. The guide Install and configure Fail2ban explains how to turn it on.


Update WordPress

WP-CLI updates the core, plugins and themes. Take a backup first, as explained in the next section.

cd /var/www/example.com
sudo -u www-data wp core update
sudo -u www-data wp core update-db
sudo -u www-data wp plugin update --all
sudo -u www-data wp theme update --all

# Update WP-CLI itself
sudo wp cli update

The wp core update-db command upgrades the database after a new WordPress release. The last line updates WP-CLI itself.


Back up the site

A WordPress site has two parts, its files and its database. Back up both, to a folder outside the site.

# Backup folder, outside the site and for root only
sudo mkdir -p /var/backups/wordpress
sudo chmod 700 /var/backups/wordpress

# Database
cd /var/www/example.com
sudo -u www-data wp db export - | sudo tee /var/backups/wordpress/db-$(date +%F).sql > /dev/null

# Site files
sudo tar -czf /var/backups/wordpress/files-$(date +%F).tar.gz -C /var/www example.com

Never put the database export in the site folder. Anyone could download it, with the accounts and their password hashes.

Put these commands in a script that cron runs every day. These copies stay on the VPS. To keep one elsewhere, follow the guide Rclone: expert guide for cloud synchronization.

Automatic backup of the whole VPS is a paid option. It makes a full copy of the server every night and stores it outside the server. You choose how many copies to keep. Restores are started from the Backups tab of the VPS page. The guide How to set up automatic VPS backups explains how to add it.


Go further


Need help?

Open a ticket from Tickets › Open a Ticket, or from the Contact support tile at the bottom of the VPS page. You can also ask your question on the OuiHeberg Discord.

Was this article helpful?

190 views
Share this article
Need a Linux VPS?

Root access, your choice of distribution and management from the OuiHeberg client area.

View plans →

Related Articles