Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

PHP 7.3 Is Now Available On Cloudways. Try Now!

Migrate PHP Website and MySQL Database With This Guide

March 26, 2019

11 Min Read
migrate php
Reading Time: 11 minutes

 

Image Credits: Dribble

This is your website hosted on 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 shared hosting provider, than you are the right person to read this article. Shared hosting sometimes create a lot of hassles that you can’t bear while running your online businesses. The situation may turn for worse when you don’t get proper support and get rid of the shit on time to suffer losses to your business.

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 in near future, or at least until 35 million websites die or convert to any other platform.

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

Without much ado, let’s begin.

Shared hosting: An Informal Intro

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 more economical solution for low budget websites. These small business websites do not tend to scale big enough in near future, 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 good on a shared server, people are enjoying the content and you are getting enough online sales to stay active in 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 from where to begin.

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

In the following paragraphs, I will discuss briefly about 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 setup 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 in 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:

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 which 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 to go 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

These is just a small list of advantages of using cloud storage. I’m sure you don’t want to miss out these options. In fact, all you need is peace of mind. You must hire a sysadmin to setup 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 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 1-click installation feature on popular cloud infrastructure service providers like DigitalOcean, Linode, Vultr, AWS and GCE. 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 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.

Start Growing with Cloudways Today

People Love us because we never compromise on hosting

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.

First you must login to Cpanel and create a zip file of 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 MySQL database and export that to the local system.

export mysql database

Now you have the complete zip file for migrating MySQL database. We’ll see how to migrate 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 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 ‘Enter’ key to extract 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 of zip file here.

filezilla ftp

MySQL Migration

You have all the website files. Now, it’s time for MySQL migration and to import 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 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 SQL file, and click 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 MySQL database. It is because you have old database username and password in config file. For Cloudways, you can get the DB credentials from the same screen where you have launched database under 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 browser before pointing out the domain name. These staging URLs help developers to quickly test and develop apps in dev environment. Once you have completely setup and migrate 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 domain registrar.

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

First PHP Migration Is Free At Cloudways

Cloudways Engineers can migrate your website Flawlessly

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 setup and you can run it in browser. There are some other important steps that you must consider. I will elaborate them in subsequent paragraphs.

Essential Settings for PHP App

There are more settings which you may need in PHP applications like memory limit, upload size, display errors, xdebug settings, PHP-FPM rules. Cloudways offers you the flexibility to setup these options directly from platform. Therefore, you don’t need to find 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 testing phase). You can upgrade or downgrade 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 successful setup and migration of your PHP app, you must install SSL certificate in your application. Cloudways provides free SSL certificate from Let’s Encrypt. You just have to add 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 .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 Cloudways server it is 309 ms.

For 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. Time to process each request is also much lesser than 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 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 server level so all of your applications existing on 1 server must be compatible otherwise run only 1 application on server.

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

Migrate PHP To New Versions

Since last two years PHP has evolved so much that the scripting language got 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 deprications in the current version so that you can replace the updated code available in new version like 7.0. But the biggest pain is when you have the big codebase and you need to migrate the code.

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:

  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 deprications, Errors and warnings. Some tools also helps to migrate database 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.

Final Words

This brings us to the end of this article which thoroughly explained how to migrate PHP apps to a 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 setup custom notifications and alerts for your server health that means if your server goes down you will get a notice instantly.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Launch PHP websites without the worry of Server Management.

Pre-Installed Optimized Stack with Git, Composer & SSH

Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. Besides his work life, he loves movies and travelling. You can email him at shahroze.nawaz@cloudways.com

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!