Last updated

WordPress

Install WordPress on Ubuntu with NGINX, PHP, and MariaDB from scratch.

Contents

  1. Install LEMP Stack
  2. Create WordPress Database
  3. Download WordPress
  4. NGINX Configuration
  5. Configure WordPress
  6. Add SSL
  7. Complete Installation

Install LEMP Stack

sudo apt update
sudo apt install -y nginx mariadb-server php8.1-fpm php8.1-mysql   php8.1-curl php8.1-gd php8.1-xml php8.1-zip php8.1-mbstring

Create WordPress Database

sudo mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'StrongPass123!';
GRANT ALL ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Download WordPress

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo mv wordpress /var/www/example.com
sudo chown -R www-data:www-data /var/www/example.com
sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;

NGINX Configuration

sudo nano /etc/nginx/sites-available/example.com
server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht { deny all; }
}
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Configure WordPress

sudo cp /var/www/example.com/wp-config-sample.php /var/www/example.com/wp-config.php
sudo nano /var/www/example.com/wp-config.php

Update these lines with your database credentials:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'StrongPass123!' );
define( 'DB_HOST', 'localhost' );

Add SSL

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

Complete Installation

Browse to https://example.com and complete the WordPress 5-minute install wizard.