How to Clone a Drupal Site to Another Domain
What is Drupal?
Drupal is an open source content management software that many websites and applications use every day. A few of the great features of Drupal include authoring content, performance, and security.
It may become necessary to make changes to your live production site. Whether it is to update modules or your drupal version, it is a good idea to clone your drupal site to a development site and make the changes on the development site instead. This article will show you how to move or clone a Drupal site to another domain.
Requirements
Database Dump and Import
Users need the ability to create a mysql database dump using PhpMyAdmin, Mysqldump, or Drush. The method chosen determines how the database backup gets imported to the new database.
Copying Files
Users need to copy the files from the live Drupal project to a new Drupal project. This tutorial uses the rsync command. If you are not familiar with the rsync command utility, this article provides tips and basic knowledge of using rsync.
SSH
Users need the ability to connect to their server using SSH.
How to Clone a Drupal site to Another Domain
This tutorial involves cloning https://growblop.com to https://staging.growblop.com. Use your domains where appropriate.
Step 1: Dump the Database
There are three different methods for making a database backup dump. The one chosen depends on your preference. Choose the one that works best for you.
Dump the Database with the Export Function in PhpMyAdmin
With PhpMyAdmin, you will click the database name. Next, you will see buttons on the top menu. Click the Export button. For the Export method, choose Quick. Then click the Go button and select Save to save the backup to your local computer.
Dump the Database with the mysqldump Command
For this method, you need to connect to the server using SSH. First, change directories to the live Drupal project’s location from the Linux terminal with the cd command. In this tutorial, the Drupal project location is /home/growblop/public_html.
Once you have changed to the Drupal project location, issue the mysqldump command to make a database dump. The location of the dump file will be /home/growblop/public_html/drup177_cloning.sql.
cd /home/growblop/public_html
mysqldump drup177 > /home/growblop/public_html/drup177_cloning.sql
Dump the Database Using drush
The third method is a powerful utility called drush. Save the dump file to a location outside of the Drupal project location. This example makes a database dump using drush and stores it in /home/growblop/drup177.drushcloning.sql.
cd /home/growblop/public_html/
drush sql:dump --result-file=../drup177.drushcloning.sql
Step 2: Copy Over the Files
Sync the Drupal project’s files to the new Drupal domain. The preferred method is to use the rsync command. Using the example domains, it copies the files from /home/growblop/public_html to /home/growblop/staging.growblop.com.
cd /home/
rsync -avH /home/growblop/public_html/ /home/growblop/staging.growblop.com/
Step 3: Create the New Database
You need to create a new database for the cloned Drupal site. If you use cPanel, click MySQL Databases from the Databases section of the home page. Then, create the new database, database username, and password.
Once created, ensure the new database user has full privileges granted. Choose the database user and name under the Add User To Database section and click the Add button. Click the All privileges checkbox.
Step 4: Set the New Database and Domain Details in the settings.php File
Now that the new database, user, and password are set, replace the live Drupal database settings with the cloned site’s new database settings. Next, open the cloned site’s settings.php file with your text editor and replace the old database connection details with the new ones.
cd /home/growblop/staging.growblop.com
nano sites/default/settings.php
Change the following database details in that file to the new database, user, and password. Here is an example of that process.
$databases['default']['default'] = array (
'database' => 'drup177',
'username' => 'drup177',
'password' => '$password',
'prefix' => 'dr40_',
'host' => 'localhost',
'port' => '3306',
You may have your live site’s domain name set inside the settings.php file. Change this setting to the new clone site’s domain name. In the settings.php file’s $settings['trusted_host_patterns'] section, change the existing URL to the new URL.
Step 5. Import the Dump to the New Database
Now that the database is backed up to a dump file and synced to the cloned site’s file location, import the database dump. Importing the database uses the same method as making the dump. Use one of the following methods depending on how you created the database dump.
Import the Database Dump with PhpMyAdmin
You can import the database dump through PhpMyAdmin. First, click the new database name. You then click the Import button that appears on the top menu. Next, select the database dump file you exported to your local computer and click the Go button.
Import the Database Dump with the Mysql Command Line
Import the database dump made from the mysqldump command using the following command.
mysql drup338 < /home/growblop/public_html/drup177_cloning.sql
Import the Database Dump Using drush
If you used drush to make the database backup, import it with the following command.
cd /home/growblop/staging.growblop.com/
drush sql:query --file=/home/growblop/drup177.drushcloning.sql
Conclusion
You have now cloned your live production Drupal site to another staging domain. You can visit the newly cloned Drupal site on your browser by following this tutorial. In addition, some great Drupal tips will significantly benefit your Drupal site.
Liquid Web offers dedicated server options perfect for your next Drupal website. Contact our sales team to discuss your needs and get started.
Related Articles:
- How to Edit the PHP Memory for Your WordPress Site via WP Toolkit
- 4 Methods for How to Install Yarn on Windows Server
- How to Install Bpytop Resource Monitoring Tool on AlmaLinux
- How to Fix “This Site Can’t Provide a Secure Connection” Error
- How to Install MongoDB on AlmaLinux
- How to Install PostgreSQL on AlmaLinux

About the Author: Robert Lane
Robert is a husband, father of four amazing kids, and has two grandsons. He's been working at Liquid Web since January 2010, and he currently works as a Data Migrations Specialist.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Edit the PHP Memory for Your WordPress Site via WP Toolkit
Read ArticleWhat is CGI-Bin and What Does it Do?
Read ArticleTop 10 Password Security Standards
Read ArticleTop 10 Password Security Standards
Read ArticleHow to Use the WP Toolkit to Secure and Update WordPress
Read Article