Self-host WordPress on a VPS
This page contains affiliate links. If you buy through them, this site may earn a commission at no extra cost to you. How affiliate links work here.
To self host WordPress, rent a small Linux VPS, run the official wordpress and mysql Docker images with Docker Compose, and put Caddy in front for automatic HTTPS. The setup takes an hour. The real work starts after that: updates, backups, and keeping the login page away from the bots that hit every WordPress site.
If you would rather never think about a server, managed WordPress hosting is the better buy, and this page says when further down.
At a glance
| Item | Choice in this guide |
|---|---|
| Server | Ubuntu VPS, 2 GB RAM or more (general advice) |
| WordPress | Official wordpress image (Apache + PHP), latest release 7.1.5 as of 2026-12-02 |
| Database | Official mysql image, tag 8.4 |
| HTTPS | Caddy on the host, automatic certificates |
| Admin access | /wp-login.php and /wp-admin/ limited to your IP or VPN, plus two-factor login |
| Updates | WordPress auto-updates, plugin updates in the dashboard, docker compose pull for the images |
| Backups | mysqldump from the database container, a tarball of the WordPress volume, copied off the server |
What WordPress needs
The WordPress requirements page recommends PHP 8.3 or greater, MySQL 8.4 or greater or MariaDB 10.11 or greater, and HTTPS support. It names Apache or Nginx as the recommended web servers. The download page listed WordPress 7.1.5 as the current release when this page was checked, released on November 18, 2026.
The Docker image covers PHP and Apache for you. You choose the database version, which matters below.
For the server, any mainstream VPS provider works. A 1 GB plan can run WordPress and MySQL for a small blog, but 2 GB leaves headroom for MySQL 8.4, PHP workers and a cache plugin; that is general advice, not a published minimum. The best VPS for self-hosting comparison covers providers in more depth, and the VPS vs home server vs managed hosting guide explains why a public website belongs on a VPS rather than at home.
Step 1: Install Docker on the VPS
Create an Ubuntu LTS server at a provider such as DigitalOcean, Vultr, Hostinger or Hetzner Cloud, add your SSH key, and point an A record (and AAAA if you have IPv6) for example.org at the server’s address.
Install Docker Engine from Docker’s own repository by following Install Docker Engine on Ubuntu. Its apt step installs the Compose plugin with the engine:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
That page also carries a warning worth reading twice: ports you publish from Docker bypass ufw and firewalld rules. A host firewall will not save you from a container port you exposed by mistake, which is why the next step binds WordPress to localhost.
Step 2: The Compose file
This is the compose.yaml example from the official wordpress image page, with three changes: passwords replaced with CHANGE_ME, the port bound to 127.0.0.1, and the database tag moved from mysql:8.0 to mysql:8.4 to match the WordPress recommendation. The mysql image page no longer lists 8.0 among its supported tags.
services:
wordpress:
image: wordpress
restart: always
ports:
- 127.0.0.1:8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: CHANGE_ME
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress:/var/www/html
db:
image: mysql:8.4
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: CHANGE_ME
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
volumes:
wordpress:
db:
Use the same long random password in both CHANGE_ME slots. The MySQL image creates exampledb and exampleuser on first start and gives root a random password you never need. The port publishing docs confirm that with a 127.0.0.1 address only the Docker host can reach the port; without it, Docker publishes on every interface.
Start the stack from the directory holding the file:
docker compose up -d
The image documentation notes that when any WORDPRESS_* variable is set, the generated wp-config.php includes a check for the X-Forwarded-Proto header, so WordPress knows it is behind an HTTPS proxy. You can see the code in wp-config-docker.php. That avoids the redirect loop the WordPress HTTPS docs warn about.
Step 3: HTTPS with Caddy
Install Caddy from its official apt repository using the commands on the Caddy install page. Those commands add Caddy’s signing key and package source, then install the caddy package, which starts and runs as a systemd service named caddy.
Replace the contents of /etc/caddy/Caddyfile with the domain form of the reverse proxy quick-start:
example.org
reverse_proxy localhost:8080
Reload Caddy, as described in Keep Caddy running:
sudo systemctl reload caddy
Caddy fetches a publicly trusted certificate on its own, as long as DNS points at the server and ports 80 and 443 are open. The reverse_proxy docs state that it sets X-Forwarded-Proto by default, which is what the WordPress config checks for.
Open https://example.org and finish the installer right away. Until you do, anyone who finds the page first can claim the site (general advice: do not leave a fresh install sitting unconfigured). Pick an admin username other than admin and a strong password.
Step 4: Keep wp-admin off the open internet
Public WordPress sites routinely see automated password guessing against /wp-login.php (general advice). Treat the admin area like any other admin panel and limit who can reach it.
The cleanest option is an IP allowlist in Caddy. This builds on the remote_ip, not and abort examples in the Caddy request matchers docs; matchers inside one named set must all match. Replace 203.0.113.10 with your static IP or your VPN’s address range:
example.org {
@denied {
path /wp-login.php /wp-admin/*
not path /wp-admin/admin-ajax.php
not remote_ip 203.0.113.10
}
abort @denied
reverse_proxy localhost:8080
}
The admin-ajax.php exception matters. The Hardening WordPress guide warns that protecting /wp-admin/ can break it, and many themes and plugins call it from public pages.
If you do not have a fixed IP, a VPN such as WireGuard on the server lets you allowlist the VPN subnet instead (general advice). If neither works for you, at least turn on two-factor login. The Two Factor plugin, listed under the WordPress.org account in the plugin directory, supports authenticator apps, email codes and backup codes. The hardening guide itself recommends two-step authentication.
Two more items from the hardening guide fit naturally in this setup:
- Disable the built-in file editor. The guide recommends
DISALLOW_FILE_EDIT. The image’sWORDPRESS_CONFIG_EXTRAvariable is evaluated insidewp-config.php, so add it to thewordpressservice’senvironmentand rundocker compose up -dagain:
WORDPRESS_CONFIG_EXTRA: |
define( 'DISALLOW_FILE_EDIT', true );
- Use one database and one database user per site. The Compose file already does this. The guide advises against revoking the user’s schema privileges, because updates and plugins need them.
Also delete plugins and themes you do not use. Every inactive plugin is still code on your server.
Step 5: Updates
There are three layers, and they update separately.
WordPress core. According to the upgrading docs, minor releases (maintenance and security) and translations install automatically by default, and new installs since WordPress 5.6 also take major updates automatically. Leave that on. The docs strongly discourage AUTOMATIC_UPDATER_DISABLED.
Plugins and themes. These do not update themselves by default, except in special cases pushed by WordPress.org. Check the Updates screen weekly, or enable auto-updates for plugins you trust from the Plugins screen. The same docs show the auto_update_plugin filter for doing it in code.
The containers. The image docs are explicit: the first install comes from the image, but afterwards WordPress manages itself inside the /var/www/html volume. Pulling a newer wordpress image updates PHP and Apache, not your WordPress files. Refresh both images regularly:
docker compose pull
docker compose up -d
Pin the database to a release series, as the mysql:8.4 tag does, so a pull never jumps you to a new MySQL version series without warning. Take a backup before every pull.
Step 6: Backups
You need two things: the database and the WordPress volume, which holds wp-content (uploads, plugins, themes) and the generated wp-config.php.
Database. The mysql image docs dump with mysqldump inside the container. This version uses the WordPress user’s credentials from the container’s own environment instead of root. -T turns off TTY allocation so the output redirects cleanly (compose exec docs), and --no-tablespaces avoids the extra PROCESS privilege the mysqldump manual says a full dump needs:
docker compose exec -T db sh -c 'exec mysqldump --no-tablespaces --single-transaction -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE"' > wordpress-db.sql
To restore, the same image docs pipe the file back into the mysql client:
docker compose exec -T db sh -c 'exec mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE"' < wordpress-db.sql
Files. The Docker volumes docs back up a volume by mounting it into a throwaway container and writing a tar file to the current directory. docker compose ps -q wordpress prints the container ID:
docker run --rm --volumes-from $(docker compose ps -q wordpress) -v $(pwd):/backup ubuntu tar cvf /backup/wordpress-files.tar /var/www/html
Off the server. A backup on the same VPS dies with the VPS. Copy both files to another machine or object storage on a schedule, keep several dated copies, and restore one onto a test server now and then. The hardening guide also suggests encrypting backups and keeping snapshots from before any compromise. Provider snapshots are a useful extra, not a replacement.
Cost: VPS versus managed WordPress
| Option | What you get | Price | Notes |
|---|---|---|---|
| DigitalOcean Basic Droplet | 1 vCPU, 2 GiB RAM, 50 GiB SSD | $12.00/mo | 2,000 GiB transfer |
| Vultr Regular Performance | 1 vCPU, 2 GB RAM, 55 GB SSD | $10.00/mo | 2 TB bandwidth |
| Hetzner Cloud CPX12 | 1 vCPU, 2 GB RAM, 40 GB NVMe | from €9.99/mo excl. VAT | €9.99 in Helsinki, €11.99 in Germany, both excl. VAT |
| Hostinger KVM 1 VPS | 1 vCPU, 4 GB RAM, 50 GB NVMe | $11.99/mo | Regular price on a 24-month prepay |
| Hostinger Premium (managed WordPress) | 3 sites, 20 GB SSD, weekly backups | $10.99/mo | Regular price on a 12-month term |
| Hostinger Cloud Startup (managed WordPress) | Unlimited sites, 100 GB NVMe, daily and on-demand backups | $25.99/mo | Regular price on a 12-month term |
Prices checked 2026-12-02 on each provider’s pricing page. Hostinger rows show the regular (renewal) price its pages list for the stated term, paid upfront; Hostinger often runs discounts below these.
The table above shows that a basic managed plan costs about the same as a small VPS on sticker price. What the VPS buys you is control: any plugin, any PHP setting, other apps on the same server, and no vendor lock-in. What it costs you is an hour or two a month of your own time. Run your own numbers, including that time and backup storage, in the self-hosting cost calculator.
When managed WordPress hosting is the better choice
Pick managed hosting, such as Hostinger’s managed WordPress plans or another host you trust, when any of these apply:
- The owner is not technical. If the person responsible for the site will never SSH into a server, nobody will apply the image updates or test a restore.
- The site is business-critical. A shop, a booking site or a client’s site needs someone on call for outages and malware cleanup. Managed hosts include that; on your own VPS it is you.
- You have no time for updates. Outdated plugins are a common way into WordPress sites (general advice). If weekly checks will not happen, let a host do them.
Self-hosting makes sense when you want to learn, run several small sites on one server, or need control a managed host will not give. If WordPress is more than you need, the guide to self-hosting a website covers simpler static options, and the hosting hub collects the rest of the server guides.
Frequently asked questions
- Does pulling a newer wordpress image update WordPress itself?
- No. The image documentation says the first install comes from the image, but after that WordPress manages itself inside the /var/www/html volume. Pulling a new image updates PHP and Apache in the container; WordPress core, plugins and themes update through WordPress's own updater.
- Which PHP and database versions does WordPress recommend?
- As of December 2026, wordpress.org recommends PHP 8.3 or greater and MySQL 8.4 or greater or MariaDB 10.11 or greater, plus HTTPS support. The official Docker example still uses MySQL 8.0, so this guide changes that one tag to mysql:8.4.
- Why bind WordPress to 127.0.0.1 instead of opening port 8080?
- Docker publishes ports on all interfaces by default, and the Docker docs warn that published ports bypass ufw and firewalld rules. Binding to 127.0.0.1 means only Caddy on the same host can reach the plain-HTTP port, so all public traffic goes through HTTPS.
- Can I block wp-admin completely from the internet?
- Mostly. Restricting /wp-login.php and /wp-admin/ to your own IP or VPN address works, but leave /wp-admin/admin-ajax.php reachable, because themes and plugins call it from public pages. WordPress's hardening guide warns that protecting wp-admin can break admin-ajax.php.
- When is managed WordPress hosting the better choice?
- When nobody on the team will log in to a Linux server every week, when the site makes money or carries a client's reputation, or when you want someone else on the hook for updates, backups and malware cleanup. Self-hosting is cheaper per site only if your time is free.
Sources, checked December 2, 2026
- Docker Hub: wordpress official image (compose example, variables, updates)
- docker-library/wordpress: wp-config-docker.php (X-Forwarded-Proto handling)
- Docker Hub: mysql official image (tags, dump and restore)
- WordPress.org: Requirements
- WordPress.org: Download
- WordPress.org: Releases
- WordPress Advanced Administration: Hardening WordPress
- WordPress Advanced Administration: HTTPS
- WordPress Advanced Administration: Upgrading WordPress (automatic background updates)
- WordPress.org plugin directory: Two Factor
- Caddy docs: Reverse proxy quick-start
- Caddy docs: Install
- Caddy docs: Keep Caddy running
- Caddy docs: reverse_proxy directive
- Caddy docs: Request matchers
- Docker docs: Install Docker Engine on Ubuntu
- Docker docs: Port publishing and mapping
- Docker docs: Packet filtering and firewalls
- Docker docs: docker compose exec
- Docker docs: docker compose ps
- Docker docs: docker compose pull
- Docker docs: Volumes (back up and restore)
- MySQL 8.4 Reference Manual: mysqldump
- DigitalOcean: Droplet pricing
- Vultr: Pricing
- Hetzner: Cloud Regular Performance plans
- Hostinger: VPS hosting plans
- Hostinger: Managed WordPress hosting plans