How to move a WordPress Development Site to Live within cPanel


Before you begin:

  • Ensure you have full backups of both your live and development sites.
  • Verify cPanel and SSH access to your hosting account.
  • Confirm WP-CLI is installed, and you have a basic understanding of SSH/command line.

This interactive guide breaks down the WordPress migration process from development to live.

Step 1: Backup Your Current Live Site

It's crucial to have a complete backup of your existing live site before making any changes. This involves connecting via SSH, navigating to your live site's root directory, and then backing up both the database and files.

  1. Connect via SSH:

    Open your terminal or SSH client and connect to your hosting account. Replace `username` and `yourdomain.com` with your actual cPanel username and domain.

    ssh [email protected]

    Alternatively, you can use the Terminal feature within your cPanel account.

  2. Navigate to `public_html`:

    cd public_html
  3. Back up the Live Database:

    Export your current live site's database to a SQL file. This will create `public_html_backup.sql` in your `public_html` directory.

    wp db export public_html_backup.sql
  4. Backup the Live Site Files:

    Compress all files in your `public_html` directory. The `.` means "current directory".

    zip -r public_html_files_backup.zip .

Step 2: Backup Your Development Site

Next, create a similar complete backup of your development site. This ensures you have a safe copy of the site you intend to make live.

  1. Navigate to the Development Site Directory:

    Assuming your dev site is in `dev.example.com` (outside `public_html`). Adjust path if needed. The `../` means "previous directory".

    cd ../dev.example.com
  2. Backup the Development Database:

    This creates `dev_site_backup.sql` in your development site's directory.

    wp db export dev_site_backup.sql
  3. Backup the Development Site Files:

    zip -r dev_site_files_backup.zip .

Step 3: Prepare the Live Site Directory

With all backups secured, you can now clear out the old live site files from `public_html` to make way for the new development site files.

 

CAUTION:

Double-check that `public_html_backup.sql` and `public_html_files_backup.zip` are present in `public_html` before proceeding. The following commands will permanently delete files.

  1. Navigate back to `public_html`:

    cd public_html
  2. Delete Existing Files (Option 1 - Safer):

    This command deletes all files/folders in `public_html` EXCEPT hidden files and your specified backup files.

    find . -maxdepth 1 -mindepth 1 ! -name "public_html_backup.sql" ! -name "public_html_files_backup.zip" -exec rm -rf {} +

    Delete Existing Files (Option 2 - Delete All, then move backups):

    If using this method, manually move your backup files to safety *before* running, or immediately after if they are outside `public_html`.

    Whilst in 'public_html', run the following commands (alternatively, use the File Manager in cPanel):

    rm -rf * rm -rf .[!.]*

    After using Option 2, move your backup files (`public_html_backup.sql`, `public_html_files_backup.zip`) to a safe location outside `public_html` (e.g., using cPanel File Manager or `mv ../backup_files_dir/`).

Step 4: Move Development Site Files to Live

Now, you'll transfer your backed-up development site files into the now-empty `public_html` directory.

  1. Copy the Development Site Archive:

    From `public_html`, copy `dev_site_files_backup.zip` from your development site's folder. Adjust path if needed.

    cp ../dev.example.com/dev_site_files_backup.zip .
  2. Unzip the Development Site Files:

    Extract the archive into `public_html`.

    unzip dev_site_files_backup.zip
  3. Clean Up Archive:

    Delete the zip file to save space.

    rm dev_site_files_backup.zip

Step 5: Import Development Database

This step involves replacing the live site's database content with the content from your development site's database backup.

 

WARNING:

The `wp db drop` command will delete all data from your current live database. Ensure you have the `public_html_backup.sql` file from Step 1.

  1. Identify Live Database Name:

    Check your `wp-config.php` file in `public_html` for the `DB_NAME` constant. You'll need this to confirm you're working with the correct database if managing via phpMyAdmin, though WP-CLI uses the config.

  2. Drop Existing Live Database Tables:

    wp db drop --yes
  3. Import the Development Database:

    Copy `dev_site_backup.sql` to `public_html` and import it.

    cp ../dev.example.com/dev_site_backup.sql . wp db import dev_site_backup.sql

    Then delete the copied SQL file:

    rm dev_site_backup.sql

Step 6: Update URLs in the Database

This critical step updates all occurrences of your development URL to your live URL within the WordPress database, ensuring all internal links and resource paths are correct.

  1. Perform Search and Replace:

    While in `public_html`, use WP-CLI. Replace `https://dev.example.com` and `https://www.example.com` with your actual URLs.

    wp search-replace 'https://dev.example.com' 'https://www.example.com' --precise --skip-columns=guid --allow-root
    • `--precise`: Ensures only exact matches are replaced.
    • `--skip-columns=guid`: Prevents issues with RSS feeds.
    • `--allow-root`: May be needed depending on permissions.

Step 7: Update `wp-config.php`

Explicitly define the `WP_HOME` and `WP_SITEURL` in your `wp-config.php` file to ensure WordPress correctly identifies its new live location.

  1. Open `wp-config.php` for editing:

    Use `nano` via SSH or cPanel's File Manager.

    nano wp-config.php
  2. Add/Modify URL Definitions:

    Find `/* That's all, stop editing! Happy publishing. */` and add these lines above it. Update if they already exist.

    define('WP_HOME', 'https://www.example.com'); define('WP_SITEURL', 'https://www.example.com');
  3. Save and Exit:

    If using `nano`, press `Ctrl+X`, then `Y`, then `Enter`.

Step 8: Clear Caches

After migration, clearing all layers of caching is vital to ensure the new site content and configuration are displayed correctly and promptly.

  1. WordPress Caches:

    If you use caching plugins (e.g., WP Super Cache, LiteSpeed Cache), clear their cache via the WordPress admin dashboard. Or, try with WP-CLI:

    wp cache flush
  2. Server Caches:

    If your host uses server-level caching (like Varnish), clear it via cPanel or contact support.

  3. Browser Cache:

    Clear your browser's cache and cookies, or use an incognito/private window for initial testing.

Step 9: Final Checks

Thoroughly test your live site after the migration to catch any potential issues. This is the final verification that everything is working as expected.

  • Browse all key pages and ensure links work correctly.
  • Check that images, videos, and other media are loading properly.
  • Test all forms (contact forms, login forms, etc.).
  • Go to `Settings > Permalinks` in WordPress admin and click "Save Changes" to regenerate permalinks.
  • Verify all essential plugins are active and functioning correctly.
  • Test user login and logout for different user roles if applicable.

If you encounter any issues, refer to your backups or contact EncodeDotHost support for assistance.


Was this answer helpful?

One email a month. Endless business benefits.

Don't miss out on WMTWWFY — the newsletter that keeps your website fast, safe, and visible.

« Back
Spinner
aluminium-anthropoid Security Check