Hero Image

Install WordPress on Debian 12 (Nginx+PHP-FPM+MySQL)

Install WordPress on Debian 12 (Nginx + PHP-FPM + MySQL)

Prerequisites

  • Nginx installed (guide)
  • PHP-FPM installed (guide)
  • MySQL/MariaDB installed (guide)

Step 1 – Create MySQL database

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'WPStrongPass!';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;

Step 2 – Download WordPress

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cp -r wordpress /var/www/example.com/
chown -R www-data:www-data /var/www/example.com/wordpress 2>/dev/null || \
chown -R nginx:nginx /var/www/example.com/wordpress
find /var/www/example.com/wordpress -type d -exec chmod 755 {} \;
find /var/www/example.com/wordpress -type f -exec chmod 644 {} \;

Step 3 – WordPress configuration

cp /var/www/example.com/wordpress/wp-config-sample.php \
   /var/www/example.com/wordpress/wp-config.php

Edit wp-config.php:

define( 'DB_NAME',     'wordpress' );
define( 'DB_USER',     'wpuser' );
define( 'DB_PASSWORD', 'WPStrongPass!' );
define( 'DB_HOST',     'localhost' );
define( 'DB_CHARSET',  'utf8mb4' );

Generate secret keys from https://api.wordpress.org/secret-key/1.1/salt/ and add them to wp-config.php.

Step 4 – Nginx server block

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com/wordpress;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include        fastcgi_params;
        fastcgi_pass   unix:/run/php-fpm/www.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {
        expires 365d;
        add_header Cache-Control "public, immutable";
    }

    location ~ /\.ht { deny all; }

    client_max_body_size 64M;
}

Step 5 – Complete WordPress setup

Visit http://example.com in a browser and follow the 5-minute WordPress installation wizard.