After being on shared hosting for quite a long time, I realized it was time to migrate my Website to a Cloud Hosting Platform.
I was paying $25 (Okay, $24.99), on a shared hosting platform. And the resources were limited. On the other side, Digital Ocean’s $20 plan comes with Four vCPUs, 80 GB SSD Disk with a 4 TB Transfer. Heck, That’s a daylight robbery.
So, just like you’re thinking right now, I made up my mind and started to migrate my Website from SiteGround to Digital Ocean.
1. A Quick Introduction
No matter what hosting you are using the website migration process is the same for every shared hosting.
So, that was a quick intro, as Promised 🙂 So, let’s get started with our Website migration.
But first, you need to have a complete BackUp of your Website on your computer. If you’re not sure about it, then I have a Step-By-Step Website Backup Guide.
So, after you have the complete Backup of your Website, let’s get started with the migrate part.
2. Migrating our Website to Digital Ocean
Creating Digital Ocean Droplet
We need to create a Droplet (yeah, that’s what they call the server) in Digital Ocean.
By the way, if you use this link, you can get a $100 free credit for 60 days. So, that’s helpful.
Now, head over to Digital Ocean, and from the top bar, click on Create and click on Droplet.
Choose an image and click on Marketplace from here, choose WordPress.
Scroll down the page, and choose the plan that best fits your Website.
You can add the block storage if you require any.
For the Authentication part, I’ll suggest using an SSH key, but you can also use a root password, but the SSH key is more secure.
If you don’t know how to set-up an SSH key, here’s a quick tutorial for it.
Now, choose the Hostname, type in your domain name, will be more convenient. Then click on Create Droplet.
2. Getting Started
Now you have the Droplet, copy the IP address and paste it into the URL section, you will see a default Digital Ocean page. It means we’re all set to go forward.
And if there’s an error, then you might have done something wrong, debug it.
I have divided the complete procedure into small blocks.
1 – Connecting to the Droplet with the SSH
Now you will need to log in to the Droplet to finish the WordPress Setup.
Here’s the complete guide that will help you log in to the Droplet through the SSH key.
After you are on the log in page, follow these commands.
2- Setting up the Droplet and Installing WordPress
1 – Add root as a username.
root
2 – Now, enter the password you’ve selected when creating an SSH key.
3 – As it’s your first time logging in to the Droplet through SSH, it will ask you to enter the Hostname (Domain name).
Type in your Domain name (without Https://, Http:// or www, e.g wordpress.com).
4 – It will then ask you to enter the email address for administrative purposes.
BTW, To clear the screen, I’ve used clear command.
5 – Then enter your username and password for the WordPress admin dashboard. But be sure that you save all the passwords so that you don’t forget them.
6 – Type in anything in the Blog Title.
7 – To say the information is correct, type in Y, and press the enter key.
8 – The next prompt will ask you if you want to use an SSL key, we will say No (type in N and press the enter key).
Congrats, WordPress is now successfully installed and activated.
3- Installing MySQL
On Ubuntu 20.04, you can install MySQL using the APT package repository.
Copy and paste these commands, and you will be good to go.
To get started, we will update the package on our server.
sudo apt update
Then install the MySQL server package.
sudo apt install my-sql server
It will install MySQL. But for other configurations, we need to set it up.
4- Configuring MySQL
We need to run the security script with DBM’S to change the less secure default options.
sudo mysql_secure_installation
Enter the password, I recommend, choosing the strongest one, for this type in ‘2’ and press the enter key.
Now, even though you have entered the password, we still need to do some configuration.
Now, the new prompt will ask you if you want to use this (you’ve just entered) or use the new one. Considering that you’re satisfied with the strength of the password you have used, type in Y and press the enter key.
And for the next prompts, choose Y, and it will remove all the anonymous users and the database.
Now that we have secured our MySQL installation let’s, create a dedicated user for MySQL.
5- Adding a Dedicated User to MySQL and Granting it all the Privileges
By default, the root user has all the Privileges, and now we want to create a new user and grant him all the Privileges.
Let’s get into MySQL.
sudo mysql
Once we are in MySQL, we can create a new user with, CREATE USER statement.
mysql > CREATE USER 'username'@'host' IDNETIFIED BY 'password';
Don’t forget to do this before pasting the above command.
Here, username = any username you want to use, for example, john.
And password = any strong password you want to use.
Host = This is the Hostname from which the user will connect. If you want to connect to the Ubuntu server locally, then you can use localhost.
After creating a user, we will grant the privileges to the user by using the following command.
mysql > GRANT PRIVILEGE ON 'database.table' TO 'username'@'host;
You might want to grant all the Privileges to the user, so if someone gets access to MySQL user, he’ll have complete access over every Data Base on the server.
You can find the complete list of available privileges on the official MySQL documentation.
Following this, we will now flush all the Privileges.
mysql > FLUSH PRIVILEGES
Then let’s exit the MySQL.
mysql > exit
You can now access MySQL using the following command.
mysql -u john -p
Replace john with your username
So, MySQL is up and running now.
3. Installing phpMyAdmin
With phpMyAdmin, users can easily interact with MySQL through a web interface.
So, now we will install phpMyAdmin on our server. Get started with some updates.
sudo apt update
And then install phpMyAdmin running these commands will require you to select different options.
Copy and paste the following command.
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
Now, when prompted to select the options, these are the options you should choose.
- For the server selection, choose apache2 and press enter. Important: If the server, apache2 is not selected, press space and tab to choose it.
- Press enter when prompted whether to use dbconfig-common to set-up the DataBase.
- Type-in the strong password (for phpMyAdmin) when prompted for it.
This installation will add the phpMyAdmin configuration file at the /etc/apache2/conf-enabled/ directory.
Now, we only need to add the mbstring extension.
sudo phpenmod mbstring
Then restart the apache2 webserver for the changes to effect.
sudo systemctl restart apache2
User Authentication and Privileges
After installing phpMyAdmin, it will automatically create a new DataBase for the user phpMyAdmin who can perform certain operations.
Configuring Password Access for the Root User
Let’s access MySQL to configure the phpMyAdmin.
sudo mysql
And now, to configure the root account to authenticate with a password.
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
Be sure to change the password to a strong password (of your choice).
And now we will create a new user (for phpMyAdmin) and give it a strong password.
mysql > CREATE USER 'john'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
Here, john = the username of your choice (you’ve selected it before).
And password = a strong password (of your choice).
We will now grant the privileges (of your choice) to the user.
mysql > GRANT ALL PRIVILEGES ON *.* TO 'john'@'localhost' WITH GRANT OPTION;
Let’s check the phpMyAdmin page before that, let’s exit the MySQL with the exit command.
mysql > exit
To check the phpMyAdmin page, type into the URL section (of your browser), IP Address (Droplet’s IP)/phpmyadmin.
Log in to the phpMyAdmin interface, either as root or with the new username and password you just configured (in the above configuration).
When you first log in to the user interface, it will look like this.
Congrats, so now we have phpMyAdmin installed. Let’s secure the system.
Securing phpMyAdmin
Run the following command.
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Add an AllowOverride All directive within the <Directory /usr/share/phpmyadmin> section of the configuration file.
After this press, ctrl+x, Y, and then press enter to save the changes.
Now enter the following command.
sudo nano /usr/share/phpmyadmin/.htaccess
sudo nano /usr/share/phpmyadmin/.htaccess
In this file, enter the following lines.
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
Save the changes and close the file.
Then restart the apache2 for the changes to take effect.
sudo systemctl restart apache2
Now when you access the phpMyAdmin page, you will be prompted with an additional security layer. Enter in your username and password that you just configured.
So, now we have the MySQL and phpMyAdmin set up. Let’s migrate our Website to the Digital Ocean droplet now.
4. Connecting the Domain name with Digital Ocean Droplet
Then we need to change the nameservers of the domain name to point it to Digital Ocean.
Change the nameservers of your Domain name to these nameservers.
ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com
If you don’t know how to do that then, use this quick guide.
The propagation time will take up to 24 hours. You can check it by using this link.
After your Domain name connects to your Droplet, we can now install SSL and secure the Website with the HTTPS:// protocol.
5. Using Cert Bot to get an SSL certificate
First, let’s see if our version of snapd is up to date. Run the following command.
sudo snap install core; sudo snap refresh core
Then, remove Cert Bot auto and any Cert-Bot OS packages with the following command.
sudo apt-get remove certbot
Now, let’s install Cert-bot on our Droplet.
sudo snap install --classic certbot
Let’s prepare the Cert Bot command.
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Then install the SSL certificate with the following command.
sudo certbot --apache
And now test automatic renewal, with the following command.
sudo certbot renew --dry-run
Visit your IP address to see if HTTPS:// enabled.
6. Importing the Existing Website’s Content
So, we’re on the last step, importing our existing Website’s content and DataBase.
Now, access your Droplet with WinSCP (alternative to FileZilla FTTPS Client).
Type in your username (root mostly) and the Hostname (it’s your Droplet’s IP), the port is 22, and enter your password in the password section.
The details for the WinSCP are the same as for the puTTy.
Go up the folder into your root directory.
Now, go to var — > www — > html
In the html, folder delete the html_old folder.
Now, again go back to the www directory.
And upload the web site’s content that you downloaded from the existing hosting server’s cPanel.
BTW: If you have missed it, then here’s a step-by-step guide to backup your website.
Once, uploaded you can extract it, use PuTTy (it’s more efficient). But before that, we need to install an unzip package.
Run the following command into PuTTy.
sudo apt-get install unzip
Then change the directory using the cd command.
cd /var/www/html
Then extract the public_html folder with the unzip command.
unzip public_html.zip
You will now see a new folder, public_html (extracted). Move all its files into the html folder.
Then restart the apache server using the command.
sudo service apache2 restart
7. Migrating the DataBase to Digital Ocean Droplet
Now, log in to the phpMyAdmin interface.
Create a new DataBase with the same name that your existing DataBase has.
Click on create, and it will create the DataBase for you.
Now, click on the small white icon (in front of your DataBase) and go to the Import tab.
Here you can see the maximum limit of upload is 16 MB, so we need to increase that limit.
To increase the upload limit, you can refer to this guide.
After that, you can upload the DataBase (of your existing Website). And you’ll be good to go.
So now restart the apache server for the changes to take effect.
sudo service apache2 restart
Congratulations on successfully migrating your WordPress website to Digital Ocean from the shared hosting platform.
Even though I’ve tried to give you the best step-by-step migration tutorial (on the internet), you might face some errors along the way I had too, but don’t get dishearted.
So, now your Website is even more powerful, up and running on one of the best Cloud servers.