Migrations are a kind of version control for your database. They allow a group to modify the database pattern and stay up to date on the current schema state. Migrations are regularly matched with the Pattern Builder to effectively manage your application’s schema.
If you use shared hosting, you are vulnerable to website attacks. So, to save your sites from unwanted traffic, you must move on to cloud hosting. And this blog focuses on migrating PHP and MYSQL with ease, so keep reading to find out more.
A 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, PHP web hosting depends largely on the PHP-based platform, which powers over 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.
This article elaborates on shared hosting problems and how you can migrate PHP and MySQL databases to cloud servers.
Without much ado, let’s begin.
- Shared Hosting: An Informal Intro
- Horrors of shared hosting
- Your Websites Deserves Better Home
- What is Cloudways? Haven’t heard!
- Backup Your Complete Website
- PHP Migration on Cloudways
- Using FTP in Filezilla
- MySQL Migration
- Test On Staging URL
- Essential Settings for PHP App
- Enable Free SSL certificates (HTTPS Redirect)
- Pingdom Test
- Apache Benchmark Test
- Look out for PHP versions at Cloudways
- Migrate PHP To New Versions
- PHP Migration Tools
- Final Words
Shared hosting: An Informal Intro
Shared means distributed resources under one roof; hence, it provides a set of resources to host multiple PHP websites on one server, which is a more economical solution for low-budget websites.
The typical anatomy of shared hosting is like this:
As the image suggests, in shared hosting, a server typically stores multiple client websites, thus sharing the resources. And the server is responsible for managing all websites equally.
You will also get the database with PHPmyadmin client for working purposes, coupled with features like DNS mapping, security, SSL, backups, etc.
So what’s bad about shared hosting? Lots of the things literally, so let’s see why should you avoid shared hosting.
Horrors of Shared Hosting
Suppose your website is running well on a shared server, people are enjoying the content, and you are getting enough sales to stay active in the business. And one day, you check the website, and suddenly your website is nowhere. It’s gone, and you don’t know the reason.
You might see the 500 server error and wouldn’t know what to do.
In situations like these, you might check logs, create support tickets, or head over to the chat agents and spend hours finding the downtime issues. Everything would get very confusing; hence, opting for shared hosting is not recommended.
You Might Also Like: Pitfalls of Laravel Shared Hosting for Your Projects
So let’s learn more about the detriments of shared hosting.
Compromised Security
Shared hosting security is a myth. With shared hosting, your websites are insecure, and hackers can hack them easily if any asset of the website(s) gets affected in the pool. They are vulnerable to malicious traffic, DDoS attacks, and viruses.
No Customization
Tweaking your server needs and customizing any internal settings of Apache, MySQL, or Redis is a hassle with shared hosting. So, you cannot set up solid rules to save your website.
Flexibility
Developers often need to work with 3rd party APIs and packages, requiring some core settings to integrate into the application. Also, late responses or poor speed can affect the website because shared servers perform relatively slowly.
Your Websites Deserves Better Home
Being an agency, developer, or online business owner, you don’t want to face shared hosting hassles and enjoy a smooth hosting solution that ensures availability and high uptime.
All your hosting issues can be resolved by opting for the right hosting provider. You can choose cloud servers like Digitalocean, Vultr, Linode, and Amazon Lightsail to keep your website running all year round. Cloud servers eliminate any speed or performance issues without costing you a fortune.
These cloud servers provide the following features:
- Optimized performance
- High-security environment
- Multiple datacenters
- Handle high traffic spikes
- Dedicated resources
- Multiple applications installation
- 24/7 support
The above-mentioned features are just some of the benefits of cloud hosting. And you don’t want to miss out on these options. So, you can hire a sysadmin to set up a server to get these benefits.
However, with Cloudways, you don’t have to hire a sysadmin or have any Linux knowledge. Everything is simple on the Cloudways platform and happens with a few clicks.
What is Cloudways?
Cloudways is a managed cloud hosting platform that let’s you launch PHP/Laravel servers and applications with a 1-click installation feature on cloud providers like DigitalOcean, Linode, Vultr, AWS , and Google’s GCE server .
With Cloudways, you can handle the server settings, monitoring, security, and performance options with a few clicks. The Cloudways servers come pre-installed with Git, Composer, Supervisord, PHP-FPM, Redis, PHP debugging tools , Memcached, etc, so you don’t have to pick up commands and run them in SSH.
Cloudways also provides 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.
To get the benefits of a cloud hosting service, you must create an account and launch your PHP server on Cloudways in minutes. But first, you should ditch your shared host and back up your complete website files and database to migrate PHP apps on Cloudways.
Stop Wasting Time on Servers
Cloudways handle server management for you so you can focus on creating great apps and keeping your clients happy.
Backup Your Complete Website
Traditional shared hosting like Godaddy or Godaddy alternatives, Hostgator (See Cloudways Hostgator alternative page), and Bluehost (See Cloudways vs Bluehost comparison page) have a Cpanel installed for your convenience. You can back up the complete website by using the compress option.
First, you must log in to Cpanel and create a zip file of the complete website folder.
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.
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:
- Using SSH
- 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.
Once you have logged in, navigate to the public_html folder and run wget command:
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.
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 to easily migrate the MySQL database. Follow the steps below:
- Click on Application Management .
- Click Access Details .
- Now, click on the Launch Database Manager button.
- For MySQL migration, you can import SQL file from here:
- 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 uploaded all the files and database, you must change the database configs in your config settings to completely migrate the MySQL database. This is because you have an old database username and password in the config file.
If you are a Cloudways user, you can see your DB credentials under the MySQL Access section. Copy those credentials and replace them in your config file.
Test On Staging URL
Cloudways also provides a staging URL to run PHP applications in the browser before pointing out the domain name. These staging URLs help developers 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 to the domain registrar.
That’s it! Your website migration process from shared hosting to a cloud server has been completed.
You can use some pre-built PHP migration tools to migrate one PHP version to another 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 like a tedious job to the developers. But using the pre-built PHP 7 migration tools, you can easily reduce your dev work and migrate in minutes.
Now that you have set up almost all the application essentials, you can run it in the browser. You must consider some important steps that I will elaborate in the subsequent paragraphs.
Essential Settings for PHP App
You may need more settings in PHP applications like memory limit, upload size, display errors, xdebug settings, and PHP-FPM rules
Cloudways allows you to set up these options directly from the platform. Therefore, you don’t need to manually find the php.ini file and edit it. Follow the steps below:
- Go to Server Management on the Cloudways Platform.
- Click Settings & Packages.
.
- In Advanced Tab, you can set up more advanced settings like OPcache .
In the Packages tab, you have four versions of PHP available 5.6, 7.0, 7.1, and 7.2, 7.3, 8.0, and 8.1 You can upgrade or downgrade the PHP version easily from the drop-down menu.
There are also some other PHP packages available that you can install with a single click.
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.
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
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 installed both shared hosting Cpanel and my managed DigitalOcean server with London Data Center.
Pingdom Test
Shared Hosting:
Cloudways Managed Digitalocean Server
Apache Benchmark Test
Shared Hosting:
Cloudways Managed Digitalocean Server
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 successfully migrating the PHP application at Cloudways, you must look out for the relevant PHP versions in which your application is developed. Cloudways provides a multipul versions of PHP, which are 5.6. 7.0, 7.1, and 7.2, 7.3, 8.0 and 8.1.
By default, 7.4 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.
To immediately upgrade your server to PHP 8.1 you can follow the steps below:
Go to Server Management > Access Detail > Settings & Packages tab
Select PHP 8.1 from the drop-down menu
Click Save
Read the warning and click OK
The upgrade process takes a few minutes, and your server will be upgraded without any downtime.
Next, to verify that PHP 8.1 is indeed available at your server, Launch the SSH terminal from the Master Credentials tab and log in using your credentials. Use the PHP -v
command to check the installed PHP version.
As you can see, the server has been upgraded to PHP 8.1.
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 8.0 version. Now, the most stable version is PHP 8.1. 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 8.x so you should also migrate PHP to this version so that the coming can be incorporated.
PHP 7 Migration Tools
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:
- PHP 7 Mar
- PHP 7 Compatibility Checker
- Phan
- Phinx for MySQL database migration
- PHPto7aid
- 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 8.0 and 8.1. You can also see the official migration guides for 8.x versions.
Q: Can I use multiple SQL database files?
A: No! 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, most of which 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 answer is NO! You cannot speed up the propagation process because, t he default TTL is mostly set to 14400 (4 hours); however, the network you are using to access the internet may update at a slower rate.
Final Words
This blog thoroughly explains the process of migrating PHP apps to cloud hosting. With cloud hosting, you get fast servers that give your website maximum uptime, so you don’t need to worry about the lousy support services of shared hosting providers.
Since cloud hosting gives you dedicated resources, there is a minimum threat of external malware and virus attacking your website. And with Cloudways firewall, you are safe from all such attacks. You can also set up custom notifications and alerts for your server’s health, meaning if your server goes down, you will get a notification instantly.
Inshal Ali
Inshal is a Content Marketer at Cloudways. With background in computer science, skill of content and a whole lot of creativity, he helps business reach the sky and go beyond through content that speaks the language of their customers. Apart from work, you will see him mostly in some online games or on a football field.