This guide will help you set up a WordPress website on a Linux server with a LEMP stack (Linux, Nginx, MySQL, PHP), secure it with Let's Encrypt SSL/TLS certificates, optimize performance, and implement continuous integration/continuous deployment (CI/CD) using GitHub Actions.
-
Install Nginx, MySQL, and PHP:
sudo apt install nginx mysql-server php-fpm php-mysql
-
Secure MySQL by running:
sudo mysql_secure_installation
-
Create a Database: Create a MySQL database and user for WordPress. Note down the credentials.
-
Install Let's Encrypt: Install Certbot to manage SSL/TLS certificates:
sudo apt install certbot python3-certbot-nginx
-
Download and Configure WordPress:
-
Download WordPress to your server:
cd /var/www/html sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzvf latest.tar.gz
-
Configure WordPress by creating a wp-config.php file using the sample configuration:
sudo mv wordpress/wp-config-sample.php wordpress/wp-config.php
-
Edit wp-config.php and provide your database credentials.
-
-
Set Permissions:
sudo chown -R www-data:www-data /var/www/html/wordpress sudo find /var/www/html/wordpress/ -type d -exec chmod 755 {} \; sudo find /var/www/html/wordpress/ -type f -exec chmod 644 {} \;
-
Create an Nginx server block configuration file for your domain:
sudo nano /etc/nginx/sites-available/yourdomain.com
Example configuration:
(Insert the Nginx configuration here)
-
Create a symbolic link to enable the configuration:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
-
Test the Nginx configuration and restart Nginx:
sudo nginx -t sudo systemctl restart nginx
-
Obtain and configure the SSL/TLS certificate:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
-
Certbot will ask if you want to redirect HTTP traffic to HTTPS; choose your preference.
-
Enable Nginx Gzip Compression:
Edit the Nginx configuration file:
sudo nano /etc/nginx/nginx.conf
Add the following lines inside the
http
block:(Insert the Nginx Gzip configuration here)
Save and exit the file, then restart Nginx.
-
GitHub Repository:
Create a new GitHub repository for your WordPress project.
-
GitHub Actions Workflow:
Create a
.github/workflows/deploy.yml
file in your repository for your GitHub Actions workflow. Here's a sample configuration: -
Secrets:
In your GitHub repository settings, add secrets:
KEY
(your SSH private key)USER
(ssh username)HOST
(ip or domain name of server)PORT
(ssh port) .
Now, every time you push to the main branch or raise pull request, GitHub Actions will deploy your WordPress site to your server.
This automated deployment process ensures your WordPress website is set up securely, with SSL/TLS, Nginx optimizations, and CI/CD in place.