Here I am going to tell you how to manually move WordPress site to local server. In this tutorial I am going to show you only the manual process and I won’t use any plugin to move live WordPress site to local server.
I will show you here how to move your live WordPress site from shared hosting as well as VPS hosting servers. To backup MySQL database and WordPress website files from VPS server I will use the command line tool (Unix shell terminal). To backup MySQL database and WordPress website files from Shared hosting server I will use cPanel (phpMyAdmin and File Manager respectively).
Why do you need to move your live WordPress site to local server?
Your live WordPress site might not have any problem and is running fine on production server for a long time without any problem.
Suddenly one day you find that you need to change or update in your WordPress site.
The changes or updates may be one or more from the below list:
- You want to change the existing theme
- You may want to add a new plugin
- You want to update the version of PHP
- You may want to upgrade your MySQL server
- You want to create your own plugin
- You want to change some default functionalities
- Or may be more…
Now while you want to do some changes or updates you may want to work on the same data as your live WordPress site is running so that it will give you the exact feeling of what you want to achieve.
It is always good idea to make some changes on your local copy of the website instead of directly changing the live web site. If anything goes wrong on your live WordPress site then your users will face critical site error and your users may leave your site with frustrations. It will give your users a bad experience.
Let’s start exporting the required WordPress files from live server and setup in the local server.
Export MySQL Database
The next step is to export your website’s database which needs to be used for the local website setup.
If your WordPress site is hosted on VPS (Virtual Private Server), then to export MySQL database make sure you login to your VPS server using putty or any other compatible client.
If your WordPress site is hosted on Shared hosting server then you need to login to cPanel and from the cPanel you need to login to phpMyAdmin tool to backup the MySQL database.
Please go through the complete tutorial on How to backup MySQL database.
Export WordPress Files
To backup WordPress files from Shared hosting, login to cPanel and select File Manager.
Once you are inside the File Manager, look for public_html folder. Do a right-click on public_html folder and choose Compress to make an archive zip file of your WordPress site files.
This will create a new compressed file public_html.zip in the same directory (inside File Manager folder). Do a right click on the zip file and select Download.
If you don’t have access to File Manager, you can choose to download the zip file through FTP client. Open your FTP Client (FileZilla or any other), enter your FTP Credentials and download the public_html.zip folder. Or even you can directly download the WordPress files through FTP client without creating a zip file.
To backup WordPress files from VPS server, login to your VPS server using putty or similar client. Generally in VPS server people are habituated to work in the Unix shell terminal. If you are using cPanel or any other GUI based interface probably you can do the job for exporting database and site files easy, but here I am going to show you how to export using command from Unix terminal.
Copy your wordpress files from actual location to temporary location. For example, if your live site files are under /var/www/html folder and if you want to copy files to a temporary folder /home/<username>/site, then you can execute the following command on your Unix shell terminal:
$ sudo cp -rp /var/www/html/* /home/<username>/site/
In the above command
sudo is being used for the non-root user who has the admin privilege.
cp is the command for copying files from a source to a destination. Options
rp were passed to the command
r option tells to copy recursively all files and folders from /var/www/html directory and the
p option tells to preserve everything (for example, original ownership, timestamp, etc.) for files & folders.
If site folder does not exist under the username then you can create using the command:
Once copied, you can go inside the folder site (cd site) and create a compressed file for your all WordPress files. For example, you may create a zip file with date for your site – wordpress-27-08-2021.zip. To create the zip file execute the following command:
$ sudo zip -r wordpress-27-08-2021.zip .
zip will instruct to create zip file. The
r option in the
zip command will compress recursively. The dot (.) in the end will consider all files to be compressed under the current directory.
Once your wordpress-27-08-2021.zip file gets created, you can connect through FTP client (FileZilla or any other client) to download the compressed file to your computer.
Setup Local WordPress Site
Now you have exported the required database and site files from your live server. Let’s setup in the local environment. Please make sure you setup Apache HTTP Server, MySQL Server and PHP in your local computer system.
- Extract your WordPress zip file which you had exported from your live server.
- Put the WordPress site files under local Apache htdocs folder – wordpress, where wordpress is the folder under htdocs and under this folder, for example, you are going to copy your extracted WordPress files.
- Next you need to import your MySQL SQL file (.sql) which you exported from your live server. You can use any MySQL client – sqlyog, heidisql, phpMyAdmin, etc. Create a database in the MySQL server, for example, wordpress. Or even better if you keep the same database name as you have in your live server otherwise you have to change the database name in the .sql file before you import in the local MySQL server.
- Change the database username/password in wp-config.php file according to your local database setup. Mostly you need to update fields –
define('DB_NAME', 'database name'); define('DB_USER', 'username'); define('DB_PASSWORD', 'password');– in wp-config.php file:
- You need to update the values in few tables to make your local WordPress site works.
UPDATE wp_options SET option_value = replace(option_value, 'https://example.com', 'http://localhost/wordpress') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET post_content = replace(post_content, 'https://example.com', 'http://localhost/wordpress'); UPDATE wp_postmeta SET meta_value = replace(meta_value, 'https://example.com', 'http://localhost/wordpress');
- Disable SSL by commenting the following lines if you have enabled in wp-config.php file:
define('FORCE_SSL_ADMIN', true); if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on';
- Enable mod rewrite for Apache if it’s not already enabled.
- Open httpd.conf file of Apache HTTP Server
- Find the line which contains #LoadModule rewrite_module modules/mod_rewrite.so and remove (#) from start of line to make the module enable. Also enable LoadModule access_compat_module modules/mod_access_compat.so.
- Find all occurrences of AllowOverride None and replace by AllowOverride All.
- You can comment or delete unnecessary lines of code from local environment, for example, Google AdSense, Google Analytics, Caching plugins, etc.
- You can now restart Apache HTTP Server if you made any changes to httpd.conf file. Now you can access the URL http://localhost/wordpress in the browser to visit your site in local environment.
If you find pages are not opening and gives error Not Found (404) then from Admin Dashboard go to Settings -> Permalinks -> Save without changing anything. It will fix the problem.
That’s all about how to move your live WordPress site to local server.