Introduction

WordPress is a popular content management system (CMS) used to create websites and blogs. This tutorial will guide you through the process of installing WordPress with Nginx as the web server and Let's Encrypt SSL certificate for secure connections on Ubuntu 22.04.

Prerequisites

Before you begin, ensure you have:

  1. An Ubuntu 22.04 server or virtual machine
  2. SSH access to the server
  3. Root or sudo privileges
  4. A domain name pointed to your server's IP address

Step 1: Update System

Before installing any new software, it's always a good idea to update the package repository and installed packages:

sudo apt update
sudo apt upgrade -y

Step 2: Install Nginx

Install Nginx web server:

sudo apt install -y nginx

Step 3: Install MySQL Database Server

Install MySQL database server:

sudo apt install -y mysql-server

During the installation, you will be prompted to set a root password for MySQL.

Step 4: Install PHP and PHP Extensions

Install PHP and required PHP extensions:

sudo apt install -y php php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

Step 5: Configure Nginx for WordPress

Create a new Nginx server block configuration file for your domain:

sudo nano /etc/nginx/sites-available/your_domain

Replace your_domain with your actual domain name, and add the following configuration:

server {
    listen 80;
    server_name your_domain www.your_domain;

    root /var/www/your_domain;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Save the file and exit the text editor.

Enable the Nginx server block configuration:

sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

Test Nginx configuration:

sudo nginx -t

Reload Nginx to apply the changes:

sudo systemctl reload nginx

Step 6: Create MySQL Database and User for WordPress

Log in to the MySQL shell as the root user:

sudo mysql -u root -p

Enter the MySQL root password when prompted.

Create a new database for WordPress:

CREATE DATABASE wordpress;

Create a new MySQL user and grant privileges to the WordPress database:

CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace your_password with a strong password for the MySQL user.

Step 7: Install WordPress

Download and extract the latest version of WordPress:

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz

Copy the extracted WordPress files to the Nginx document root directory:

sudo cp -a /tmp/wordpress/. /var/www/your_domain

Set the correct permissions on the WordPress files:

sudo chown -R www-data:www-data /var/www/your_domain

Step 8: Configure WordPress

Copy the sample WordPress configuration file:

sudo cp /var/www/your_domain/wp-config-sample.php /var/www/your_domain/wp-config.php

Edit the WordPress configuration file:

sudo nano /var/www/your_domain/wp-config.php

Update the database connection settings with the MySQL database details:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wordpressuser' );
define( 'DB_PASSWORD', 'your_password' );
define( 'DB_HOST', 'localhost' );

Replace your_password with the password you set for the MySQL user.

Step 9: Set Up Let's Encrypt SSL

Install Certbot for Let's Encrypt:

sudo apt install certbot python3-certbot-nginx

Obtain an SSL certificate for your domain:

sudo certbot --nginx -d your_domain

Follow the on-screen prompts to obtain and install the SSL certificate.

Step 10: Complete WordPress Installation

Open a web browser and navigate to your domain:

https://your_domain

Follow the on-screen instructions to complete the WordPress installation by providing site information, creating an administrator account, and installing WordPress.

Conclusion

Congratulations! You have successfully installed WordPress with Nginx and Let's Encrypt SSL on Ubuntu 22.04. You can now log in to your WordPress dashboard and start building your website or blog.

Was this answer helpful? 0 Users Found This Useful (0 Votes)