Categories: How To's

How to move WordPress website from Staging server to production?

WordPress is open source CMS you can use to create a beautiful website, blog, or app. Nearly 27% of the websites are built on WordPress CMS. Developers who build websites on wordpress generally host it in a staging environment. They setup wordpress, create pages, install and customize themes, install plugins etc, to create a fully functional website. Once the website is completed and ready to bring online, it has to be moved to the production server. Thankfully, the task is not difficult. It basically involves the following steps.

1. Host the production website.
2. Copy the files.
3. Backup and restore the database.
4. Change the Site URL.

1. Host the production website.

The first step is to host the production website on a server. It might be a shared server, a vps or a dedicated server. The server should support PHP and MySQL. Though the website can be hosted on Windows, I would prefer Linux with Apache, PHP and MySQL. If you are hosting on a shared server, you will get a control panel like Plesk or cPanel to manage the website. Once the website is hosted, create the MySQL database for the website and create the appropriate DNS entries so that the domain resolves correctly.

2. Copy the files.

The next step is to copy the files/folders of the website from the staging server to the production server. You can download the files and upload to the website using FTP. If you have root access of both the servers, you can also move the files using SCP. If you move the files using SCP, make sure to set the correct permissions as the permissions of the files/folders will change to root. The files/folders should be assigned the permission of the user under which the website is hosted. In both the cases, also check if the .htaccess is copied to the production server. Generally the .htaccess file does not copy as it is hidden. In this case, you have to copy the .htaccess file manually.

3. Backup and Restore the Database.

The third step is to backup the MySQL database in the staging server. You can use the mysqldump command to backup the database. Alternatively, you can backup the database using PHPMyAdmin if you have it installed in the staging server. Once the backup is completed, you can copy the backup file either using FTP or SCP to the production server. In the production server, you can restore the database backup either using the mysql command or PHPMyAdmin.

4. Change the Site URL.

Even after completing the above steps, you will still not be able to access the website properly as it is redirect you to the staging website url. The reason is that the siteurl parameter is set to the staging website url. You have to change it to the production website which is not possible from wordpress admin as the website will still redirect to staging website if you access the wordpress admin. To change the Site URL, open the wp_options in PHPMyAdmin and change the value of the siteurl and home records to the production website url. If you don’t have PHPMyAdmin, you can use the following SQL queries to modify the values.

update wp_options set siteurl=’www.sitename.com’ where siteurl=’staging.sitename.com’
update wp_options set home=’www.sitename.com’ where home=’staging.sitename.com’

In the above queries, wp_options is the name of the table containing the values of the Site URL, www.sitename.com is the address of the production website and staging.sitename.com is the address of the staging website.

Once the above steps are performed correctly, you will be able to access your website which will be live on the production environment.

Nitesh Shah

Share
Published by
Nitesh Shah

Recent Posts

How to setup first Azure Virtual Machine?

Setting up your first Azure Virtual Machine can be done by following these steps: Create…

1 year ago

How to setup Amazon Cloudfront and S3 to serve static resources

Amazon CloudFront is a content delivery network (CDN) that helps you serve static content such…

1 year ago

Step-By-Step Guide To Setting Up An AWS Application Load Balancer

Step-By-Step Guide To Setting Up An AWS Application Load Balancer Are you looking for a…

1 year ago

How to restore MySQL database from .frm and .ibd files?

MySQL databases often get corrupted due to issues like hardware failure, file system failure etc.…

4 years ago

SQL Server Replication

SQL Server Replication is the process of copying databases from one node to another to…

5 years ago

101 System Admin Tools to make life easy

Here are 101 System Admin tools which make System Admins' life easy.

7 years ago

This website uses cookies.