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:
- Go to DigitalOcean (special link with $50 free credits)
- Hit [Sign up] button on the Home Page
- Enter Email Address and desired Password OR you can even register with Google or GitHub Account using SSO
- Verify your Email ID (not required for SSO)
- Enter the Payment details; Credit Card or PayPal (Do not worry! you won’t be charged until credits are used or expired)
- And finally login to your DigitalOcean dashboard
You’ll be asked for a couple of basic questions along with the 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.
- Hit on Create Droplet
- Select the latest Ubuntu OS 20.04 (current stable version while writing this post)
- Choose Droplet Size. I recommend using at least 1 GB RAM for smooth functioning.
- Select Data Center (based on targetted region/country)
- Select Additional Option (if required – not necessary for WordPress)
- Number of Droplets: 1
- Hostname: yourdomain.com (or anything you name it!)
- Hit on Create button
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.
Adding Domain Name and Configure DNS settings
Currently, DigitalOcean doesn’t have a domain registration feature. So you need to buy the domain outside and point the nameservers towards DigitalOcean’s NS for managing the 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.
- Search for desired Domain Name on domains.google.com
- Check the availability for domain
- Add to Cart (if the domain name is available)
- Check out with free Privacy Protect add-on
- Complete payment transaction
- 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 the DigitalOcean dashboard.
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:
- Login to DigitalOcean dashboard
- Navigate to Networking tab in left-sidebar
- Switch to Domain tab
- Enter the domain name (example.com)
- Select the Droplet from the drop-down (if you’ve multiple droplets)
- Hit on Add Domain
- The domain name will start appearing
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 records 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 the Zone file (at the bottom of the same page).
Here are a few DNS settings that I think you should consider adding:
Record Type | Value | Point to |
CNAME | www | example.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 Type | Value | Point to |
MX | 1 | aspmx.l.google.com. |
MX | 5 | alt1.aspmx.l.google.com. |
MX | 5 | alt2.aspmx.l.google.com. |
MX | 10 | alt3.aspmx.l.google.com. |
MX | 10 | alt4.aspmx.l.google.com. |
Alternatively, you can also just hit on the button [Add Gmail MX Record] to automatically add these into 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.
- Enter the IP address of droplet server
- Use port as 22
- Click Connect button
- The terminal will start connecting to the cloud server
- Enter the Username that you’ve received in mailer (default is root)
- Enter the password (invisible while typing)
- You’ll be logged into Ubuntu Cloud droplet
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.
For extensive details, you can refer to the 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.4 version (updated from php7.3).
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.4 php7.4-cli php7.4-common php7.4-fpm php7.4-curl php7.4-mbstring php7.4-mysql php7.4-zip php7.4-xml php7.4-gd php7.4-intl php7.4-soap
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 processor security.
We will also need to adjust the Nginx configuration for PHP-FPM to enhance the performance and speed-up with FastCGI.
Install and Configure MySQL Database for WordPress
Now that the 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.4-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.
- Database name: wpdatabase
- Database user: wpuser
- Database password: wppassword
Login into MySQL server via SSH using root user account:
mysql -u root -p
Enter the root user password when prompted.
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;
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 the 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; } }
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 to 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
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.