WordPress on DigitalOcean Cloud – A Setup Guide from Scratch!

Looking for a complete end-to-end WordPress on DigitalOcean installation guide? Seems like you're at the right page. Refer my simple yet extensive guide and video tutorial on the entire setup from the scratch.

Hello everyone, hope you’re doing great today! This is a complete setup and installation guide for WordPress on DigitalOcean cloud server. I’ve also included the video demo for ease of understanding.

Firstly, if you’re reading this article then I don’t think you need an introduction to what is WordPress(WP) all about.

Secondly, the DigitalOcean (DO) is one of the best and fastest-growing cloud hosting service provider, I use DigitalOcean to power-up this restoreBin blog.

With DO, you can spin a cloud server (known as Droplet) in less than a minute! If you’re new to Cloud Server then signup for an ultra-fast cloud webserver at DigitalOcean, you’ll also get a $50 free credits using this link.

Let’s get started with our complete end-to-end guide on installing WordPress on DigitalOcean. I’d suggest bookmarking (Ctrl+D) this page for your future reference.

Sign up and Create a Droplet

The very first thing that you need is to create an account at DigitalOcean and spin a droplet. The steps are pretty simple and straight forward.

Steps to Sign up DigitalOcean with free $50 credits:

  1. Go to DigitalOcean (special link with $50 free credits)
  2. Hit [Sign up] button on the Home Page
  3. Enter Email Address and desired Password OR you can even register with Google or GitHub Account using SSO
  4. Verify your Email ID (not required for SSO)
  5. Enter the Payment details; Credit Card or PayPal (Do not worry! you won’t be charged until credits are used or expired)
  6. And finally login to your DigitalOcean dashboard

You’ll be asked for a couple of basic questions along with project name and other details. You can refer to this DigitalOcean registration guide for further details.

Steps to Create Droplet for WordPress:

Once you’re into DigitalOcean dashboard console follow the below steps to spin a droplet server.

  1. Hit on Create Droplet
  2. Select the latest Ubuntu OS 18.04  (current stable version while writing this post)
  3. Choose Droplet Size. I recommend using at least 1 GB RAM for smooth functioning.
  4. Select Data Center (based on targetted region/country)
  5. Select Additional Option (if required – not necessary for WordPress)
  6. Number of Droplets: 1
  7. Hostname: yourdomain.com (or anything you name it!)
  8. Hit on Create button

DigitalOcean Droplet Number, Hostname and Project Selection

You’ve now signed up for an account and also created a basic droplet to host WordPress. You can refer to this detailed guide on DigitalOcean Droplet Creation and get free credits.

Watch the Video Tutorial on DigitalOcean Sign up and Droplet Creation for free:

Ubuntu Cloud Server Setup on DigitalOcean Account: How to get started?

Adding Domain Name and Configure DNS settings

Currently, DigitalOcean doesn’t have domain registration feature. So you need to buy the domain outside and point the nameservers towards DigitalOcean’s NS for managing DNS setting within DO.

I prefer using Google Domains as this being one of the most reliable and authenticated domain name registrars. Steps for registering is pretty much simple and almost correlated with any registrar site.

  1. Search for desired Domain Name on domains.google.com
  2. Check the availability for domain
  3. Add to Cart (if the domain name is available)
  4. Check out with free Privacy Protect add-on
  5. Complete payment transaction
  6. Visit your Domains section, and your domain will be available in the portal

How to Add Domain Name in DigitalOcean?

Once the domain name is available in your registrar’s dashboard, all you need is to point the Name Server towards DigitalOcean to manage the domain name from DigitalOcean dashboard.

Open DNS Settings in Domain Registrar

Visit your registrar domain name settings and modify the Name Server(NS) to point towards DigitalOcean nameserver with below values:

  • ns1.digitalocean.com
  • ns2.digitalocean.com
  • ns3.digitalocean.com

It may take a while for the DNS changes to reflect into your account. Meanwhile, we can proceed with further setup.

After we added the NS to point towards DO, we will be attaching the domain name to the droplet. Hence, it would be easier for us to remember the domain name instead of a server IP address.

Follow these steps to add the domain name in DigitalOcean networking:

  1. Login to DigitalOcean dashboard
  2. Navigate to Networking tab in left-sidebar
  3. Switch to Domain tab
  4. Enter the domain name (example.com)
  5. Select the Droplet from the drop-down (if you’ve multiple droplets)
  6. Hit on Add Domain
  7. The domain name will start appearing

Adding Domain Name in DigitalOcean Droplet

Your domain name is now successfully added and you’ve in the Domain Name Server (DNS) settings page.

Setup DNS settings in DigitalOcean

Once you’re in Domain Name Server settings page, you have got the options to add different types of record like A, AAA, CNAME, MX, TXT, SRV, NS. Managing the DNS records in DigitalOcean is simple and you can also verify whether the changes be reflecting in Zone file (at the bottom of the same page). Here are a few DNS settings that I think you should consider adding.

Record TypeValuePoint to
CNAMEwwwexample.com.

If you’re looking for setting up your business, then consider signing up G Suite with 20% discount code and add the following records:

Record TypeValuePoint to
MX1aspmx.l.google.com.
MX5alt1.aspmx.l.google.com.
MX5alt2.aspmx.l.google.com.
MX10alt3.aspmx.l.google.com.
MX10alt4.aspmx.l.google.com.

Alternatively, you can also just hit on the button [Add Gmail MX Record] to automatically add these into DNS settings.

Adding Gmail or G Suite MX Records in DigitalOcean DNS Settings

We have now successfully set up the Domain name configuration with our DigitalOcean Droplet.

Login into Droplet and Setup a LEMP Stack

Next, you need to install a powerful LEMP Stack on Cloud Server.

We need an SSH connection terminal for further installation. You can use PuTTY client available for Windows OS, and for macOS, you can use use the built-in terminal and configure the remote connection.

Login to Cloud Server via SSH connection with the credential that you’ve received in the email after creating the droplet.

  1. Enter the IP address of droplet server
  2. Use port as 22
  3. Click Connect button
  4. The terminal will start connecting to the cloud server
  5. Enter the Username that you’ve received in mailer (default is root)
  6. Enter the password (invisible while typing)
  7. You’ll be logged into Ubuntu Cloud droplet

Connect root user in New Remote Connection using Terminal App

Next, we would be installing the Nginx, MySQL, and PHP (known as LEMP Stack) on the droplet as these are mandatory pre-requisite for WordPress functioning.

Install and Configure Nginx Webserver for WordPress

Nginx is currently one of the best lightweight web servers for the web hosting server. We can install Nginx easily with a few command lines from Ubuntu’s APT repository.

Execute these commands in terminal for Nginx installation:

sudo apt-get update
sudo apt-get install nginx
sudo service nginx restart

These commands will install and restart the webserver on Cloud.

To check whether Nginx is installed on our server, type the IP Address in the browser URL. Since we already added the domain name, you can also visit the domain name address for the same.

http://server.ip.address

OR

http://your-domain-address.com

You will be able to see an Nginx default welcome page.

Welcome to nginx! message on IP Address

For extensive details, you can refer Powerful Nginx installation on LEMP Stack.

Installing PHP Processor in DigitalOcean droplet

It’s always good to install the latest PHP processor along with FastCGI to process the dynamic request from WordPress. We will install the current latest PHP 7.3 version.

Run the following command via SSH to install the PHP Processor on Cloud:

sudo apt-get update 
sudo apt-get upgrade 
sudo apt-get install software-properties-common python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.3 php7.3-cli php7.3-common php7.3-fpm php7.3-curl php7.3-mbstring php7.3-mysql php7.3-zip php7.3-xml php7.3-gd php7.3-intl php7.3-soap

Installing PHP and supporting modules

These series of command will install the PHP7.3 version along with the common necessary modules. We have also added a PHP repository to get the frequent updates for the developer.

For more details, read a complete setup guide for PHP Processor on Ubuntu Cloud Server OS. This guide also has an advance setup to improve PHP processors security.

We will also need to adjust the Nginx configuration for PHP-FPM to enhance the performance and speed-up with FastCGI.

Watch the video tutorial on setting up a powerful LEMP stack on a cloud server:

Install and Configure Powerful LEMP Stack on Ubuntu Cloud Server

Install and Configure MySQL Database for WordPress

Now our that cloud server is running and powered by Nginx and backed by PHP-FPM Processor, next would be installing MySQL server.

MySQL is a database management program that will be used by WordPress to store and retrieve the data whenever requested.

To install the MySQL server current default version, execute the below commands.

sudo apt-get install mysql-server php7.3-mysql

This command will install MySQL server and PHP MySQL supporting modules. However, if you’re looking for the fastest and well-optimized database server, then install MySQL 8.0 version (I recommend this!).

One thing to note, while executing the above command, the system will ask you to set and confirm a password for the MySQL root user. The password can (and should) be different than the droplet password.

Once the MySQL server is installed, we need to create a MySQL database table for WordPress to store all the information. Run the below command:

sudo mysql_install_db

Thereafter, run this command for securing the database and locking the data securely.

sudo mysql_secure_installation

Here you will be asked with MySQL username and password. Even changing the password, type ‘n’ or ‘no’ if you want to continue using existing MySQL Password that was created earlier.

Here comes the most important part — WordPress Configuration needs 3 variables as a part of MySQL database setup.

  1. Database namewpdatabase
  2. Database userwpuser
  3. Database passwordwppassword

Login into MySQL server via SSH using root user account:

mysql -u root -p

Enter the root user password when prompted.

Login into MySQL 8.0 on Ubuntu Cloud Server

Next, let create the database using the above dummy values mentioned.

CREATE DATABASE wpdatabase;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppassword';
GRANT ALL ON wpdatabase.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
exit;

Created Database and User for WordPress on MySQL

The command will create the database along with the MySQL user and password for WordPress. After last exit;, you’ll be exited from MySQL and back to SSH shell.

Alert:  Do not use the above dummy values, make sure that live site has unique MySQL credentials. 

You can refer to this detailed guide on creating a MySQL database and user for WordPress.

Install WordPress on DigitalOcean

Before we proceed with installing WordPress, we need to make sure that Nginx web server configuration is correctly set up to listen to the WordPress domain and root directory.

Configure Nginx for WordPress directory

We are going to use the default Nginx virtual host file located under /etc/nginx/sites-available/ to listen to our domain name and PHP Processor socket.

Using the SSH client, edit the default configuration file in nano editor:

sudo nano /etc/nginx/sites-available/default

And make the following changes so that our configuration file will finally look as below:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/demo;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name demo.restorebin.com;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Modified Nginx for reading WordPress files and folders

That’s it, close and save the editor (Ctrl+C) and restart the Nginx webserver.

sudo nginx -t
sudo service nginx restart

You can refer this section for a complete guide to configure Nginx virtual host for WordPress setup.

Configure WordPress on DigitalOcean cloud

Download the latest version of WordPress locally in /tmp/ folder on Cloud server using the command line:

cd /tmp 
curl -LO https://wordpress.org/latest.tar.gz

Extract the WordPress compressed file in the temporary folder and copy the sample configuration file to create a new WordPress wp-config.php file.

tar xzvf latest.tar.gz
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Now let’s copy the entire extracted WordPress files into our public folder /var/www/demo using the following command:

sudo cp -a /tmp/wordpress/. /var/www/demo

Copy wp-config-sample.php file and entire WordPress into root directory

Now that we have copied all the WordPress folder to root directory, let’s change the ownership so that the WordPress will automatically make the required changes on the file and folder system without our explicit permission.

sudo chown -R www-data:www-data /var/www/demo

Next, proceed with editing the wp-config.php file to add the MySQL credential details and install WordPress. You can log in cloud server via SFTP using FileZilla.

Open the WordPress configuration file in SFTP client FileZilla located in /var/www/demo/wp-config.php and follow the steps:

visit WordPress root directory via SFTP

Generate the secret key using WordPress secret key generator in SSH:

curl -s https://api.wordpress.org/secret-key/1.1/salt/

You will get the unique values that need to replace dummy values already present in the wp-config.php file.

generate and replace the salt secret values in WordPress

Next, we need to modify database value to reflect with our MySQL database details.

. . .

define('DB_NAME', 'wpdatabase');

/** MySQL database username */
define('DB_USER', 'wpuser');

/** MySQL database password */
define('DB_PASSWORD', 'wppassword');

. . .

Finally, allow WordPress to write to the file system by defining the FS_METHOD in the wp-config.php file by adding the following snippet:

define('FS_METHOD', 'direct');

FS_METHOD direct defined in WordPress wp-config.php file

Save the file, and upload it back to SFTP server. Finally, reboot the Ubuntu Server to commit all the changes made.

reboot

Refer this section for an advanced WordPress wp-config.php file configuration.

Install WordPress and set up login credentials

We’ve now completed the entire necessary backend set up for a WordPress. Let’s proceed with installing the WordPress CMS in our favorite web browser.

Access the domain name in chrome or whatever the browser you’ve:

http://www.your-domain-name.com

Select the preferred language and the administrator username-password along with email address.

Install WordPress - Account Details Setup

Finally, hit on [Install WordPress] button complete the installation online. Login to your fresh WordPress installation using the above credentials to access the dashboard for the first time.

WordPress Dashboard - First Time Login after Installation

Watch the complete video demo tutorial on installing the WordPress on LEMP Stack:

Install WordPress with LEMP Stack on Powerful Cloud Server

Advanced Guides for WordPress on DigitalOcean

Now that you’ve successfully installed WordPress on DigitalOcean, next you can follow these advanced guide to make your installation even better.

Conclusion:

I hope the guide has been very helpful to you. However, let me know if you were facing any issue or found something missing in the tutorial. I’d be happy to acknowledge and make the correction.

If you've any thoughts on WordPress on DigitalOcean Cloud – A Setup Guide from Scratch!, then feel free to drop in below comment box. Also, please subscribe to our restoreBin YouTube channel for amazing videos tips. Cheers!

Share

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *