How Can We Help?
< All Topics
Print

Creating a Development Site in Drupal: A Step-by-Step Guide

a) How do I create a development site in Drupal ?

1. First, follow these Getting Ready for Drupal Installation section steps to ensure hosting is set up, know the web root, and have an empty database and database user to set up your development site.

2. Then, you can use one of the following methods to create a database dump file from the live site’s database:

  • To export SQL format from MySQL to a live site’s server with phpMyAdmin installed, use the Export tab in phpMyAdmin. Gzip compression is recommended for reducing file size in output files.
  • To access your MySQL database, use the mysqldump -u USERNAME -p’PASSWORD’ DATABASENAME > BACKUPFILE.sql command, replacing your site’s database name, username, and password.
  • If you prefer to use Drush, use the drush sql-dump > BACKUPFILE.sql command.
  • Utilize the backup and migration modules provided within the live site.

The database dump is stored in the BACKUPFILE.sql file, but it should not be stored under the root of your Drupal site on your hosting server for security reasons.

3. After that, copy all files from the live site’s web root directory to the development site’s web root directory.

4. Next, edit the sites/default/settings.php file in the development site’s top-level directory in a plain text editor. Find the rows with the database name, username, and password and update them with information about the set-up development site database:

$databases[‘default’][‘default’] = array (
‘database’ => ‘live_site_database_name’,

‘username’ => ‘live_site_database_username’,
‘password’ => ‘live_site_database_password’,

5. Then, check your settings.php file for the following settings and edit it to point to your development site URL instead of your production site URL:

$settings[‘trusted_host_patterns’]

6. After that, you can use one of the following methods to import the database dump file into the development site’s database:

  • To import a large MySQL database into PHPMyAdmin on a live site’s server, use the “Import” tab in PHPMyAdmin, available from various hosting control panels.
  • To update your MySQL database, use the mysql -u USERNAME -pPASSWORD DATABASE_NAME < BACKUPFILE.sql command, replacing your site’s database name, username, and password. If you created a compressed backup file, decompress it first.
  • The command drush sql-query –file=BACKUPFILE.sql can be used if you prefer to use Drush.

7. Finally, configuration overrides in the settings.php file can be used for different configurations on the development and live sites. $config variables help maintain coverage values separately from standard configuration data. Production values can be found in the database:

$config[‘system.site’][‘name’] = “Development Site for Anytown Farmers Market”;

b) How do I use Composer and Git to download files in Drupal ?

a. Use Git to download a project

1. First, navigate to one level above the directory in the command-line window, such as the network root directory for core software or the module directory or subdirectory to move files to a specific directory.

2. Then, navigate to the desired page on Drupal.org, such as the Drupal core software or admin toolbar module, and click on it for contributions.

3. After that, click on the Version Control link located at the top of the page to access the Git command for a project.

4. Next, copy the git clone command under the first setup repository and paste it into the command line:

git clone –branch 8.2.x https://git.drupal.org/project/drupal.git

5. The process creates a project directory named Drupal, downloads necessary files, and, if necessary, renames the directory.

6. If you downloaded the Drupal project (core software), follow the instructions below to download its external dependencies.

7. Finally, navigate to the created directory and execute the command git pull to update the files in the project’s Git repository to the latest version.

b. Use Composer to download external core dependencies

1. First, change the core software’s root directory.

2. Then, run the command composer install on the command line to download external dependencies.

c. Use Composer to download the core software

1. First, change the directory level on the command line to move the software to its desired location.

2. Then, enter the following command, where my_site_name is the directory you want to create:

composer create-project drupal/drupal my_site_name

d. Use Composer to download a module or theme

1. First, input the command “composer config repositories.drupal composer https://packages.drupal.org/8” from the root of your site to contribute modules and themes to your site.

2. To override the default location for uploading downloaded modules and themes in Composer, edit the composer.json file at the root level of your site installation. Change the “extra”: {, line and add the following line after it. This will ensure that modules are located in the correct subdirectory.

“installer-paths”: {
“modules/contrib/{$name}”: [“type:drupal-module”],
“modules/custom/{$name}”: [“type:drupal-custom-module”],
“profiles/contrib/{$name}”: [“type:drupal-profile”],
“themes/contrib/{$name}”: [“type:drupal-theme”],
“themes/custom/{$name}”: [“type:drupal-custom-theme”],
“libraries/{$name}”: [“type:drupal-library”],
“drush/{$name}”: [“type:drupal-drush”]
},

3. Then, identify the project name in the last part of the project page URL, like Geofield at https://www.drupal.org/project/geofield, to add a contributed module or topic.

4. To download the contributed module or theme and its external dependencies, enter the following command in the root directory of your site, replacing the short name with your site’s name:

composer require drupal/geofield

e. Use Composer to update a project’s files

1. First, the short name of a project to be updated is determined by the last part of the project.page URL, like Geofield in the Geofield module.

2. Then, enter the version number as 1.7 for version 8.x-1.7 or 3.1 for core software version 8.3.1.

3. Next, enter the following command in the root directory of the site, replacing the short name with the correct version number.

composer require drupal/geofield:1.7

c) How do I deploy new site functionality in Drupal ?

1. First, open the local development site.

2. Then, navigate to Configuration to select Development, then click Configuration synchronization to select Export, and click Single item (admin/config/development/configuration/single/export) in the Manage administrative menu to access the single export page.

3. After that, select View from the list of configuration types.

4. Next, choose the vendor from the Configuration Name list, and the configuration will be displayed in the textarea.

5. Then, copy the configuration from the textarea.

drupal

6. After that, open the production site.

7. Next, navigate to Configuration, select Development, and click Configuration synchronizationImport to select single item in the manage administrative menu (Admin/Configuration/Develop/Configuration) to access the import page.

8. Then, select View from the Configuration Type list.

9. After that, paste the configuration into the textarea.

10. Next, click the “Import” button, and it will prompt a confirmation page.

11. Then, click Confirm.

12. Finally, verify that the view has been imported by navigating to the Manage administrative menu to Structure > View.

d) How do I synchronize configuration versions in Drupal ?

1. First, navigate to Configuration to select Development, then click Configuration synchronization to select Export (admin/config/development/configuration/full/export) from the source site in the Manage administrative menu.

2. Then, click Export to generate an archive of the complete site configuration and save the file on your local computer.

3. After that, navigate to Configuration to select Development and click on Configuration synchronization to select Import (admin/config/development/configuration/full/import) in the target site in the Manage administrative menu.

4. Next, navigate to the downloaded configuration archive and click on Upload. Your archive will be uploaded to the target site, and you’ll be redirected to the configuration synchronize page (Admin/Configuration/Develop/Configuration).

5. Then, check for expected differences on the page, including added, removed, or changed configuration items. View changes by clicking on the “View Differences” button.

6. Finally, click Import All to import the configuration changes.

Table of Contents