How to download a website from live server to development local server?

download-move-website-from-live-server-to-local-development-server

In this post, we shall see how to download a website from live server to development local computer. I will be using a Drupal website as an example. On the local machine, I am running XAMPP stack on Windows. But the process would generally be the same for any other CMS or website for that matter. If you are looking for how to move or upload a website from local development computer to a live production server, following the steps here.



Usually most people develop website first on local development computer and then upload the website to a live server using FTP clients or directly from the web host interface. Some may then continue with further changes and developments on the live server instead of doing everything on local development computer and upload the changes/files. It is a good practice though – to develop and edit changes on local development computer as we would not want our websites to break due to some new changes. So, it is best to develop and test first on local development computer before uploading to live server. Though it is a duplication of work, it will save us the trouble if something should go wrong.

However, there may be cases where most common and non-risky changes might have been done on the production server more often than on the local development computer. And if you finally want to download the website to local development computer so that the local copy is exactly same as the one live, then you need to download the website. In the following steps, we shall see how to download a website from live server to development local server. As stated above, I will be using a Drupal website running on XAMPP on local machine running Windows. But the process would generally be the same for any other CMS or website for that matter. If it is a simple HTML website without any database involved, it is as simple as copying all the website files to the local machine and place the main website folder inside the WWW or htdocs directory for IIS and Apache respectively. 

How to move a Drupal Site from live server to development computer?

This is an example on Drupal running on XAMPP on Windows, so the directory names etc. may be different if you are using another CMS or another development stack. In this example, "drupalsite" is the name of the website just for example.

1.    Download the website files from live server
a.    Login to web host control panel or by using an FTP program, download the website files.

For Drupal sites, just download the “sites” folder as that is where all the website files are. If there has been some customization done outside the “sites” folder, you should download all the website files under root or "site" folder plus the folder containing the customization done.

2.    Download the database of the live website
a.    Login to the Drupal website as an Admin and flush all cache before exporting database. It will make the database file smaller and may also save us from some errors during the import.

To clear all cache in Drupal- 
go to “/config/development/performance” and click on “Clear all cache”.

b.    Login to the website’s phpMyAdmin, select the database for the website
c.    Click “export” tab and export the database
d.    It will be exported as a “.sql” file.

3.    Put the downloaded website files to the local development computer.
As discussed above, for Drupal websites, you may download the complete website files or just the “sites” folder provided there are no customization done outside the “sites” folder and  provided there is a previous version of the same website on the local server. In that case, you just need to download the “sites” folder and replace on the local server.

If all website files were downloaded from live server then-
If you have downloaded all the website files or you want to replace all the website files, then just rename the existing website folder on the local server with “_old” appended to the website folder name for the time being. If we face issues, we can still rename and remove “_old” to use it again.

Go to C:\xampp\htdocs\drupalsite and rename it to “drupalsite_old”

a. Now move the website files downloaded from live server to C:\xampp\htdocs\drupalsite

If only "sites" folder was downloaded from live server then-
For Drupal, if there are no customization done outside the “Sites” directory, you may only replace the “sites” directory, since that folder contains all the website files necessary.

a. In that case, look for sites folder under C:\xampp\htdocs\drupalsite and simply rename the sites folder to say “sites_old”. We can delete this folder if not longer required later.
b.  Move the "sites" folder downloaded from live server to C:\xampp\htdocs\drupalsite

That is all regarding moving the website files from live server to development server.

As discussed above, for Drupal sites, you may download all the website files and folders or just the “sites” folder if you already have a previous copy of the same website on the local server.

Try accessing the website locally just to see what it displays?
At this stage, if we try accessing the Drupal website or any CMS based website locally, we should get a PDO Exception error – access denied etc. That is because the details in the Drupal (or other CMS) settings or configuration file do not match with the details required by the local database. The actual database name, the user, password are usually different on the live server and local server. Usually on local server, we mostly use “root” as the user along with whatever password set for the root user. On live server, we normally don’t or can’t use “root” user. Database names also may have some prefix assigned by the web host but that is not the case on local server.

Accessing the website without updating/replacing the old website database:
If you want to access the website (with the one downloaded from live server) with the same old database of the website existing on the local machine, you can change the following in setting.php file which is under \drupalsite\sites\default folder. You may edited the details in bold below as per the user, password and database name as on the local database.

$databases = array (
  'default' => array (
    'default' => array (
      'database' => 'mtcdb',
      'username' => 'root',
      'password' => 'root',
      'host' => 'localhost',
      'port' => '', 'driver' => 'mysql',  'prefix' => '',   ),  ),);

4.    Import website database from live server to local server
So far we have downloaded a website from live server to local server. If this is a basic HTML website without a database, it will work. But for websites with database, such as CMS based websites, we also need to replace the existing database with the database downloaded from the live server.

a.    Start XAMPP, start Apache and MySQL services
b.    Open http://localhost/phyMyAdmin and login if password is set
c.    First export the database to keep a backup of the local website just in case. We can delete it later if not required.
d.    Now while in phpMyAdmin, select the database of the local website, scroll down and check how many tables there are in the database. We can compare later just in case.
e.    Now, “check all table” at the bottom of the page
f.    From the drop down menu next to “Check all Tables”, select “DROP”.  Click
“Yes” when prompted and wait for it to complete.

phpmyadmin-select-tables-drop
Dropping tables from database in phpMyAdmin


g.    Now, click on IMPORT to import the downloaded database.
h.    Click “BROWSE” and locate the SQL database downloaded from the live server and import.
i.    After the database is imported, click on “STRUCTURE” tab and check that the numbers of tables are the same.

Note. The number of tables may not be the same if there were significant changes done on the live server or if some modules were installed on the live server after it was last updated from local server. But since we have already replaced the “sites” folder, the modules updated on live server are also included under “sites” folder.

k. Though we cleared all cache before exporting database from live server, we may also select all the table with prefix “cache” and EMPTY the tables, just in case. After selecting all the cache tables and after selecting “EMPTY”, you should get  the below SQL query to be executed. Click Yes to continue.
TRUNCATE `cache`;
TRUNCATE `cache_admin_menu`;
TRUNCATE `cache_block`;
TRUNCATE `cache_bootstrap`;
TRUNCATE `cache_field`;
TRUNCATE `cache_filter`;
TRUNCATE `cache_form`;
TRUNCATE `cache_image`;
TRUNCATE `cache_libraries`;
TRUNCATE `cache_menu`;
TRUNCATE `cache_page`;
TRUNCATE `cache_panels`;
TRUNCATE `cache_path`;
TRUNCATE `cache_update`;
TRUNCATE `cache_variable`;
TRUNCATE `cache_views`;
TRUNCATE `cache_views_data`;
l. After the database is successfully imported, it is now time to check database login details on “settings.php” at \drupalsite\sites\default. Since we did not drop the entire database but only dropped the tables, the name of the database remains the same locally. So it need to be updated below if the live database name is different.

$databases = array (
  'default' =>
  array (
    'default' =>
    array (
      'database' => 'mtcdb',
      'username' => 'root',
      'password' => 'root',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

Update the database name, username and password for MySql as per the details configured on the local server.

m.    Test by accessing the website locally by access http://localhost/drupalsite

Note that the user account to log in to the website would be that of the live site, not the previous local website if they are different that is. But if the development started on the local machine initially, and was uploaded to the live sever, then the username should be the same. If password for users were change on live server, then use the same passwords as used on the live server.


No comments