11.8. Making a Development Site
- 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 第 3.2 节 “Concept: Additional Tools”.
- Follow the steps in 第 3.3 节 “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.
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 第 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.
- Copy all of the files from the web root of your live site to the web root of your development site.
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',
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']
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
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";
- Verify that the development site is working correctly.
- Log in to the development site as an administrator, and clear the cache. See 第 12.2 节 “Clearing the Cache”.
- 第 11.10 节 “Deploying New Site Features”
Attributions
Written and edited by Jennifer Hodgdon, Joe Shindelar at Drupalize.Me, and Jojy Alphonso at Red Crackle.
Source file: install-dev-making.asciidoc
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion