Install WordPress on your own server (Nginx, PHP, MariaDB)
Set up WordPress step by step on Debian or Ubuntu: PHP-FPM, database, Nginx configuration with pretty permalinks, HTTPS and the most important security steps.
WordPress powers about a third of all websites. On your own server you are faster than on shared hosting, have no limits on plugins and full control. This guide sets up the classic LEMP stack: Linux, Nginx (pronounced "Engine X"), MariaDB, PHP.
Requirements
- Nginx installed
- MariaDB installed and secured
- A domain with an A record pointing to the server
Install PHP
sudo apt update
sudo apt install php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-xml php-zip php-imagick
php -v
Note the version (Debian 12: 8.2, Ubuntu 24.04: 8.3); you need it for the socket in a moment.
Create the database
sudo mariadb
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'a-long-random-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Download WordPress
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo mkdir -p /var/www/example.com
sudo cp -a wordpress/. /var/www/example.com/
sudo chown -R www-data:www-data /var/www/example.com
Configure Nginx
sudo nano /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php;
client_max_body_size 64M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
location ~ /\.(ht|git) {
deny all;
}
location = /xmlrpc.php {
deny all;
}
}
Adjust php8.2 to your version. The line try_files … /index.php?$args enables pretty permalinks such as /contact/. Hardly anyone needs xmlrpc.php today, but it is a popular target for attacks.
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d example.com -d www.example.com
For the certificate see Let's Encrypt certificate with Certbot.
Allow larger uploads
By default PHP only allows 2 MB. In /etc/php/8.2/fpm/php.ini:
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
sudo systemctl restart php8.2-fpm
Setup in the browser
Open https://example.com. The wizard asks for the language, database name (wordpress), user, password and server (localhost). Then you create your admin account. Do not choose admin as the username.
Security after the installation
- Updates: Keep WordPress, themes and plugins up to date. WordPress installs minor updates itself.
- Few plugins: Every plugin is potential attack code. Delete what you do not use instead of just deactivating it.
- Disable the file editor: Add the line
define('DISALLOW_FILE_EDIT', true);towp-config.php. - Protect the login: With Fail2ban or a plugin for two-factor login.
- Backups: Back up the database and
wp-contentregularly, see Backups with restic.
Make WordPress cron reliable
WordPress only runs scheduled tasks when someone visits the site. It is better to let the server do it. In wp-config.php:
define('DISABLE_WP_CRON', true);
and via sudo crontab -u www-data -e:
*/5 * * * * php /var/www/example.com/wp-cron.php > /dev/null 2>&1
For the community
Know your stuff? Write a guide.
Share what you know: we review every submitted guide, publish it under your name and say thank you with credit for your services.