Knowledgebase
Knowledgebase
Create a staging site on cPanel for Magento
Posted by Will Kruss on 20 February 2021 05:09 PM

Create Staging Sub Domain

The first thing we want to do is setup a sub domain for our staging store:

  1. Login to cPanel for your domain, and click on the Sub Domains icon.
  2. For both the Sub Domain and Document Root, we'll enter the word: staging
  3. Click on the Create button.

Create Staging Database

While we're still in cPanel, let's setup a blank database for our staging store:

  1. Go back to the main screen for cPanel, and click on the MySQL Database Wizard icon.
  2. For the New Database, we'll enter staging.
  3. Click on the Next Step button.
  4. For the Username, we'll enter staging, and for the Password, enter whatever you'd like here.
  5. Click on the Next Step button.
  6. Click on the box next to ALL PRIVILEGES.
  7. Click on the Next Step button.

Copy Production Store

Now that our sub domain and database has been setup, we need to copy our production store over to the sub domain directory.

  1. Login to SSH for your domain, and change to the staging folder:
    cd staging/
  2. Copy all of the data from the directory where Magento is installed, which is usually in the public_html directory, to the staging directory:
    cp -R ../public_html/* ../public_html/.htaccess .

For the next step, you'll need to know the database information for the production store. If you don't remember this, open up the following file:

app/etc/local.xml

Lines 43-46 will contain your hostname, username, password, and database name.

Next, we need to copy the data from the production database over to our staging database. We'll be doing this from SSH as well.

mysqldump -u PRODUCTION_DBUSER -p PRODUCTION_DBNAME > data.sql

You'll be prompted to enter the password for the user that has privileges to the production database, so type that in and hit the Enter key.

This can take a couple seconds to a couple minutes depending on the size of your database, so just wait until it finishes.

Once it finishes, we need to import this data to our staging database:

mysql -u STAGING_DBUSER -p STAGING_DBNAME < data.sql

Just like before, you'll be prompted to enter a password, but this time it will be for the user who has privileges for the staging database.

Update Configuration

Using your favorite text editor, open up the following file from the staging directory:

app/etc/local.xml

Replace the values for lines 44-46 with the database details for our staging database.

Now we need to do is update the Unsecure and Secure URL for our staging store:

  1. Login to cPanel for your domain, and click on the phpMyAdmin icon.
  2. From the sidebar on the left, click on the _staging link.
  3. Click on the SQL tab, and in the text area, run the following command:
    SELECT * FROM `core_config_data` WHERE `path` LIKE '%base_url%';
  4. Click the Check All link and then click on the pencil icon.
  5. Update the value fields with the URL for your staging site.
  6. Click on the Go button at the very bottom to save your changes.

After You Upgrade

Check you can reach the store at the new subdomain e.g. staging.yourdomain.com

(0 vote(s))
Helpful
Not helpful