WordPress on VPS
WordPress is the most used CMS in the world. On a VPS you have full control over the environment: faster and more flexible than shared hosting.
02
Prerequisites
Before proceeding ensure you have:
If you don't have them yet, follow the guide: LEMP Stack
- Nginx installed and running
- PHP 8.1+ with PHP-FPM
- MariaDB/MySQL installed
- A domain pointing to the server IP
- Certbot for SSL
03
1. Create database and user
bash
mysql -u root -p
sql
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'secure_password_here';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
04
2. Download and install WordPress
bash
# Create the site directory
mkdir -p /var/www/example.com
cd /var/www/example.com
# Download WordPress
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz --strip-components=1
rm latest.tar.gz
# Set correct permissions
chown -R www-data:www-data /var/www/example.com
find /var/www/example.com -type d -exec chmod 755 {} \;
find /var/www/example.com -type f -exec chmod 644 {} \;
05
3. Configure Nginx
bash
nano /etc/nginx/sites-available/example.com
nginx
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
# Maximum upload size (align with php.ini)
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;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
# Block access to sensitive files
location ~ /\.(ht|git) {
deny all;
}
# Cache for static files
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
}
}
bash
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
06
4. Configure PHP for WordPress
bash
nano /etc/php/8.2/fpm/php.ini
Recommended parameters:
ini
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120
memory_limit = 256M
max_input_vars = 3000
date.timezone = Europe/Rome
bash
systemctl restart php8.2-fpm
07
5. Install SSL
bash
certbot --nginx -d example.com -d www.example.com
08
6. Complete web installation
Go to https://example.com in your browser. The WordPress wizard will ask you for:
- Database name: wordpress
- Database user: wp_user
- Password: the one set at step 1
- Database host: localhost
- Table prefix: wp_ (change it for more security, e.g. site_)
09
Recommended post-installation optimizations
Essential plugins
| Plugin | Purpose |
|---|---|
| Wordfence or Solid Security | Security and brute force protection |
| WP Super Cache or W3 Total Cache | Page caching |
| WP Mail SMTP | Reliable email via relay SMTP |
| UpdraftPlus | Automatic backups |
| Smush or ShortPixel | Image optimization |
Protect wp-login.php from brute force
nginx
# Add in the server block of Nginx
location = /wp-login.php {
limit_req zone=one burst=5 nodelay;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
At the top of nginx.conf:
nginx
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/m;
Increase memory limit in wp-config.php
bash
nano /var/www/example.com/wp-config.php
Add before the line /* That's all, stop editing! */:
php
define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '512M');
10
Update WordPress via WP-CLI
WP-CLI lets you manage WordPress from command line:
bash
# Install WP-CLI
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
# Update WordPress core
wp --path=/var/www/example.com --allow-root core update
# Update all plugins
wp --path=/var/www/example.com --allow-root plugin update --all
# Update all themes
wp --path=/var/www/example.com --allow-root theme update --all
# Backup the database
wp --path=/var/www/example.com --allow-root db export /root/backup-wp.sql
11
Common issues
| Issue | Solution |
|---|---|
| Error 500 | Check /var/log/nginx/error.log and PHP debug |
| Upload fails | Increase upload_max_filesize and client_max_body_size |
| Slow | Install a cache plugin and optimize images |
| Emails not arriving | Install WP Mail SMTP, see Troubleshooting |
| Redirect loop | Add to wp-config.php: define('FORCE_SSL_ADMIN', true); |
Articoli correlati
Software
Package Installation
How to install, update and remove software on your Linux server
2 min di lettura
Software
Web Server: Nginx
Installation and basic configuration of Nginx on your server
2 min di lettura
Software
Web Server: Apache
Installation and basic configuration of Apache on your server
2 min di lettura
