How to Install WordPress on DigitalOcean: A Step-by-Step Guide

DigitalOcean provides a robust and scalable cloud infrastructure that’s perfect for hosting WordPress sites. If you’re looking to set up a WordPress website on DigitalOcean, this guide will walk you through the process from start to finish. By the end, you’ll have a fully functional WordPress site running on a DigitalOcean droplet.

Step 1: Create a DigitalOcean Account

  1. Sign Up: If you don’t already have a DigitalOcean account, go to DigitalOcean’s website and sign up.
  2. Add Payment Information: Enter your payment details to activate your account.

Step 2: Create a New Droplet

  1. Log In to DigitalOcean: Access your DigitalOcean dashboard by logging in.
  2. Create a Droplet:
    • Click on the “Create” button and select “Droplet” from the dropdown menu.
    • Choose an OS: For WordPress, a popular choice is Ubuntu. Select the latest version of Ubuntu (e.g., Ubuntu 22.04).
    • Select a Plan: Choose a plan that fits your needs. For most small to medium WordPress sites, the basic plan (e.g., $5/month) is sufficient.
    • Choose a Data Center: Select a data center location that is closest to your target audience.
    • Add SSH Keys: For secure access, add your SSH keys. If you don’t have an SSH key, you can generate one using tools like ssh-keygen on your local machine.
    • Create Droplet: Click on “Create Droplet” to launch your server.
  3. Access Your Droplet:
    • Once your droplet is created, you will receive an email with its IP address and root password.
    • Use an SSH client (like ssh in the terminal or PuTTY on Windows) to connect to your droplet:
      bash

      ssh root@your_droplet_ip

Step 3: Set Up the Server Environment

  1. Update Packages:
    • Once logged in, update your package lists and upgrade existing packages:
      bash

      sudo apt update
      sudo apt upgrade
  2. Install Necessary Software:
    • Install Apache:
      bash

      sudo apt install apache2
    • Install MySQL:
      bash

      sudo apt install mysql-server
    • Secure MySQL Installation:
      bash

      sudo mysql_secure_installation

      Follow the prompts to set up a root password and secure your MySQL installation.

    • Install PHP:
      bash

      sudo apt install php libapache2-mod-php php-mysql
  3. Restart Apache:
    • Restart Apache to apply changes:
      bash

      sudo systemctl restart apache2

Step 4: Create a MySQL Database for WordPress

  1. Access MySQL:
    • Log in to MySQL:
      bash

      sudo mysql -u root -p
  2. Create a Database and User:
    • Run the following commands to create a database and user:
      sql

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

Step 5: Download and Install WordPress

  1. Download WordPress:
    • Navigate to the /var/www/html directory and download WordPress:
      bash

      cd /var/www/html
      sudo wget https://wordpress.org/latest.tar.gz
      sudo tar xzvf latest.tar.gz
      sudo mv wordpress/* .
      sudo rm -rf wordpress latest.tar.gz
  2. Set Correct Permissions:
    • Adjust the file permissions:
      bash

      sudo chown -R www-data:www-data /var/www/html
  3. Configure WordPress:
    • Rename the sample configuration file:
      bash

      sudo cp wp-config-sample.php wp-config.php
    • Edit the wp-config.php file to add your database details:
      bash

      sudo nano wp-config.php

      Update the following lines with your database information:

      php

      define('DB_NAME', 'wordpress_db');
      define('DB_USER', 'wordpress_user');
      define('DB_PASSWORD', 'your_password');
      define('DB_HOST', 'localhost');

Step 6: Complete the WordPress Installation

  1. Access Your Website:
    • Open your web browser and go to your droplet’s IP address. You should see the WordPress setup page.
  2. Follow the Installation Wizard:
    • Choose your language and click “Continue.”
    • Enter your site title, admin username, password, and email address.
    • Click “Install WordPress” and then log in using the credentials you set up.

Step 7: Secure Your Server

  1. Set Up a Firewall:
    • Use ufw to set up a basic firewall:
      bash

      sudo ufw allow OpenSSH
      sudo ufw allow 'Apache Full'
      sudo ufw enable
  2. Enable Automatic Security Updates:
    • Install and configure unattended-upgrades to keep your system updated:
      bash

      sudo apt install unattended-upgrades

And there you have it! Your WordPress site is now up and running on DigitalOcean. With this setup, you’re ready to start customizing your site, installing themes and plugins, and adding content. If you encounter any issues or need further customization, DigitalOcean’s documentation and community forums are great resources for additional help.

Leave a Reply

Your email address will not be published.