Javascript required
Skip to content Skip to sidebar Skip to footer

Migrate Mysql Database to New Server

migrate php

Image Credits: Dribble

This is your website hosted on a shared web server. Let's wait and read the article until its completely loaded 😀

If you haven't migrated PHP and MySQL to cloud hosting and your website has recently experienced an attack on a shared hosting provider then you are the right person to read this article. Shared hosting sometimes creates a lot of hassles that you can't bear while running your online businesses. The situation may turn for the worse when you don't get proper support and get rid of the shit on time to suffer losses to your business.

The hosting service provider is the backbone of your online application(s) and website(s) because your online presence is 100% dependent on them.

In most cases, web hosting for PHP depends largely on the PHP-based platform which is a scripting language – which for the past 20 years – is powering approx 80% of the websites on different PHP frameworks like Laravel, Symfony, Codeigniter, and Yii. So, don't think PHP will die soon, or at least until 35 million websites die or convert to any other platform.

In this article, I'll elaborate on shared hosting problems and how you can migrate PHP and MySQL website to cloud servers.

Without much ado, let's begin.

  1. Shared Hosting: An Informal Intro
  2. Horrors of shared hosting
    1. Less Security
    2. No Customization
    3. Flexibility
    4. Downtime & Crashes
  3. Your Websites Deserves Better Home
  4. What is Cloudways? Haven't heard!
  5. Backup Your Complete Website
  6. PHP Migration on Cloudways
  7. Using FTP in Filezilla
  8. MySQL Migration
  9. Test On Staging URL
  10. Essential Settings for PHP App
  11. Enable Free SSL certificates (HTTPS Redirect)
  12. Pingdom Test
  13. Apache Benchmark Test
  14. Look out for PHP versions at Cloudways
  15. Migrate PHP To New Versions
  16. PHP Migration Tools
  17. Final Words

Shared means distributed resources under one roof, hence, shared hosting provides a set of resources to host multiple PHP websites on one server which is a more economical solution for low budget websites. These small business websites do not tend to scale big enough soon, albeit using dynamic external resources. The typical anatomy of shared hosting is like:

shared hosting

As the image suggests, in shared hosting, a server typically stores multiple client websites thus sharing the resources. The server is responsible for managing all websites equally. You will also get the database with PHPmyadmin client for working purposes, coupled with a lot of features like DNS mapping, security, SSL, backups, etc.

So what's the bad about shared hosting? If I delve deeper into details, I will say what's horrible about shared hosting? Lots of the things literally, Let's discuss what's bad about shared hosting.

Horrors of Shared Hosting

Your website is running well on a shared server, people are enjoying the content and you are getting enough online sales to stay active in the business.

Now imagine! You check the website and suddenly your website nowhere. It's gone, and you don't know the reason. The screen is showing the sweet 500 server error :D. What will you do now? Check log? Create support tickets? Head over to the chat agents and spend hours with them to find the downtime issue? There are countless steps you can take, but you don't know where to begin.

You Might Also Like: Pitfalls of Laravel Shared Hosting for Your Projects

In the following paragraphs, I will discuss briefly the horrors of shared hosting.

Less Security

Shared hosting security is a myth. The website is seriously insecure and hackers can hack it easily if any asset of the website(s) gets affected in the pool. You can't easily save it from DDoS attack or virus attacks.

No Customization

If you want to tweak your server needs and customize any internal settings of Apache, MySQL, or Redis, you simply can't, hence you are unable to set up solid rules to save your website.

Flexibility

Often developers need to work with 3rd party APIs and packages which also require some core settings to integrate into the application. Late responses or poor speed can also affect the website because performance is relatively slow on shared servers.

Downtime & Crashes

Downtime and crashes hurt big time, but the issues are prevalent in shared hosting. The shared servers can easily spread over and can negatively affect multiple websites. You will experience the malware issues often coming up, and your website will crash multiple times during a day.

This is my opinion, to which you can disagree. Community reviews provide a good resource to show you all. Let's see what they think about shared hosting:

Shared Hosting is like having bad roommates. pic.twitter.com/ZHtL9q2K6C

— Dalibor Gogic (@daliborgogic_) August 4, 2017

Bad day for crappy hosting companies. http://is.gd/4YZBS I think shared hosting is end-of-life.

— Jen Simmons (@jensimmons) November 19, 2009

containerise whatever you use and keep it all sandboxed. php on shared hosting is a security mess. safemode helps etc

— Kerry Hoath (@khoath) April 17, 2017

@MurrayMintUK @fazy Many hosting companies do well. Shared hosting is not inherently bad, but there are vulnerabilities to be aware of.

— Beth Tucker Long (@e3BethT) February 22, 2014

@ScottWWagner was very disappointed to find GoDaddy offers applications in shared hosting they know cant operate on their system. Cost me an extra $150 to get my system restored back to working. My bad for thinking GoDaddy is quality company.

— Gary Norwalt (@TechNorwalt) September 4, 2018

Once again, my website is intermittently slow to load today and occasionally won't load at all. Once again, there are problems with e-mail. This is what I get for paying for shared hosting. Too bad I can't afford to upgrade to a VPS.

— TVObscurities (@tvobscurities) June 28, 2018

Haha. Shared hosting is a mess. Managed WP VPS all the way 🙂

— Bryan Dwyer (@BtheBD) February 23, 2017

Your Websites Deserves Better Home

Being an agency, a developer, or an online business owner, you don't want to face the above-mentioned hassles and will want to have a smooth hosting solution that can ensure availability and uptime 24/7. Don't worry though. There is a solution for all the website hosting issues you face. You can opt for cloud servers like Digitalocean, Vultr, Linode, and Amazon Lightsail to keep your website running all the year-round.

I always recommend going for these options instead of shared hosting servers because the budget is similar and you tend to get highly optimized instances.

These cloud servers are far better, and provide the following features to benefit you:

  1. Optimized performance
  2. High-security environment
  3. Multiple datacenters
  4. Handle high traffic spikes
  5. Dedicated resources
  6. Multiple applications installation
  7. 24/7 support

There is just a small list of the advantages of using cloud storage. I'm sure you don't want to miss out on these options. All you need is peace of mind. You must hire a sysadmin to set up a complete server on any of the above-mentioned hosting service providers.

What if a tell you that you don't need to know Linux or hire a sysadmin? Yes! Cloudways managed hosting is your new home.

What is Cloudways? Haven't heard!

In simple terms, Cloudways is a managed cloud hosting platform through which you can launch PHP / Laravel servers and applications with a 1-click installation feature on popular cloud infrastructures service providers like DigitalOcean, Linode, Vultr, AWS, and Google's GCE server. You can handle the server settings, monitoring, security, and performance options on Cloudways managed hosting platform with few clicks. The Cloudways servers come pre-installed with Git, Composer, Supervisord, PHP-FPM, Redis, PHP debugging tools, Memcached, etc. so you don't need to pick up commands and run in SSH.

Cloudways also provides you easy server and application management options like DNS Management, MySQL migration, SSL certificates, SMTP, Server Cloning and Transfer, Team Collaborations, Staging Environments for developers, and lots of other features. Sounds good?

To get the benefits of a cloud hosting service, you must first create an account and launch your PHP server on Cloudways. But first, you need to ditch your shared host and backup your complete website files and database to migrate PHP apps on Cloudways.

Experience 10x Faster Load Time On Your PHP Web Applications

We understand the value of faster websites in today's highly competitive business era.

Backup Your Complete Website

Traditional shared hosting like Godaddy, Hostgator, and Bluehost always have Cpanel installed for your convenience. You can backup the complete website by using the compress option. Also see bluehost alternative.

First, you must log in to Cpanel and create a zip file of the complete website folder.

php website backup

Once the compression process is complete, log in to the database manager (PHPMyAdmin in many cases) from where you can migrate the MySQL database and export that to the local system.

export mysql database

Now you have the complete zip file for migrating the MySQL database. We'll see how to migrate the MySQL database later in this article. But now, it's time to say goodbye to the old shared hosting service.

PHP Migration on Cloudways

Now you are just about to get a new, fast, and highly optimized hosting service. I assume that you have already signed up to Cloudways, and you are ready with your first PHP application server. If not yet, you can follow the gif below:

Now, you have launched the server successfully. You have two options to upload your website file:

  1. Using SSH
  2. Using FTP

If you are familiar with SSH commands, then it's easy for you to upload files via wget command. Do remember that you have a zip file on Cpanel and it's still there. You must copy its URL. For instance, I have a website https://shahroznawaz.com and I've created a complete zip file on root the URL will be https://shahroznawaz.com/website.zip . Now log into Cloudways SSH Terminal using your master credentials. You can find them on the Access details page.

launch ssh

Once you have logged in, navigate to the public_html folder and run wget command:

navigate to public_html

Hit the 'Enter' key to copy the zip file to the root directory. Now unzip the file by running the command:

Unzip your-website

Hit the 'Enter' key to extracting all the files to the root directory.

Using FTP in Filezilla

The second option to migrate your website is via FTP using FileZilla client. You can simply connect FTP with master credentials (host, username, password). Then navigate to your application folder again and drag all the files into the folder. There is no need for a zip file here.

filezilla ftp

MySQL Migration

You have all the website files. Now, it's time for MySQL migration and to import the database. Cloudways provides the custom database panel – for your convenience – just like PHPmyadmin from where you can easily migrate MySQL database. You must navigate to the Application Details Page and click on Launch Database Button.

launch mysql manager

For MySQL migration, you can import SQL file from here:

mysql migration

Upload the SQL file, and click the Execute button. Your database is now populated with your desired files.

Change MySQL Database Configs

Now that your MySQL migration is completed and you have all the files and database uploaded, you must change the database configs in your config settings to completely migrate the MySQL database. It is because you have an old database username and password in the config file. For Cloudways, you can get the DB credentials from the same screen where you have launched the database under the MySQL Access section. Copy credentials and replace them in your config file.

Test On Staging URL

Cloudways also provides a staging URL through which you can run PHP applications in the browser before pointing out the domain name. These staging URLs help developers to quickly test and develop apps in a dev environment. Once you have completely set up and migrated the PHP application, you can point your domain in DNS Management Tab, replacing the staging URL with your actual domain name. Don't forget to point your server IP and staging URL in the domain registrar.

That's it! Your website migration process from shared hosting to a cloud server is complete. Yayy!!

100% Secure PHP Hosting with 24/7/365 Efficient App Monitoring

We offer the best in class security of your web applications with proactive app monitoring.

For migrating one PHP version to another, you could use some pre-built PHP migration tools . For instance, migrating PHP 5.x to PHP 7.x often looks a tedious job to the developers. But using the pre-built PHP 7 migration tools , you could easily lessen your dev work having migration done in minutes.

Now almost all the application essentials have set up and you can run it in the browser. There are some other important steps that you must consider. I will elaborate on them in subsequent paragraphs.

Essential Settings for PHP App

There are more settings that you may need in PHP applications like memory limit, upload size, display errors, xdebug settings, PHP-FPM rules. Cloudways offers you the flexibility to set up these options directly from the platform. Therefore, you don't need to find the php.ini file and edit it.

cloudways php settings

In Advance Tab, you can set up more advanced settings like OPcache.

opcache settings

In the Packages tab, you have four versions of PHP available 5.6, 7.0, 7.1, and 7.2 (7.3 is in the testing phase). You can upgrade or downgrade the PHP version easily from the drop-down menu. There are also some other PHP packages available which you can install with a single click.

manage cloudways packages

Enable Free SSL certificates (HTTPS Redirect)

After the successful setup and migration of your PHP app, you must install an SSL certificate in your application. Cloudways provides a free SSL certificate from Let's Encrypt. You just have to add an email and domain name to install the certificate. Once you have installed the SSL certificate, you can set the toggle to auto-renewal so that your certificate will auto-renew after 90 days.

Enable ssl

After installing the SSL certificate, you must redirect Http URLs to https by adding rules in the .htaccess file. Also, replace all https URLs from your code.

Testing on Shared and Cloudways Server

As I've mentioned in an earlier paragraph, shared hosting is not suitable for websites loading rigid content and dynamic templates. To concrete the case let's test the website on both platforms. I've used the admin dashboard and install on both shared hosting Cpanel and my managed DigitalOcean server with London Data Center.

Pingdom Test

Shared Hosting:

shared hosting performance

Cloudways Managed Digitalocean Server

Cloudways php speed

Apache Benchmark Test

Shared Hosting:

shared hosting apache benchmarks

Cloudways Managed Digitalocean Server

cloudways php apache benchmarks

Both of the tests are self-explanatory. The results show a major difference in data. The Pingdom shows the load time on shared hosting is: 1.41 sec while on the Cloudways server it is 309 ms.

For the Apache benchmark test, I've set 1000 requests with 100 concurrent users and the result for shared hosting is request/sec = 560 and for Cloudways it is 735 request/sec. The time to process each request is also much lesser than a shared hosting server.

This is a simple test. If I must go ahead with more customizations – with caching, OPcache, PHP-FPM, and Memcached – the results will change drastically and you will get an optimized picture.

Look out for PHP versions at Cloudways

While you successfully migrate PHP application at Cloudways you must look out for the relevant version of PHP in which your application is developed. Cloudways provides a variety of 4 versions of PHP which are 5.6. 7.0, 7.1, and 7.2 (7.3 in testing). By default 7.0 is installed when you launch any new server on Cloudways. You can easily upgrade or downgrade the versions. Remember the PHP will install on the server level so all of your applications existing on 1 server must be compatible otherwise run only 1 application on the server.

For updating the PHP version you can move to Server details → settings & Packages →  Packages Tab. Here you will see the drop-down of the PHP version select your desired version and update it.

Migrate PHP To New Versions

Since the last two years, PHP has evolved so much that the scripting language got a major update of PHP 7.0 version after that a series of 7.x versions has come for developers. Now, the most stable version is PHP 7.3. Previously we have written an article on migrating PHP 5.6 to 7.0 which you can follow if your application is still using 5.6 because any kind of update is finished now for this. The recommended version is now PHP 7.3 so you should also migrate PHP to this version so that the coming can be incorporated.

The first thing you must see is the depreciation in the current version so that you can replace the updated code available in a new version like 7.0. But the biggest pain is when you have the big codebase and you need to migrate the code.

At this time, there is no automated PHP migration tool to achieve the version migration but of course, there are tools available to identify the deprecations and compatibility like these:

  1. PHP 7 Mar
  2. PHP 7 Compatibility Checker
  3. Phan
  4. Phinx for MySQL database migration
  5. PHPto7aid
  6. PHP 7 Upgrade Tool

The above tools will help you find out the depreciation, Errors, and warnings. Some tools also help to migrate databases like Phinx.

I've already mentioned the migration guide from PHP 5.6 to 7.0. You can also see the official migration guides for 7.1, 7.2, and 7.3 versions.

Q: Can I use multiple SQL database files?

A: If multiple SQL files are present, the import/migration will fail. Only provide one .sql file per site as Cloudways only allows one database per site.

Q: How long does it take to transfer a website from one host to another?

A: To transfer a website from one hosting provider to another, it shouldn't take more than 10-12 hours, and most of that time is DNS propagation. The speed of the migration depends largely on your hosting providers.

Q: How can I speed up the propagation process?

A: The short answer is no. Mostly, the default TTL is set to 14400 (4 hours); however, the network that you are using to access the internet may update at a slower rate.

Final Words

This brings us to the end of this article which thoroughly explained how to migrate PHP apps to Cloud hosting. Ain't you happy now? All you get is fast servers which give your website maximum uptime and you don't need to crack your head with support services of that lousy shared hosting providers. Since you are utilizing the dedicated resources now, there is no threat of external malware and virus attacking your website, because Cloudways firewall is there to save you from these attacks. You can also set up custom notifications and alerts for your server health that means if your server goes down you will get a notification instantly.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Customer Review at

"Cloudways hosting has one of the best customer service and hosting speed"

Sanjit C [Website Developer]

Migrate Mysql Database to New Server

Source: https://www.cloudways.com/blog/migrate-php-and-mysql/