My Journey in Setting Up WordPress with Nginx and SSL
Introduction
Jump to section titled: IntroductionAs 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 SetupI wanted a reliable and secure setup for hosting WordPress sites, and after researching, I decided to use:
- Ubuntu 22.04 LTS for stability and security
- Nginx for better performance compared to Apache
- SSL (Let’s Encrypt) for security and HTTPS support
This combination ensures that my WordPress sites are fast, secure, and scalable.
Step-by-Step Guide
Jump to section titled: Step-by-Step Guide1. Setting Up the Server
Jump to section titled: 1. Setting Up the ServerI 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 WordPressI 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 DatabaseUsing 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 NginxI 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 EncryptTo 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- File Permissions Matter: WordPress won’t work correctly if permissions are wrong.
- Database Security Is Important: Using a secure password and restricting privileges is crucial.
- Nginx Configuration Can Be Tricky: Testing with
nginx -t
before restarting saved me a lot of debugging time. - SSL Is a Must: Modern websites need HTTPS for security and SEO benefits.
Conclusion
Jump to section titled: ConclusionSetting 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! 🚀
- ← Previous
Build personal blog easy with 11ty.js - Next →
Touch Typing Practice Feb 2025