Skip to main content

Copy Drupal site from live server to localhost

Copy Drupal site from live server to localhost

In this example, we are using xampp in localhost. This is the step:-

In live server

1) Activate maintenance mode | Configuration->Development->Maintenance Mode and will disable the site
2) Delete Drupal Cache | Configuration->Development->Performance
3) Copy the database from live server | using export
4) Copy the code from live server | using FTP 

In localhost

1) Create the database
2) Import the database from backup | read how to import large database
3) Change setting.php file

   From live server setting:-
   $settings['trusted_host_patterns'] = [
    '^mydomain\.com$',
    '^www\.mydomain\.com$',
  ];

 Change to:
  $settings['trusted_host_patterns'] = [ '^localhost$', ];

4) Change the database setting

From live server setting
$databases['default']['default'] = array (
 'database' => 'drupal_db',
 'username' => 'user',
 'password' => 'password',
 'prefix' => '',
 'host' => 'localhost',
 'port' => '3306',
 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
 'driver' => 'mysql',
);

Change to | in localhost (xampp) - username is root & no password
$databases['default']['default'] = array (
 'database' => 'drupal_db',
 'username' => 'root',
 'password' => '',
 'prefix' => '',
 'host' => 'localhost',
 'port' => '3306',
 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
 'driver' => 'mysql',
);

5) Remove the real domain HTTPS configuration to work in HTTP mode.
In case we have SSL enabled in our production server, we will have to remove the lines that allow us to redirect HTTP to HTTPS in .htaccess file.

# RewriteCond %{HTTPS} off
# RewriteCond %{HTTP:X-Forwarded-Proto} !https
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

6) Run update.php

Source/read more


Read more:-

Google AdSense
client = ca-pub-2898279488603899
slot = 9058461004
format = auto