Last updated December 17, 2019


Goal

Make a copy of a site that you can use to develop new features and test updates on.

Site prerequisites

  • You have a live, developed site that you would like to make a copy of for development purposes.
  • If you want to use Drush for some of the steps in this task, Drush must be installed. See Section 3.2, “Concept: Additional Tools”.

Steps

Making a Development Site

  1. Follow the steps in Section 3.4, “Preparing to Install”, so that you have hosting set up for your development site, you know where the web root is for your development site, and you have an empty database and database user for your development site to use.
  2. Make a database dump file from your live site’s database. Try one of the following methods:

    • If you are using MySQL as your database, and your live site’s server has phpMyAdmin installed (it is available from many hosting control panels), use the Export tab in phpMyAdmin to export in SQL format. Using gzip compression on the output file is suggested, to reduce the file size.
    • If you are using MySQL and have access to the command line, use this command (substituting in your site’s database name, user name, and password):

      mysqldump -u USERNAME -p'PASSWORD' DATABASENAME > BACKUPFILE.sql
    • If you prefer to use Drush, use this command:

      drush sql-dump > BACKUPFILE.sql
    • Use the contributed Backup and Migrate module from within your live site. See Section 11.3, “Downloading and Installing a Module from Drupal.org for instructions on installing contributed modules.

      You now have a database dump stored in the file BACKUPFILE.sql. For security reasons, avoid storing this file on your hosting server anywhere under the Drupal site root. This will prevent others from getting a copy of your database.

  3. Copy all of the files from the web root of your live site to the web root of your development site.
  4. Edit the sites/default/settings.php file under your development site’s top-level directory in a plain-text editor. Find the lines near the end that contain the database name, database username, and database password, and update them to the information about the development site database you set up. The lines look something like this (before editing):

    $databases['default']['default'] = array (   'database' => 'live_site_database_name',   'username' => 'live_site_database_username',   'password' => 'live_site_database_password',
  5. Check whether your settings.php file has the following setting; if yes, then you will need to edit this to point to your development site URL instead of your production site URL:

    $settings['trusted_host_patterns']
  6. Import the database dump file you created, into the development site’s database. Try one of the following methods:

    • If you are using MySQL as your database, and your live site’s server has PHPMyAdmin installed (it is available from many hosting control panels), use the Import tab in PHPMyAdmin. You may find that you have to restart the import a few times, if your database was large.
    • If you are using MySQL and have access to the command line, use this command (substituting in your site’s database name, user name, and password; if you made a gzip-compressed backup file, you will also need to uncompress it first):

      mysql -u USERNAME -pPASSWORD  DATABASE_NAME < BACKUPFILE.sql
    • If you prefer to use Drush, use this command:

      drush sql-query --file=BACKUPFILE.sql
  7. If your development and live sites need to have different configuration, then you have to use configuration overrides in the settings.php file. The $config variable will help you maintain override values separately from the standard configuration data. For instance, you might want the site name to be "Anytown Farmers Market" on the production site, but "Development Site for Anytown Farmers Market" on the development site. To do that, you could have the production value in the site configuration (in the database), and on the development site, in the settings.php file, you would need to have:

    $config['system.site']['name'] = "Development Site for Anytown Farmers Market";

Expand your understanding