In this tutorial, we will learn how to migrate WordPress to AWS Instance. Many of us want to transfer/move his WordPress site to an Amazon Web Services EC2 instance. For them, we have found an easy way to migrate a WordPress site from shared hosting to AWS.
Step 1: Launch an EC2 Instance
1. Sign in to AWS and click on Services from the menu bar. And then click on EC2. From the left sidebar click on Instances.
2. Click on Launch Instance button. There are many types of AMIs (Amazon Machine Image). But we will select Amazon Linux AMI (the first one) for this tutorial. Click on the Select button. Next, we will select free tier eligible t2.micro as the Instance type. Here you may select a higher instance type with more RAM memory. After that click on Next: Configure Instance Details.
3. Here we will select our Subnet like the image below and click Next: Add Storage
4. Select your preferred storage size for your Instance. We inserted 20Gb as storage. Click on Next: Add Tags.
5. Add a tag for your EC2 instance and click on Next to configure security group. Select create a new security group and add a name for your group.
6. After that click on the Add Rule button and add two more rules to allow HTTP and HTTPS connection to your instance. Click on Review and Launch.
7. Click on Launch to launch your AWS EC2 Instance!
8. You will be asked to select or create a new key pair. Select create a new key pair from the drop-down menu. Name your key pair and then click on the Download Key Pair button. Store this key pair in a safe place. We will need this key pair to connect to our EC2 instance using PuTTY.
9. Click on Launch. Now go to EC2 and make sure your newly created instance is running.
Step 2: Allocate Elastic IP
1. From the left sidebar click on Elastic IPs.
2. Click on Allocate New Address and then Allocate. Click on the Close button. Select your newly allocated IP and select Associate address.
3. On the next page select your instance to associate this with your Elastic IP. After that click on Associate. And then click Close.
4. Go to Instances from the left sidebar. Select your Instance. From the lower part of the window copy the Public DNS or Public IP address. We will need this address to log in to our instance using PuTTY.
Step 3: Install a LAMP Web Server with the Amazon Linux AMI
Now that we have created our EC2 Instance and allocated an Elastic IP address to the instance, we need to install LAMP server (i.e Apache server) on it to make it ready to host our WordPress site.
We will connect to our Linux Instance using PuTTY. Download PuTTy and install it on your PC. If you don’t know how to connect to your Linux Instance from Windows using PuTTY follow these steps:
Connecting to your Linux Instance from Windows using PuTTY
- Open All Programs > PuTTY > PuTTYgen
- Click on Load and in the dialog box select All Files as the file type. Then select your Key Pair PEM file which you have downloaded earlier.
- Click OK and then Save Private Key
- Save the PPK file on your PC
- Open PuTTY
- In the Hostname field enter ec2-user@Public_DNS. Here Public DNS is the address that you have copied earlier.
- Leave the port number as 22
- Click Connection from the left side panel and enter 180 in the Keepalive field.
- Click SSH and then Auth.
- Click Browse to select the PPK file that you have generated earlier
- Click Open
- Click Yes
Now that you are connected to your EC2 Instance, you are ready to set up your Apache server!
1. Enter the following command to perform a quick software update on your instance.
sudo yum update -y
2. Then run the following command to install multiple software packages to install LAMP server.
sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd
3. Start the Apache server
sudo service httpd start
4. To make sure the Apache server starts at every system boot enter this command.
sudo chkconfig httpd on
5. We need to set certain file permissions to allow WordPress to write, edit or delete files on our server. To do this enter following commands one by one.
sudo usermod -a -G apache
ec2-user
exit
Again login to your Instance using PuTTY and run following commands one by one.
sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;
Restart the Apache web server to pick up the new group and permissions
sudo service httpd restart
6. Install PHP ZIPArchive module
sudo yum install php70-zip
7. Restart Apache
sudo service httpd restart
Step 4: Secure MySQL Server
- To secure the database server run the following commands one by one
sudo service mysqld start
sudo mysql_secure_installation
- If you are entering MySQL for the first time hit the enter button on your keyboard. Then insert ‘y’ and again hit the enter button.
- Now you will have to set a strong master password for your MySQL server. Insert the password twice here. You will not see anything while you type your password here. Store your password in a safe place for future use.
- Now type ‘y’ and press the enter button every time you are asked to type Y/N.
- To enable MySQL server to start at every system boot enter the following command.
sudo chkconfig mysqld on
- Now restart Apache server
sudo service httpd restart
Step 5: Create a New Database and a User for your WordPress Site
1. We will create a new database on our MySQL server. To do this run this command.
mysql -u root -p
2. Type the master password that you have created earlier and press the enter button. Now type the following command.
CREATE USER '
wordpress-user
'@'localhost' IDENTIFIED BY 'your_strong_password
';
3. Here replace
and wordpress-user
with your username and password. Make sure to save your username and password in a safe place. We will need them later.your_strong_password
4. Run this command to create a new database.
CREATE DATABASE '
wordpress-db'
;
5. Here replace
with your database name. Store this name for future use.wordpress-db
6. Now grant full privileges for your database to the WordPress user that you created earlier.
GRANT ALL PRIVILEGES ON '
wordpress-db'
.* TO "wordpress-user
"@"localhost";
7. Now flush the database privileges.
FLUSH PRIVILEGES;
8. Exit MySQL
exit
Allow WordPress to Use Permalinks
1. To allow WordPress to use permalinks and .htaccess file run this command
sudo nano /etc/httpd/conf/httpd.conf
2. Find the section that starts with <Directory “/var/www/html”> using the scroll key of your keyboard.
<Directory "/var/www/html"
…
AllowOverride None
….
</Directory>
3. Here replace None with All
AllowOverride All
4. Press Ctrl+X. Type ‘y’ and then press enter button to exit.
5. Type ‘exit’ to close PuTTY.
Step 6: Set Up Duplicator to Migrate WordPress to AWS Instance
1. Login to your WordPress site on your old host. Install and activate Duplicator plugin. Go to Duplicator > Packages from your dashboard. Click Create New.
2. Click Next. Wait for sometime. Now click Build.
3. It may take several minutes to finish building the packages. Keep this window open until Duplicator plugin finishes building the packages. Download both Installer and Archive files.
Step 7: Upload these Files to Your EC2 Instance
1. There are many ways to upload files to EC2 Instance. We will use WinSCP here. Download and install WinSCP. Open it.
- To connect to your Instance using WinSCP type the same hostname that you have used for PuTTY.
- Click Advanced and then SSH > Authentication.
- Here browse folders to select the PPK file you used to connect using PuTTY.
- Click OK and then Login.
2. Once WinSCP establishes a connection to your EC2 Instance, navigate to /var/www/html from right side panel of WinSCP.
3. On the left side panel navigate to the folder containing the Installer and the Archive files that you have downloaded from your WordPress site.
4. Select those files and right click to select Upload to upload these files to /var/www/html folder of your Instance.
Step 8: Routing Traffic to an Amazon EC2 Instance (Add Domain)
1. Get IPv4 Public IP address of your EC2 Instance from step 2.
2. Open the Route 53 console at https://console.aws.amazon.com/route53/
4. Under DNS Management click Get started now.
3. Click Hosted Zones from the left side panel.
4. Click Create Hosted Zones
5. Again click create hosted zones.
6. In the right side panel enter your domain name. Click Create.
7. Click Create Record Set. In the value field enter the IPv4 Public IP address of your EC2 Instance. Keep other values default. If you are moving your site to a subdomain you may add subdomain name in the name field. Click Create.
Step 9: Install Your WordPress Site on Your New Host (AWS)
1. Go to All Programs and open Notepad with administrative rights
2. Go to File > Open and navigate to C:\Windows\System32\drivers\etc folder.
3. Select All Files as the file type to see the hosts file. Open this file.
4. Create a new line and insert the IPv4 Public IP address and your domain name adding a space between them.
5. Visit this URL on your browser. Replace yourdomain.com with your domain name.
yourdomain.com/installer.php
6. Tick mark the box to accept terms and notices and click Next.
7. Enter the database name, username, and password you created in step 5. Then click Test Database.
8. If you see a success message like this, click Next. If not check your database credentials.
9. A prompt will ask you to confirm this action. Click Yes. Wait for sometime. Then click Next. Keep the window open until the installer install your WordPress site on your new host(AWS).
10. Once the installation is finished, Duplicator plugin will ask you to login to your site.
11. Login to your site’s dashboard which is now hosted on your AWS EC2 Instance and delete the WordPress installer files from Duplicator plugin.
12. Undo all changes that you have made to your hosts file.
Step 10: Change Nameservers of Your Domain
1. Get the nameservers from your domain’s Hosted Zones of Route 53 console.
2. Add these nameservers to your domain’s control panel. It will take 24 to 48 hours to propagate your domain to your new host.
You are all done! Now you know how to migrate WordPress to AWS instance.
thanks you so much dear brother…..
you help me alot for this problem…..
keep do the good work like this god bless you bhaiijaan…..love you from India
You are welcome.
Hi There,
Thanks a lot for the indepth step-by-step guide to migrating a wordpress site over to AWS. Great work!
I have one question? Do you have an idea in terms of price comparison when comparing WordPress hosting to the cost of running it on an EC2 instance?
Thanks
Patrick
Thanks for your remarks, and I actually do not have sufficient knowledge about the pricing of present WordPress hosting plans.
Hello! I am going to migarate my site to AWS , if i face any problem, i ask for help, kindly reply in time. Thanks😊
Sorry, I am late to answer your questions. Did you complete your website migration successfully?