Editing a website’s code is often needed to update a site, but doing this to the live website could create downtime and other unwanted effects. Instead, its ideal to create an environment especially for developing new ideas. In this tutorial, we will explore creating a development site specifically for CentOS servers.
As a warning, this is advanced technical work. It’s possible to make mistakes and cause downtime on your live domain. If you are not 100% confident, it may be a good idea to hire a system admin or developer to copy the domain for you.
- Be sure you are logged in as root user.
- I’ll be working from a Liquid Web Core Managed VPS server running CentOS.
Step 1: Continue on to back up the cPanel account, just in case you have any issues while creating your development environment:
/scripts/pkgacct [username] --backup /home/temp/
Step 2: After creating a backup, you will create a copy the database of the main domain, otherwise known as the primary domain.
mysqldump [database_name] > /home/temp/backup.[database_name].sql
Step 3: Create the new dev domain in WHM. This domain name will be a subdomain of the primary domain. Creating a subdomain is one of the first steps in designing your development environment. We prefer to use, dev.[domain].com, the same domain name but with “dev” in front of it for clarity. Do be sure to note all the information, like the username and password. If you are not familiar with how to create a new account, see the following tutorial.
Step 4: Once you’ve created the subdomain within your cPanel you’ll copy the files from the main document root to the newly created dev document root. The document root is the location where your website’s files.
Use the following command to find the document root for either domain. Replace “exampledomain.com” with the primary and development domains for determining the location of document root for each.
whmapi1 domainuserdata domain=[exampledomain.com] | grep -i documentroot
Step 5: After locating the document roots we will copy the files from the primary domain over to the development environment. Insert the document roots into this next command.
rsync -avh /document/root/of/the/primary/domain/ /document/root/of/the/new/dev/domain
Step 6: Next you will need to state the correct ownership of the dev domain’s files and directories, as the previous username will be in place. The ‘dev_username’ will be the given/chosen when you created the new account. The following command will change the ownership for you.
chown -R [dev_username]: /home/[dev_username]
Step 7: After changing file ownership, create a new database and database user for the dev domain. Be sure to notate this information including the password set. Our documentation on the creating a new database will walk you through this necessary process.
Step 8: Once you’ve created the new database its user, you can start copying the original database into the newly created database.
mysql [new_database_name] < /home/temp/backup.[database_name].sql
Step 9: Copying over the database is the bulk of the work, but you’ll still need to edit the configuration files for your domain. Typically, some files need to access the database and will accomplish this via the database user and password. The file that contains these credentials needs to be updated to have the database, database user, and password you created in step 8 of this tutorial. If unsure of the location of these files talking with a developer may be helpful. If you are working with a WordPress site, you can continue onto the next section. Otherwise, if you have updated your dev configuration files with your new database info continue onto step 10.
Step 10: To complete this tutorial you have two choices: add an A record to your DNS view your dev site online or edit your local hosts file to view solely on your computer. For our Liquid Web customers feel free to contact The Most Helpful Humans™ with questions you may have in setting up a development environment.