Best Practices for Migrating a PHP Site to CloudPanel

Nemesis

Active member
Joined
Mar 22, 2025
Messages
35
Points
61
Age
26
What are the recommended best practices for migrating my existing PHP website to CloudPanel with minimal downtime?
 
Solution
Below are the recommended best practices for migrating a PHP site (e.g., www.domain.com) to CloudPanel smoothly and safely:
🔸 Step 1: Create a PHP Site on CloudPanel
  • Use your live domain (e.g., www.domain.com) when creating your PHP site. This ensures correct Nginx redirection from non-www to www, or vice versa.
  • CloudPanel automatically adds a subdomain (www1.domain.com) as a pre-live domain for testing.

🔸 Step 2: Configure DNS for Testing

  • Create an A record for your testing subdomain:
    Code:
    www1.domain.com → your-server-IP

  • Enable Basic Authentication in CloudPanel to prevent search engines from indexing your test site.

🔸...​

Below are the recommended best practices for migrating a PHP site (e.g., www.domain.com) to CloudPanel smoothly and safely:
🔸 Step 1: Create a PHP Site on CloudPanel
  • Use your live domain (e.g., www.domain.com) when creating your PHP site. This ensures correct Nginx redirection from non-www to www, or vice versa.
  • CloudPanel automatically adds a subdomain (www1.domain.com) as a pre-live domain for testing.

🔸 Step 2: Configure DNS for Testing

  • Create an A record for your testing subdomain:
    Code:
    www1.domain.com → your-server-IP

  • Enable Basic Authentication in CloudPanel to prevent search engines from indexing your test site.

🔸 Step 3: Migrate Your Website Content

  • Files:
    Copy your website files from the old server to your CloudPanel site directory via FTP or SFTP.
  • Database:
    On the old server, export your database using:
    Code:
    mysqldump -h127.0.0.1 -u$userName -p --opt --single-transaction --quick $databaseName > dump.sql

  • Upload dump.sql to CloudPanel and import it:
    Code:
    clpctl db:import --databaseName=my-database --file=dump.sql

  • Update your site's configuration files to reflect the new database credentials and set the base URL to your test subdomain:
    Code:
    https://www1.domain.com

🔸 Step 4: Testing Your Migrated Site


  • Thoroughly test your site at:
    Code:
    https://www1.domain.com

  • Verify functionality, performance, and database integrity.

🔸 Step 5: Live Switch with Minimal Downtime

  • On your old server, display a maintenance page to prevent visitor access during migration.
  • Re-export any updated content (e.g., media files) and database from your old server:
    Code:
    mysqldump -h127.0.0.1 -u$userName -p --opt --single-transaction --quick $databaseName > dump.sql

  • Import this fresh database dump into CloudPanel again:
    Code:
    clpctl db:import --databaseName=my-database --file=dump.sql

🔸 Step 6: Final Testing Using Host File


Before changing your DNS publicly, test the migrated site locally by modifying your hosts file:


Windows:
  • Open text editor as Administrator.
  • Edit file:
    Code:
    C:\Windows\System32\drivers\etc\hosts

  • Add entry:
    Code:
    your-server-IP  www.domain.com domain.com

  • Save and test your site in a browser at:
    Code:
    https://www.domain.com
Linux/Mac:
  • Edit hosts file:
    Code:
    sudo nano /etc/hosts

  • Add entry:
    Code:
    your-server-IP www.domain.com domain.com

  • Save changes and test your website at:
    Code:
    https://www.domain.com

🔸 Step 7: Update DNS Records (Go Live)

  • Change your DNS A records for domain.com and www.domain.com to point to your CloudPanel server IP.
  • Disable Basic Authentication to allow public access.
  • Remove the temporary hosts file entry created earlier.


This structured approach ensures a seamless, safe, and minimal-downtime migration to CloudPanel.
 
Solution
Back
Top