1 Create MySQL Database
Log into MySQL and create a database and user for WordPress:
mysql -u root -p
Then inside the MySQL shell:
CREATE DATABASE wordpress; CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'SecurePass@2024!'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
2 Download & Place WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvf latest.tar.gz
mv wordpress /var/www/html/wordpress
# Set correct ownership
chown -R www-data:www-data /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress
3 Configure wp-config.php
cd /var/www/html/wordpress cp wp-config-sample.php wp-config.php nano wp-config.php
Find and update these lines with your database credentials:
define( 'DB_NAME', 'wordpress' ); define( 'DB_USER', 'wpuser' ); define( 'DB_PASSWORD', 'SecurePass@2024!' ); define( 'DB_HOST', 'localhost' );
4 Create Nginx Server Block
nano /etc/nginx/sites-available/wordpress
Paste this configuration:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/html/wordpress;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
}
5 Enable the Site
# Remove default site (important!) rm /etc/nginx/sites-enabled/default # Enable WordPress site ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ nginx -t systemctl reload nginx
Removing the default site is critical. If it's still enabled, Nginx serves the default page instead of WordPress.
6 Fix Cloudflare SSL Redirect Loop
After pointing your domain and setting Cloudflare SSL to Full, you may get a redirect
loop. Add this to wp-config.php above the "stop editing" line:
define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
}
7 Update WordPress URLs via MySQL
If you changed your domain and WordPress is looping, reset URLs directly in the database:
USE wordpress; UPDATE wp_options SET option_value = 'https://example.com' WHERE option_name = 'siteurl'; UPDATE wp_options SET option_value = 'https://example.com' WHERE option_name = 'home'; EXIT;
Visit https://example.com/wp-admin — you should see the WordPress installer or login
screen.
Done!