How to Make a Duplicate Drupal Site

When administering a Drupal site, it’s a good idea to make a duplicate site for testing purposes. This allows the administrator to make large changes to the web site while the existing site is still running. This article will teach how to make a duplicate Drupal site for testing.

Steps to Duplicate a Drupal Site on a Subdomain

First Step is to Create the Subdomain

To set up a Drupal test site, create a subdomain that you will use to separate your Drupal site. The following are the steps on how to set up the subdomain. If you don’t have hosting for your website already, check out our Drupal Hosting options for an optimized platform for your website.

  1. Log into your cPanel.
  2. Create the subdomain that will be used for the Drupal testing site, for example you may want to name it something like

Second, Set Up the Database

Because Drupal stores all the content in a database, the database will need to be imported into a separate database. The following section will explain how to export your Drupal database, change the site url in the database, and import the database into your testing database.

  1. Create a database.

    Create Drupal database
  2. Create a database user.

    Create Drupal database user
  3. Add the user to the database will full permissions.

    Important! Make sure you save the Database name, Username, and password in a notepad or text document. These will need to be used later in the setup.

    Assign permissions to Drupal database user
  4. In phpMyAdmin, export your current database.

    Export the old Drupal Database
  5. Make a duplicate of your Database on your local computer. (This is to prevent you from having to export the database again due to any possible mistake.)
  6. Open the .sql file with Notepad++ or another editor.

    Find and replace old domain with new
  7. Find and replace all instances of the old subdomain with the new subdomain. For Example, if your existing Drupal is on

    All occurrences replaced
  8. Replace all instances of the old domain with the new domain. For example:
  9. Import your Database into the new database you created.

    Import the Drupal database to the new database

Finally, Move the Drupal Files

Now that the database is set up, the files will need to be moved and the settings.php file will need to be edited to use the new database connection. The following section will explain how to move and set the settings.php file to work on the new subdomain.

  1. Go to your cPanel File Manager.
  2. Copy your Drupal Files from your current directory to the document root directory created for your subdomain. The root directory usually is the same name as the subdomain that was created.
  3. Select all the Drupal files.

    Important! When selecting all your Drupal Files, make sure any other files and/or folders not related to Drupal are not selected. After selecting all, hold the Ctrl key and click the folders to deselect any “non-Drupal” files and /or folders. If you do not deselect unrelated files and/or folders, there will be duplicates taking up disk space.

  4. Click Copy at the top right side of the File Manager. Type the path to the folder you want to move your files to (This will be the subdomain document root location). Click Copy.
  5. Now we will need to update the database settings for Drupal. Navigate to the path to the Document Root folder for the Sub Domain. For example:
  6. Select the file and click the code editor.
  7. Update the database name, username and the password for the database to the new database credentials so you can test them.

    Update the Drupal settings.php file
  8. Click on the Save Changes button.

For more step-by-step guides and practical tips, visit our Drupal Education Channel.

46 thoughts on “How to Make a Duplicate Drupal Site

  1. I could not find any instances of the old subdomain address at all in the sql, si imported it into the new database as is. 

    Is there another way a database is recognised as belonging to a particular subdomain, and/or is there a way to change this infor directly in either MySQL or phpMyAdmin.
    I don’t want to transfer files over to the new folder until I know what I should do here.

    Thank you for all the help. I wouldn’t have known where to start otherwise.

    I think automation would be excellent but I suppose web developers want to keep their jobs. 🙂

  2. Hi, i need help 🙂

    After clone drupal, work only home pahe, for others show warnning message

    “Error 404 Not Found.The requested URL /admin/people was not found on this server.”

    Here cloned site, please HELP ME!


    1. Hello,

      A 404 error means the file or folder you are looking for does not exist, I would recommend ensuring you have copied all the files over. Generally with content management systems like Drupal content is generated dynamically and will show a 404 if you are missing the .htaccess file. I would make sure you copied that over as well.

      Best Regards,

  3. Thank you for your response!

    In case anyone has a similar problem, I would recommend checking to see if the database username and password were entered correctly with no extra spaces in the settings.php file.  In my case, I was one character off on my database username.  Once I fixed that, the problem was solved.

  4. Hi,

    I followed the steps but have the following error message when I try to view the duplicate site:



    The website encountered an unexpected error. Please try again later.

    Error message

    PDOException: SQLSTATE[HY000] [1045] Access denied for user ‘***’@’localhost’ (using password: YES) in lock_may_be_available() (line 167 of /home/***/***.com/includes/



    Any idea how I might be able to resolve this or what I might have done wrong?

    Thanks so much for any help you might be able to provide!


    Best regards,



    1. JJ, it appears that your MySQL user does not have permissions to do the required action to proceed. I would check your MySQL user permissions for the database you are using. If you’re unsure of the permissions to set, you will need to speak to a web or MySQL developer for specific assistance.

  5. Hello!

    I’m a bit stuck at Step 5 of the last section about moving the Drupal files.

    It appears that I’ve copied over all my files, but when I click on sites>default for the new testing subdomain in File Manager (to get to …/sites/default/settings.php), it says “This directory is empty.”

    Not sure why not all the files copied over.  Is this a permissions issue or something else?

    Any assistance would be greatly appreciated!

    1. JJ, I recommend checking the full path that you are moving from, and the full path that you are trying to move to. You can paste the full path into your file manager in the field toward the top-left hand side and click ‘Go’ to make sure you’re in the correct directory. Also, the search function to the top-right hand side may help, too.

  6. I just wanted to add that I followed all the instructions, and got to the point where teh site was up and running in its new location, but only the main page would show.  All menu options would give me page no found.  Couldn’t log into it either.

    I moved the lhtaccess file over after setting filemanger to see hidden files, and it worked like a charm!  you saved me a nite’s troubleshooting efforts.  Thank you so VERY VERY much….

  7. I have created a duplicate of my Drupal website using the above instructions. The site seems to have been created properly, but I am unable to log in. When I attempt to log in, the site does not recognize that I have logged in. It does not create an error, but I am not logged in either.

    The only difference is that I was moving the site from my primary domain to a subdomain.


    1. Hello Davesi,

      If you’re creating a duplicate and you followed all of the directions, then the user name and configuration should be the same from the previous site. I tried finding a Drupal support article on this problem and the closest thing that I have is this post. The precise error message might the key to finding out why it’s not working per the post. I also found this post about clearing a cookie to solve the issue.

      If you have any further questions or comments, please let us know.

      Arnel C.

  8. I got evverything up and running, bbut when I navigate to the site, I get this error:

    Drupal 8.1.0


    The website encountered an unexpected error. Please try again later.
    Drupal\Core\Database\ConnectionNotDefinedException: The specified database connection is not defined: default in Drupal\Core\Database\Database::openConnection() (line 361 of core\lib\Drupal\Core\Database\Database.php).

    Drupal\Core\Database\Database::openConnection('default', 'default') (Line: 166)
    Drupal\Core\Database\Database::getConnection() (Line: 40)
    Drupal\Core\Config\BootstrapConfigStorageFactory::getDatabaseStorage() (Line: 31)
    Drupal\Core\Config\BootstrapConfigStorageFactory::get() (Line: 492)
    install_begin_request(Object, Array) (Line: 113)
    install_drupal(Object) (Line: 39)

    I am 100% sure that the databbse connetion is correct, i can access it using the specified credentials via terminal.
    Is there somethin I missed?

    Thank you.
    1. Hello AVN,

      Sorry for the problems with the Drupal install. The error is indicating an issue with the specific database. You need to make sure the duplicate installation has its own database and that it is properly referenced in your configuration files. Please review those settings.

      If you have any further questions or comments, please let us know.

      Arnel C.

  9. Tried following these directions and they JUST DON”T WORK.  1) Can’t copy /sites/default folder into my subdomain folder (permission error, but I have read access), 2) Can’t copy .htaccess file into my subdomain folder.  This is WAY more difficult than it should be.  IMHO there REALLY should be some automation to duplicating a site for development purpoases.

    Larry Bates


    1. Hello Larry,

      These instructions were written as the process was followed so it should work for you. Are you getting any errors when trying to copy files over? Which specific Drupal version are you using?

      Kindest Regards,
      Scott M

  10. Thank you so much for this it really helped me out. Have a long a prosperus life good sir! 😀

    kindest regards,


  11. Hello TJ Edens,

    Thanks so much for your help!

    Changing the permissions to 777 for both the settings.php file as well as the folder where it was located seems to have done the trick.  (I have changed both back.)

    I really appreciate your help!!!  Hope you have a great weekend.



  12. Hello John-Paul,

    Thanks for the quick response.

    I used the guide to change the permission of the settings.php file to 644.  However, I am still getting the same “Permission” error.

    Is there something else I need to do?  Thanks again for all of your help!!!

    Kind regards,


    1. Hello JJ,

      Change the permissions to 777 then after the installation is done change it back to 644. I had to do the same thing when installing Drupal the other day.

      Best Regards,
      TJ Edens

  13. Hi,

    I was able to complete each step until the very last step – Step 7 under moving the Drupal Files.  When I went to save my changes, I received an error message that said:

    Could not write “***/sites/default/settings.php”: Permission denied

    Please advise how I should proceed.  I appreciate this great tutorial and all of your help!

    1. Hello JJ,

      Thank you for contacting us. Since you are getting a “Permission” error, I recommend checking the permissions for the “settings.php” file.

      Here is a helpful link to our guide on Changing File Permissions in cPanel. Typically, .php files use 644 permissions. This allows you to read and access the settings.php file.

      Thank you,

  14. Hello !


    Thank you for this article.

    After following it, I can see my home page and access my different articles, but I don’t have any css applied, it seems like it doesn’t find the theme…

    Also, I can’t log in, using /?q=user/login I get a blank page…


    Any suggestion ? 



  15. Scott, I followed the instructions (great quality!) and seemed to have created a copy of my site: when I go to the subdomain link it pulls up the exact home page as the original – awesome!

    However, none of the links seem to work (menu, subsections, etc) – on attempt, it gives me the following message:

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.”

    Any quick places I can look to correct this? 

    Already made sure the permission were re-set.



  16. another question. So, I copied over the drupal files, but the settings.php file would not upload. I was told I didn’t have access. So, instead, I just downloaded drupal and uploaded it to and created the settings.php file as if it were a new install. Of course, now, when I go to, it wants me to install drupal. Now, I’d be happy to install drupal to the test site, provided it won’t damage the production site. However, I am concerned because the test sites directory is located in public_html/testsite and the production site is located in public/html. I just want to be sure that there won’t be any problems with the production site if I run the install in the test site directory.

    1. Hello Scott,

      It is fine to install Drupal into a subfolder. Just remember to use that subfolder in the URL and not simply the domain name when installing.

      Of course it is always advisable to make a copy of your public_html folder prior to making any changes just in case.

      Kindest Regards,
      Scott M

    2. As far as I can see, it´s a great article. You treat your readers like they are intelligent creatures, I like that a lot. Bookmarked 🙂

  17. I don’t know what changes to make in the .sql document. you say to replace all istances of the old subdomain with the new one. But I don’t know what the old subdomain is. I have no idea where my drupal files are installed to. I know the site is in the public_html directory, but im lost beyond this point.

    1. Hello Scott,

      Thank you for your question. In the .sql document, you need to find all instances of the old domain name, for example:

      Then replace that with the new subdomain you created in Step 2 of the first section. For example:

      If your site is installed in the public_html directory, then your Drupal files will also be in that folder. For detailed information on the folder structure, see our full guide titled “What directory should I put my files in?

      If you have any further questions, feel free to post them below.

      Thank you,

  18. Hi Scott, you are absolutely right.

    But why i did it is because.. 

    after completing all the steps mentioned in your guide, when i visited the subdomain it was loading with blank page and no activity at all (i mean there was no process wheel spinning in google chrome tab etc)

    i tried multiple times and apart from subdomain i also tried same process on my localhost using MAMP server (i am on Mac)

    i also tried firing but nothing happened so as a last try i tried and something happened (that is the installation). 


    Oh this also reminds me of one strange thing -which now when i think- it kind of makes sense. 

    While finishing step8 (importing database successfully) i did saw the message of tables imported successfully – However when i clicked on that database it still showed empty database (no tables found). I restarted browser, removed cache etc but it was still showing empty database. 

    Please help me or guide me in a right direction. 


    1. Hello Dhaval,

      The white screen can often be due to php errors. You will want to check error logs and set up Drupal to report any errors. Below are a couple of pages from the Drupal site to help you with that:
      Blank pages
      Show errors while developing

      The database should have imported correctly, however, if you do not see the database size change and have refreshed your browser, be sure to contact your hosting support as to why.

      Kindest Regards,
      Scott M

  19. Hi Team,

    thank you so much for this tutorial. Everything went great. I followed all instructions step by step.

    However, i am facing weird issue. 

    lets say my site is and it is running on drupal 6.22

    i created a test domain called –
    i export import database, created user in mysql, copied all drupal files including my site files and edited settings.php

    i editted .htacess file as per the comments from your team. 

    n then when i test my subdomain – it installed drupal but it gave me a clean drupal platform. 

    What i was expecting was a clone version of my site but instead i have a blank version of drupal. 

    What to do ? Please guide me. 


    1. Hello Dhaval,

      I am a little confused by your question. After the file copy and changing the configuration files to point to the new database you should have seen the proper site. Did you say you installed Drupal in the subdomain after you copied the files over?

      Kindest Regards,
      Scott M

  20. Hi friend, good and easy tutorial, i did everything what you said, but when i finished the process the site has a problem with views, it shows this

    Notice: unserialize(): Error at offset 4195 of 5857 bytes en views_db_object->load_row() (línea 2251 de /home/domain/public_html/test_site_folder/modules/views/includes/

    all site works fine, only Views give me errors that appear in views pages and views block.

    how to resolve this?


    1. Hello Rolando,

      Thank you for your question. I saw a similar problem posted in the Official Drupal forums, where they offer possible solutions.

      Since this error seems related the 3rd party Drupal module Views, I recommend confirming it is setup correctly, and compatible with the version of Drupal you are running.

      If you have any further questions, feel free to post them below.
      Thank you,


  21. Hi Scott.

    Thank you very much – it seems to be all working now. A couple of additional questions:

    1) Strangely I could not (and still can’t) see the htaccess files even though I had enabled “see hidden files” when I open file manager.

    2)Also – I am confused by the hierarcy of the urls. The url to the front page of the testsite is (you’ll note that since this is a public comment I’ve written “myprimarydomain” instead of my actual domain).

    So I expected that in the testsite to see additional content other than my home page, I would have to input the url in the same method as my live website, but that does not work.

    For instance, on my live website, to see the page called “reincarnation” – I type


    However on the testsite  – typing does not work. Howwever – I noticed that typing does work!


    That surprised me. Is this normal? (I don’t want to have problems when I end up finishing my work on the test site and replacing my original site).


    Thank you


    1. Hello Bruce,

      I’m happy to assist with your additional questions.

      1) the .htaccess file should be the first file after the folders if your file list is being viewed alphabetically. The . will register before letters so it will show before files that begin with a. I do see it there in the testsite subfolder, however.

      2) With my original fix, (I didn’t take into account using a format) the changes I made caused the errors you now see when using the subdomain format. I have since altered it to display both ways, oddly enough by simply reversing the original changes.

      I have tested and successfully. I also tested and successfully. Both formats also grant access to the login page without error. I assume the other pages should also work.

      I wish I could tell you what the difference was between when you first contacted us and now, but there is no difference in the .htaccess file and settings.php file between then and now. Why it is working now is a complete mystery to me.

      Please let us know if you have any further questions, I’m happy to assist.

      Kindest Regards,

  22. Hi John Paul,

    After sending my previous email, I tried copying all the files to my new “testsite” folder (just in case I inadvertently missed a drupal related one).

    Now the testsite is partly working  – and it replicates the front page of the original site perfectly – but it only shows the front page only. When I try to login or go to nested pages, I get:

    “Error 500 – Internal Server Error –  An error was encountered while processing your request. Typically this is a temporary condition. Please contact the web site owner for further assistance.”


    1. Hello Bruce,

      You still needed to copy the .htaccess file from the main to the subdirectory as well. Once copied, the RewriteBase needed to be changed to accommodate the new subfolder. I made that change for you and the login area is now appearing.

      Also, since the site is not using the base domain name, we needed to change the $base_url variable to reflect your domain and then the subfolder in the sites/default/settings.php file.

      Please let us know if you have any further issues.

      Kindest Regards,
      Scott M

  23. Hi John Paul,

    Thank you for the instructions. I am having trouble getting mine to work. I am getting a message “error 403 – You don’t have permission to access the requested resource. Please contact the web site owner for further assistance.”

    I am pretty sure that it’s not a propogation issue, because I created another subdomain just now, in which I placed a simple index.php, and it works fine.

    I followed your instructions very carefully and the only place where i think error might have cropped up is:


    Settting up database:Step 4: my phpMyAdmin  is a different version than  the one in the picture of the instruction link, and I had some trouble navigating it, and am not sure if I did it correctly:

    Moving files: Step 3: I have a lot of files in the “to be copied from”  directory and not all are drupal related. So I am not sure if I have copied all the drupal files or if I am missing some – should I just copy all?

    Any help you can provide would be greatly appreciated.


  24. Hi, James
    Thanks for your article, however, in the step 4 of the final part, I couldn’t copy files to my testsite’s default folder, then I tried to use the upload function, and it still doesn’t work.

    Can you help me solving this problem? 

    By Chiheng from Taiwan 


    1. Hello Chiheng,

      Thank you for your question. We are happy to help, but need a little more information.

      Are you selecting the files (step 3) before clicking the Copy button?

      Do you see any errors? What are the errors?

      What type and version of Browser are you using?

      Have you tried another browser?

      If you have any further questions, feel free to post them below.
      Thank you,


Was this article helpful? Join the conversation!