Skip to main content

Best Practices - PHP Site Migration

You will find best practices on this site on how to migrate a PHP Site to CloudPanel. In our example, we will migrate our site www.domain.com to CloudPanel. Before going live, we need to ensure that our site is running as well as expected before doing the live switch.

Create a PHP Site

Live Domain

Create your site with the live domain so that the redirection from non-www to www and vice versa is correctly generated.

  1. Create a PHP Site via CloudPanel or via CLI with your domain www.domain.com.

In the Vhost of your site, you see that the subdomain www1.domain.com has been added by CloudPanel, which will be used as our pre-live domain for testing purposes.

www1 subdomain
  1. Create a DNS Record (A) for the subdomain www1.domain.com.

  2. Enable Basic Authentication to prevent being indexed by search engines.

Site Migration

  1. Copy your sites files from the old server to CloudPanel.

  2. Export the database by using mysqldump:

mysqldump -h127.0.0.1 -u$userName -p --opt --single-transaction --quick $databaseName > dump.sql
  1. Upload the database dump dump.sql to CloudPanel.

  2. Login via SSH with the site user and import it via CloudPanel Cli.

clpctl db:import --databaseName=my-database --file=dump.sql
  1. Configure your site to run under the subdomain https://www1.domain.com.

Testing

Take some time for testing to ensure that your site is running as expected on CloudPanel.

Live Switch

  1. Put a maintenance site on the old server to prevent visitors from accessing the site.

  2. Export files like a media directory, which may have been changed in the meantime.

  3. Export the database by using mysqldump:

mysqldump -h127.0.0.1 -u$userName -p --opt --single-transaction --quick $databaseName > dump.sql
  1. Upload the database dump dump.sql to CloudPanel.

  2. Login via SSH with the site user and import it via CloudPanel Cli.

  3. Add a host file entry for the final testing before switching the DNS Records.

  1. Open your text editor in Administrator mode.
  2. In the text editor, open C:\Windows\System32\drivers\etc\hosts.
  3. Add the IP Address and domains.
8.8.8.8 www.domain.com domain.com
  1. Save the changes.
  1. Open your browser and do a final testing of https://www.domain.com.

  2. Change the DNS records for domain.com and www.domain.com to the server ip.

  3. Disable Basic Authentication.

  4. Remove the host file entry from step 6.