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.
Database Dump and Import
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.
Users need the ability to connect to their server using SSH.
How to Clone a Drupal site to Another Domain
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
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.
- How To Flush Your Local DNS Cache
- Install Multiple PHP Versions Using EasyApache 4
- How to Manage Windows Server Update Settings via Group Policy Editor
- Remove a MySQL User on Linux via Command Line
- How to Upgrade Apache and PHP With cPanel’s EasyApache
- Best Practices For Changing Your Email Marketing Provider
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Onboard to Liquid Web: A Step-By-Step Guide to Migrating Your Data to a Virtual ServerRead Article