Skip to main content
Heterl0

My Journey in Setting Up WordPress with Nginx and SSL

Introduction

Jump to section titled: Introduction

As a front-end developer, I’ve always focused on building great user interfaces, but recently, I’ve been diving deeper into server management and deployment. In this blog, I’ll share my personal experience setting up WordPress on an Nginx server with SSL, a journey that has helped me understand web hosting, security, and performance optimization. Check me project here!.

Why I Chose This Setup

Jump to section titled: Why I Chose This Setup

I wanted a reliable and secure setup for hosting WordPress sites, and after researching, I decided to use:

This combination ensures that my WordPress sites are fast, secure, and scalable.

Step-by-Step Guide

Jump to section titled: Step-by-Step Guide

1. Setting Up the Server

Jump to section titled: 1. Setting Up the Server

I started by updating my system and installing necessary packages:

sudo apt update && sudo apt upgrade -y

Then, I installed PHP, Nginx, and MySQL:

sudo apt install -y nginx mysql-server php-fpm php-mysql

This provided the foundation for running WordPress.

2. Installing and Configuring WordPress

Jump to section titled: 2. Installing and Configuring WordPress

I downloaded and extracted WordPress:

wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo mv wordpress /var/www/wordpress

I set the correct file permissions:

sudo chown -R www-data:www-data /var/www/wordpress/
sudo chmod -R 755 /var/www/wordpress/

3. Setting Up the Database

Jump to section titled: 3. Setting Up the Database

Using MySQL, I created a new database and user:

CREATE DATABASE wordpress_db;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'securepassword';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;

4. Configuring Nginx

Jump to section titled: 4. Configuring Nginx

I configured Nginx to serve WordPress efficiently. I edited the configuration file:

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

Added the following configuration:

server {
    listen 80;
    server_name example.com;
    root /var/www/wordpress;
    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:/var/run/php/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

After saving, I enabled the configuration and restarted Nginx:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo systemctl restart nginx

5. Enabling SSL with Let’s Encrypt

Jump to section titled: 5. Enabling SSL with Let’s Encrypt

To secure the site with HTTPS, I installed Certbot:

sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot

I obtained an SSL certificate and configured Nginx:

sudo certbot --nginx -d example.com -d www.example.com

To ensure automatic renewal:

sudo certbot renew --dry-run

Lessons Learned

Jump to section titled: Lessons Learned

Conclusion

Jump to section titled: Conclusion

Setting up WordPress with Nginx and SSL was a rewarding experience. Not only did it help me understand backend technologies, but it also made me appreciate the work that goes into web hosting and security. I hope this guide helps anyone looking to set up their own WordPress site with a strong, secure foundation.

This is just the beginning—next, I plan to explore performance optimizations and caching strategies. Stay tuned! 🚀