Partners        Payment Options        My Account       Cart

Blog, News & Events

How to Set Up a Staging Environment in cPanel on Sternhost: Test Changes Safely Before Going Live

Making changes directly on your live website can be risky. A staging environment—an exact copy of your site—allows you to test updates, new plugins, or design changes without affecting your production site. In this guide, you’ll learn how to create, manage, and deploy from a staging environment in cPanel on Sternhost.

Why You Need a Staging Environment

  • Risk-Free Testing: Try out new features, themes, or code without breaking your live site.
  • Quality Assurance: Catch bugs, broken links, or layout issues before your visitors do.
  • Faster Development: Collaborate with developers and content editors in an isolated workspace.

 

Step 1: Create a Subdomain for Staging

  1. Log in to cPanel: Visit sternhost.com/cpanel.
  2. Open “Subdomains”: Under the Domains section, click Subdomains.
  3. Add Staging Subdomain: Enter a name (e.g., staging), select your domain, and click Create.
  4. Verify Directory: cPanel will generate a folder (e.g., public_html/staging) where your staging site files will live.

Step 2: Clone Your Live Site Files

  1. Go to File Manager: Click File Manager under Files.
  2. Compress & Download:
    • Navigate to your live site’s root (public_html/).
    • Select all files, click CompressZip, then Download.
  3. Upload & Extract:
    • Switch to the public_html/staging folder.
    • Upload the ZIP file and use Extract to unpack your site files.

 

Step 3: Duplicate Your Database

  1. Export Live Database:
    • In cPanel, open phpMyAdmin under Databases.
    • Select your live database, click Export, and download the SQL file.
  2. Create New Database:
    • Back in cPanel, click MySQL® Databases.
    • Create a new database (e.g., staging_db), a new user, and assign All Privileges.
  3. Import to Staging DB:
    • In phpMyAdmin, select staging_db and click Import, then upload your SQL file.

Step 4: Update Configuration for Staging

  1. Edit Config File:
    • In File Manager, open wp-config.php (or your application’s config) within /staging.
  2. Change Database Credentials:
    define('DB_NAME', 'staging_db');
    define('DB_USER', 'staging_user');
    define('DB_PASSWORD', 'your_password');
    define('DB_HOST', 'localhost');
    
  3. Adjust URLs:
    • For WordPress, use phpMyAdmin’s SQL tab to run:
      UPDATE wp_options 
      SET option_value = 'https://staging.yourdomain.com' 
      WHERE option_name = 'siteurl' OR option_name = 'home';
      

Step 5: Restrict Access to Your Staging Site

  1. Password‑Protect Directory:
    • In cPanel, go to Directory Privacy (or Password Protect Directories).
    • Choose /public_html/staging, enable protection, set a user/password.
  2. Robots Exclusion:
    • Add to /public_html/staging/robots.txt:
      User-agent: *
      Disallow: /
      

Step 6: Test and Deploy

  1. Test Thoroughly:
    • Browse every page, test forms, log in as different users, and verify functionality.
  2. Push Changes Live:
    • Once approved, repeat Steps 2–4 in reverse to copy tested files and database to your production environment.
    • Or, use a plugin/CLI tool (e.g., WP‑CLI) for one‑click deployments.

Additional Resources

Conclusion

A dedicated staging environment is invaluable for safe, controlled development. By following these steps in Sternhost’s cPanel, you’ll protect your live site, improve code quality, and speed up your workflow. Ready to get started? Log in to your Sternhost cPanel and spin up your staging site today!

Leave a Reply

Your email address will not be published.