Migrate a WordPress site from Alibaba Cloud SAS to ECS

Posted on 17 January 2022 by Alberto Roura.
alibaba cloudalicloudaliyunapacheecslampLinuxmigrationmysqlphpsasscpwordpress

Terms like “Cloud Computing“, “Cloud Server“, “Virtual Machine” or “Database” could be daunting for someone who is just starting. This is why I completely understand the people who are having a hard time deciding whether or not create a blog or e-commerce site. Even if you’re not an IT expert and have never created a cloud server before, Alibaba Cloud SAS (Simple Application Server) is the perfect choice for you. According to Alibaba Cloud, Simple Application Server is a new generation computing service for stand-alone application scenarios. It provides one-click application deployment and supports all-in-one services such as domain name resolution, website publishing, security, O&M, and application management. This optimizes the user experience of setting up a simple application and makes it easier for entry-level users to use cloud computing products.

In a nutshell, SAS can be a perfect way to get started in Cloud Computing, and combining it with a CMS like WordPress will make that idea of having a blog or an online shop a piece of cake.

This said, if your site grows and you feel you are in need of more complex controls such as Elastic IPs, Scaling or other more “technical” features in the cloud, you will definitely need to migrate your site from SAS to ECS (Elastic Compute Service). ECS is compatible with pretty much every feature for advanced networking, scaling, custom solutions and general O&M.

Step 1: Create The ECS Instance

First things first, and here it means you should create the ECS Instance before doing anything else, as we need as little downtime as possible. So, go to the ECS Console and create a new instance. As per specs, I recommend you to go with the same as what you had until now to start with, and go up as needed. So, if your SAS is 2cpu/2gb, go with the same. For the Image should be good if you use Ubuntu 20.04. Around networking, is up to you if you need an EIP or not, but choosing one will help you with a future migration.

Step 2: Install The LAMP Stack

This is my favourite combination of tools, the so called LAMP stack, which is nothing else than “Linux/Apache/MySQL/PHP“, nice team when working together!

Install Apache & PHP

Apache is the web server itself and PHP is the component that will process code to display dynamic content. It can connect to your MySQL database and hand the processed content over to Apache so that it can display the results to your visitors. So, run:

sudo apt update
sudo apt install apache2 php libapache2-mod-php php-mysql

Install MySQL

This will serve as the database for your WordPress site, to install it just run:

sudo apt install mysql-server

After installing MySQL, you need to configure it to setup basic config and a password:

sudo mysql_secure_installation

Step 3: Set Your WordPress Into Maintenance Mode

Now that our ECS instance is “ready to rock“, let’s bring down our WordPress on the SAS by putting it into Maintenance Mode. Why? Because we don’t want to lose any change that happens in the moving. Personally, I rather have a small window for downtime than losing a comment or a sale.

For this, still inside the SAS instance, just place the following piece of code at the bottom of your theme’s function.php file:

function maintenance_mode() {

if (!current_user_can( edit_themes ) || !is_user_logged_in()) {
  wp_die(We are moving. Please try again in a few minutes.);}
}

add_action(get_header, maintenance_mode);

With this snippet, nobody would be able to see or change anything on the site. We are ready for the move!

Step 4: Get A Copy Of Your Database

By using tools like “Adminer” or “phpMyAdmin“, you can easily connect to the database (checking the credentials inside the wp-config.php file) and download a copy of the entire database. The best thing is that, you cannot only connect to your local database, but also connect to the MySQL one running in the new ECS instance and importing the one from the SAS with ease.

I personally recommend Adminer, as is based in only one file and is easy to operate. Just download the adminer.php file to the same path of your wp-config.php file in the SAS instance and visit it from the browser. The interface is very easy to use and you’ll be able to export the data from the SAS and import it back into the new ECS in just a few minutes.

Step 5: Pack, Retrieve And Unpack All files

The last step to follow in the SAS instance will be to pack all the WordPress installation folder with tar. For this, locate the path of the WordPress installation and compress it running:

tar -czvf sas-wordpress.tar.gz /path/to/wordpress

Now, connect to the new ECS by SSH and upload the sas-wordpress.tar.gz to it. Go to /var/www/html and extract the contents of the file here.

NOTE: Remember, remove the code you wrote in step 3 and, if you set up the new database with different credentials than the old SAS instance, you should update the wp-config.php file before continuing with the data from step 2.

Step 6: Update DNS Records With New IP

If steps were followed and there is nothing strange or special with your WordPress site, this should be the last thing needed for the migration. Changing the DNS Records for your site will make the site available again to the public but serving the content from the new ECS Instance.

Usually, only the A Record of the domain is enough to update the site, as the www should be a CNAME pointing to the domain, therefore catching up the changes instantly and decreasing the chance for human error.

Step 7: Test

Well, well, well… Lift Off! If everything went well, your website should work as before and everything must be there as it was before. Magic!

If something didn’t quite work, please don’t hesitate to ask me, I have many (many many) years of experience with WordPress and I made hundreds (if not thousands) of migrations like this. Cheers!


Original article: Migrate a WordPress site from Alibaba Cloud SAS to ECS.

✉️ Contact

Ready to take the next step? Don't wait any longer! If you're interested in learning more about Guztia products and services, or if you have any questions or concerns, book a meeting today.

Book a Meeting

Our team of experts is standing by, ready to assist you with anything you need. Book a Meeting, and Guztia will take care of the rest.