skip to content

Setting Up WordPress on Ubuntu

/ 4 min read

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, 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:

Terminal window
sudo mkdir -p /var/www/

2. Getting WordPress Up and Running

Now, let’s download WordPress and set it up in its new home:

Terminal window
cd /var/www/
sudo wget
sudo tar -xzf latest.tar.gz
sudo mv wordpress/* ./
sudo rm -rf wordpress latest.tar.gz
sudo chown -R www-data:www-data /var/www/

3. Setting Up a Database

Time to create a database for your site. Fire up MySQL::

Terminal window
mysql -u root -p

Inside the MySQL shell, run the following commands:

CREATE USER 's_user'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON s_db.* TO 's_user'@'localhost';

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:

Terminal window
sudo nano /etc/nginx/sites-available/

Copy and paste this configuration (adjust as needed):

server {
root /var/www/;
index index.php index.html index.htm;
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:

Terminal window
sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

6. Checking and Reloading Nginx

Always good to double-check our work:

Terminal window
sudo nginx -t
sudo systemctl reload nginx

7. 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:

Terminal window
sudo apt update
sudo apt install certbot python3-certbot-nginx

For more details, you can refer the official Certbot website.

Step 2: Obtain and Install SSL Certificate

Run the following command to get your certificate:

Terminal window
sudo certbot --nginx -d -d

Certbot is pretty smart - it can also detect the domains in your Nginx config if you run the below command:

Terminal window
sudo certbot --nginx

Above 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:

Terminal window
sudo crontab -e

In the editor, add this line to run the renewal command twice daily:

0 */12 * * * /usr/bin/certbot renew --quiet

You can also test the renewal process (without actually renewing) using:

Terminal window
sudo certbot renew --dry-run

To manually check and renew your certificates:

  1. Check existing certificates:
Terminal window
sudo certbot certificates
  1. Renew the certificate:
Terminal window
sudo certbot renew

8. Firewall Adjustment

If you’re using a firewall (and you should be!), make sure it’s configured to allow HTTPS traffic:

Terminal window
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 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')

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! 🚀💻📝