Last updated March 17, 2011. Created by madamep on November 9, 2005.
Edited by eliza411, bekasu, jhodgdon, AjK. Log in to edit this page.
Before you begin, decide where the new installation will be located. Usually you can just install Drupal to a subdirectory: http://www.example.com/test_site/.
Make sure you have already completed the steps for backing up your database.
Note:
In order to have clean urls in your test_site directory you have to edit the mod_rewrite settings in test_site/.htaccess, uncomment and modify:
RewriteBase /test_site
I. Copy your live site files to a test site directory
Copy the contents of your live site directory to a new directory called "test_site", or whatever name you would like to use:
cp -R /path/to/drupal/ path/to/new/drupal/site
Make sure the .htaccess file gets copied to the new directory as well.
II. Setup a blank test-site database with MySQL
a) Create a new, blank MySQL database (login to MySQL) and give permissions for a user to access it:
mysqladmin -u dba_user -p create test_site_database
(Where 'dba_user' is an example MySQL user which has the CREATE and GRANT privileges. Use the appropriate user name for your system.)
b) MySQL will prompt for the 'dba_user' database password and then create a blank test_site database. Next you must login and set the access database permissions:
mysql -u dba_user -p
c) Again, you will be asked for the 'dba_user' database password. At the MySQL prompt, enter following command:
GRANT ALL PRIVILEGES ON test_site_database.* TO nobody@localhost IDENTIFIED BY 'password';
where 'test_site_database' is the name of your database 'nobody@localhost' is the username of your webserver MySQL account 'password' is the password required to log in as the MySQL user.
d) To activate the new permissions you must enter the command:
flush privileges;
and then enter '\q' to exit MySQL.
III. Change settings.php (or includes/conf.php) in your test_site directory
a) Open and edit the file located under sites/default/settings.php (or includes/conf.php) with an editor. Follow the directions in the file and modify these three settings:
$db_url = 'mysql://user:pass@localhost/testsite_db';(test-site database login & password, URL location of the test-site database. "localhost" usually works by default.)
$db_prefix = '';(Sometimes your database tables will have a prefix. Ask your webhosting company for help if you think this is causing a problem. Otherwise leave it blank.)
$base_url = 'http://www.example.com/test_site';(This is where you want to move Drupal. You can install Drupal to a subdirectory such as http://www.example.com/test_site. This is what we want.)
IV. Import your database backup into the test_site database
Now that you have a new blank test_site database, you must take the backup.sql file you created in the backup step and import it into your new database. This will create a copy of the live site database on the new test site database. There are several methods for doing this.
IV method 1: Use the contributed database insertion script
Deprecated.
IV method 2: Use mysqldump directly
You can also copy the database directly from the old database to the new database, by issuing this command:
mysqldump --opt --user=<user> --password=<password> <original database> | mysql --user=<user> --password=<password> <new database>This way you do not need to make a dump, which greatly improves speed.
IV method 3: Using the mysql console
You can also use the MySQL console to import your database, by issuing the following commands. This assumes you already created the new MySQL database, following the instructions above.
mysql -u {user name you are using for the new database} -p
Enter password: {enter new database password}
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is xxxxx
Server version: 5.0.44Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use {new database name};
mysql> source /path/to/your/backup/file/such/as/backup.sql;
mysql>\qV. Check if your test site works
Navigate to http://www.example.com/test_site and you should see a working copy of your live site.
Don't forget to edit .htaccess and settings.php
In settings.php, use a text editor to change (or uncomment) the line
$db_url = 'mysql://user:pass@localhost/test_site_db';and fill in your correct username and password for the test_site database that you created above.
Also change the line
$base_url = 'http://www.example.com/test_site';In .htacccess, change RewriteBase /your_live_site/ to RewriteBase /test_site/
Then you should be ready to test your new test_site.