Hey there, fellow WordPress enthusiasts! Today, I’m going to walk you through the process of setting up a WordPress site
on Ubuntu. We’ll be using a domain (in this case, slashism.com) and configuring Nginx. Don’t worry if you’re not a tech
wizard - I’ll break it down into manageable steps.
1. Creating a Home for Your Site
First things first, let’s create a cozy little directory for your new WordPress site:
sudo mkdir -p /var/www/slashism.com2. Getting WordPress Up and Running
Now, let’s download WordPress and set it up in its new home:
cd /var/www/slashism.comsudo wget https://wordpress.org/latest.tar.gzsudo tar -xzf latest.tar.gzsudo mv wordpress/* ./sudo rm -rf wordpress latest.tar.gzsudo chown -R www-data:www-data /var/www/slashism.com3. Setting Up a Database
Time to create a database for your site. Fire up MySQL::
mysql -u root -pInside the MySQL shell, run the following commands:
CREATE DATABASE s_db;CREATE USER 's_user'@'localhost' IDENTIFIED BY 'your_secure_password';GRANT ALL PRIVILEGES ON s_db.* TO 's_user'@'localhost';FLUSH PRIVILEGES;EXIT;Remember to replace ‘your_secure_password’ with something strong and unique!
4. Configuring Nginx
Let’s tell Nginx about your new site. Create a new configuration file:
sudo nano /etc/nginx/sites-available/slashism.comCopy and paste this configuration (adjust as needed):
server { root /var/www/slashism.com; index index.php index.html index.htm; server_name www.slashism.com slashism.com; client_max_body_size 100M;
location / { try_files $uri $uri/ /index.php?$args; }
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
listen 443 ssl; listen 80;}5. Activating Your Site
Let’s make your site configuration active:
sudo ln -s /etc/nginx/sites-available/slashism.com /etc/nginx/sites-enabled/6. Checking and Reloading Nginx
Always good to double-check our work:
sudo nginx -tsudo systemctl reload nginx7. Installing and Configuring Certbot for SSL
Now, let’s secure our site with SSL using Certbot. This nifty tool makes it a breeze to set up Let’s Encrypt certificates. Here’s how:
Step 1: Install Certbot and the Nginx Plugin
First, let’s make sure we have the latest packages and install Certbot with its Nginx plugin:
sudo apt updatesudo apt install certbot python3-certbot-nginxFor more details, you can refer the official Certbot website.
Step 2: Obtain and Install SSL Certificate
Run the following command to get your certificate:
sudo certbot --nginx -d slashism.com -d www.slashism.comCertbot is pretty smart - it can also detect the domains in your Nginx config if you run the below command:
sudo certbot --nginxAbove command will ask for some info like your email address (for important notifications) and agreement to the Terms of Service.
Certbot will automatically install the SSL certificate and configure Nginx. It’ll ask if you want to redirect all HTTP traffic to HTTPS. I’d recommend saying “yes” to this.
Step 3: Set Up Automatic Renewal
Let’s Encrypt certificates are valid for 90 days, but don’t worry - Certbot’s got your back. It sets up a cron job or systemd timer to automatically renew your certificates before they expire. It’s like having a personal assistant for your SSL!
You can also set up the cron job yourself to automatically renew your certificates. Open the crontab editor:
sudo crontab -eIn the editor, add this line to run the renewal command twice daily:
0 */12 * * * /usr/bin/certbot renew --quietYou can also test the renewal process (without actually renewing) using:
sudo certbot renew --dry-runTo manually check and renew your certificates:
- Check existing certificates:
sudo certbot certificates- Renew the certificate:
sudo certbot renew8. Firewall Adjustment
If you’re using a firewall (and you should be!), make sure it’s configured to allow HTTPS traffic:
sudo ufw allow 'Nginx Full'sudo ufw delete allow 'Nginx HTTP'This opens up port 443 for HTTPS and closes port 80 for HTTP - keeping things nice and secure.
9. Finalizing WordPress Installation
Now, head over to https://slashism.com in your browser and finish setting up WordPress using the database details we created earlier.
Troubleshooting SSL Redirects
If you run into any redirect issues with HTTPS, don’t panic! Add these lines to your wp-config.php file:
define('FORCE_SSL_ADMIN', true);if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';And there you have it! You’ve successfully set up WordPress on Ubuntu with SSL. Remember, this guide assumes you’ve already got PHP and MySQL/MariaDB installed on your server. If you run into any hiccups, feel free to reach out or check the official documentation.
Happy blogging! 🚀💻📝