308: Making a duplicate Drupal test site
When administering a Drupal site, its 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 make a duplicate 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.
- Log into your cPanel
- Create the subdomain that will be used for the Drupal testing site, for example you may want to name it something like testsite.yourdomain.com.
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.
- Create a database.
- Create a database user.
- 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.
- In PhpMyAdmin, export your current database
- 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.)
- Open the .sql file with Notepad++ or another editor.
- Find and replace all instances of the old subdomain with the new subdomain. For Example, if your existing Drupal is on drupal.yourwebsite.org
Replace all instances of the old domain with the new domain. For example: drupaltest.yourwebsite.org
- Import your Database into the new database you created.
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.
- Go to your File Manager.
- 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.
- 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.
- 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.
- 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: /home/userna5/public_html/testdrupal/sites/default/settings.php
- Update the database name, username and the password for the database to the new database credentials so you can test them.
- Click on the Save Changes button.
Select the file and click the code editor.
We value your feedback!
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
new! - Enter your name and email address above and we will post your feedback in the comments on this page!
2014-03-17 9:12 am
Hi, JamesThanks 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?
ThanksBy Chiheng from Taiwan
2014-03-17 9:19 am
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.
2014-05-23 10:16 am
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.
2014-05-23 10:59 am
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."
2014-05-23 11:25 am
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.
2014-05-23 12:43 pm
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 www.testsite.myprimarydomain.com (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 www.myprimarydomain.com/reincarnation
However on the testsite - typing www.testsite.myprimarydomain.com/reincarnation does not work. Howwever - I noticed that typing www.myprimarydomain.com/testsite/reincarnation 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).
2014-05-23 2:58 pm
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 subdomain.domain.com 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 testsite.domain.com and domain.com/testsite successfully. I also tested testsite.domain.com/reincarnation and domain.com/testsite/reincarnation 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.
2014-07-18 1:28 pm
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/view.inc).
all site works fine, only Views give me errors that appear in views pages and views block.
how to resolve this?
2014-07-18 2:25 pm
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.