WordPress still powers a huge chunk of the web, and installing it yourself means full control: your plugins, your data, your server, no hosting-plan upsells. This guide sets it up on Ubuntu with the classic LEMP stack — Linux, Nginx, MariaDB, PHP.
A quick note on versions: Ubuntu 18.04 is past standard support, so for anything new, use 22.04 or 24.04 — the steps below are identical on all of them.
1. Install Nginx, MariaDB, and PHP
sudo apt update
sudo apt install -y nginx mariadb-server php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip
Secure the database with a root password and sensible defaults:
sudo mysql_secure_installation
2. Create the WordPress database and user
sudo mysql
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'a-strong-password-here';
GRANT ALL ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
3. Download WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo cp -r wordpress /var/www/wordpress
sudo chown -R www-data:www-data /var/www/wordpress
WordPress writes uploads and plugin files as the web server user, so ownership matters — wrong permissions are the most common cause of "update failed" later.
4. Configure Nginx
Create /etc/nginx/sites-available/wordpress:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg)$ {
expires 30d;
}
}
Enable it and reload:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
5. Run the installer
Point your DNS at the server, then open http://example.com in a browser. The WordPress installer asks for:
- Database:
wordpress - Username:
wpuser - Password: the one you created
- Host:
localhost - Table prefix: leave
wp_or change it, doesn't matter much
Pick your site title and admin user (not "admin" — bots try that name first), and you're in.
6. HTTPS and the essentials
Every WordPress site needs TLS — logins and admin sessions go over it constantly:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
Certbot edits the Nginx config and sets up auto-renewal; our Let's Encrypt guide has the renewal-test details.
Then finish with the basics: set pretty permalinks (Settings → Permalinks → Post name), install one caching plugin, and set up backups before you touch anything else — a WordPress site is a database plus the wp-content folder, and both need regular copies (backup tools compared).
If something breaks
-
"Error establishing a database connection" — wrong credentials in
wp-config.php, or MariaDB not running:sudo systemctl status mariadb -
White screen — usually a PHP error; check
/var/log/nginx/error.logand the PHP-FPM log -
Plugin uploads ask for FTP — file ownership issue; re-run the
chown -R www-data:www-datacommand
That's a complete self-hosted WordPress: fast, yours, and ready for content.
Top comments (0)