Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] How to Migrate Website from PHP 5.6 to PHP 7

#1
How to Migrate Website from PHP 5.6 to PHP 7

<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/08/how-to-migrate-website-from-php-5-6-to-php-7.jpg" width="550" height="190" title="" alt="" /></div><div><p>Last modified on August 16th, 2020.</p>
<p>If you have to come this article now with an intention to migrate your website from PHP 5.6 to PHP 7, first please be aware. Your time is already over. This is too late. Somehow you should get this done now. Do not postpone this work beyond this moment.</p>
<p>This is an overwhelming task. We never know what will break. For now things are running smooth with the website. If we migrate the version to PHP 7, we do not know if it will run or not. So everybody keeps postponing this sensitive task.</p>
<p>Fear not, I will guide you through this migration journey. I have done it for many <a href="https://phppot.com/php/simple-php-shopping-cart/">shopping cart</a>, financial domain and critical websites. I have sound experience doing this and you can bank on me. I will present you my experience doing these migrations.</p>
<h2>Upgrading the setup or development or server environment to PHP 7</h2>
<p>I will guide you for the migration of the PHP application or website only. Upgrading the server environment like Apache version or the installed PHP version can be dealt with another article. It is a sysadmin thing.</p>
<p>If you are on a shared web hosting server, you will have an option in your control panel. It should be a single click easy work. Otherwise your hosting provider will do it for you. You may have to raise a ticket to get it done. Unless if you are in a dedicated server environment, you need not worry about.</p>
<p>Whatsoever, migration of the website or the PHP application should be done by you. It is not in the hosting provider or sysadmin’s scope. It should be done by the PHP developer.</p>
<h2>PHP versions, support and EOL</h2>
<p>Why now? What is the necessity to migrate PHP 5.6 to PHP 7 now? Before going into why, you should know about the PHP versions, their support duration and EOL details. It will give you the answers.</p>
<p><a href="https://phppot.com/wp-content/uploads/2020/08/php-versions-support-eol.jpg"><img class="alignnone wp-image-11845 size-large" src="https://phppot.com/wp-content/uploads/2020/08/php-versions-support-eol-550x190.jpg" alt="PHP versions support and EOL" width="550" height="190" srcset="https://phppot.com/wp-content/uploads/2020/08/php-versions-support-eol-550x190.jpg 550w, https://phppot.com/wp-content/uploads/20...00x104.jpg 300w, https://phppot.com/wp-content/uploads/20...68x265.jpg 768w, https://phppot.com/wp-content/uploads/20...36x530.jpg 1536w, https://phppot.com/wp-content/uploads/20...rt-eol.jpg 1749w" sizes="(max-width: 550px) 100vw, 550px"></a></p>
<p>Ref: <a href="https://www.php.net/supported-versions.php">https://www.php.net/supported-versions.php</a></p>
<h2>Why should you migrate from PHP 5.6?</h2>
<p>PHP 5.6 version active releases ended in early 2017 and reached its end of life (EOL) by 2018 end. That was once upon a time and long long ago. After PHP 5.6, we had PHP 7.0, 7.1, … and the current live version is 7.4</p>
<p>My longtime client recently forward an email he got from his hosting provider. His website is hosted with a popular shared hosting server.</p>
<p>The hosting provider has given ten days time to upgrade from PHP 5.6 to PHP 7.2 Even they have asked to migrate PHP 7.0 and PHP 7.1 to PHP 7.2 If the upgrade is not done within the given time frame, the hosting provider will upgrade the PHP version to 7.2 themselves.</p>
<p>This timeframe is to allow migrate the website to be compatible with 7.2. The control panel allows to change the <a href="https://phppot.com/php/php-in-website-development-era/">PHP versions</a> back and forth.</p>
<p>If you are in a shared hosting server environment, you will be forced to migrate anytime soon. You better make the move yourself, so that you can plan and execute at your convenience.</p>
<h2>Security</h2>
<p>If there is one reason that stands on top of everything is security. There are many vulnerabilities that are being exposed to public daily. When there is a known vulnerability, PHP team will release a fix.</p>
<p>But if the PHP version has reached it EOL, then there will not be a release. Your website will stand exposed inviting the hackers. So it is important to migrate your website to a PHP version that is being supported. Upgrade your old PHP now!</p>
<h2>Performance</h2>
<p>There are numerous studies published and circulated widely. PHP 7 has, “100%+ performance gain on most real-world applications” says Rasmus Lerdorf (Ref: <a href="http://talks.php.net/fluent15#/php7">http://talks.php.net/fluent15#/php7</a>) This is from his slides from PHP 7 talk at fluentconf. The good performance due to low latency is widely acknowledged.</p>
<p><img class="alignnone size-large wp-image-11847" src="https://phppot.com/wp-content/uploads/2020/08/PHP-7-performance-550x398.png" alt="PHP 7 performance" width="550" height="398" srcset="https://phppot.com/wp-content/uploads/2020/08/PHP-7-performance-550x398.png 550w, https://phppot.com/wp-content/uploads/20...00x217.png 300w, https://phppot.com/wp-content/uploads/20...68x556.png 768w, https://phppot.com/wp-content/uploads/20...rmance.png 1006w" sizes="(max-width: 550px) 100vw, 550px"></p>
<p>So how does good performance help your website? For one second lag, you will loose a minimum of 10% visitors. Search engines give priority to fast loading websites. Are these two reasons not enough?</p>
<p>As published by Christian Vigh, <strong>PHP 7 is faster by a whooping 400% than PHP 5.2</strong></p>
<p><img class="alignnone size-large wp-image-11848" src="https://phppot.com/wp-content/uploads/2020/08/PHP-performance-benchmark-550x292.png" alt="PHP performance benchmark" width="550" height="292" srcset="https://phppot.com/wp-content/uploads/2020/08/PHP-performance-benchmark-550x292.png 550w, https://phppot.com/wp-content/uploads/20...00x159.png 300w, https://phppot.com/wp-content/uploads/20...68x407.png 768w, https://phppot.com/wp-content/uploads/20...chmark.png 1388w" sizes="(max-width: 550px) 100vw, 550px"></p>
<p>Ref: <a href="https://www.phpclasses.org/blog/post/493-php-performance-evolution.html#performance">https://www.phpclasses.org/blog/post/493-php-performance-evolution.html#performance</a></p>
<h2>New PHP features</h2>
<p>Developers should be armed with good set of tools. When the language gives a good set of features, that enables the developer to produce a good product. Following are some of the features that are available in PHP 7.</p>
<ul>
<li>The null coalescing operator</li>
<li>Return and scalar type declarations</li>
<li>Anonymous Classes</li>
<li>Zero cost asserts</li>
<li>Typed properties 2.0</li>
<li>Preloading</li>
<li>Null coalescing assignment operator</li>
<li>Improve openssl_random_pseudo_bytes</li>
<li>Weak references</li>
<li>New custom object serialization mechanism</li>
<li>Password hash registry</li>
<li>Covariant returns and contravariant parameters</li>
<li>Spread operator in array expression</li>
<li>Multi-catch exceptions</li>
<li>Keys usable in lists</li>
</ul>
<h2>Backwards compatibility</h2>
<p>This is the key thing to focus on website migration. You might have used a feature that is available only in the lower version and removed in the newer version. Here is a list of backward incompatible changes between PHP 5.6 and PHP 7.0</p>
<ul>
<li>set_exception_handler() is no longer guaranteed to receive Exception objects</li>
<li>Internal constructors always throw exceptions on failure</li>
<li>Parse errors throw ParseError</li>
<li>list() no longer assigns variables in reverse order</li>
<li>Empty list() assignments have been removed</li>
<li>list() cannot unpack strings</li>
<li><a href="https://phppot.com/php/power-of-php-arrays/">Array</a> ordering when elements are automatically created during by reference assignments has changed</li>
<li>Parentheses around function arguments no longer affect behaviour</li>
<li>foreach no longer changes the internal array pointer and more changes.</li>
<li>Changes to Division By Zero and more integer handling changes.</li>
<li>Hexadecimal strings are no longer considered numeric and more string handling changes.</li>
<li>All ext/mysql functions and more list of functions removed.</li>
<li>New objects cannot be assigned by reference</li>
<li>Switch statements cannot have multiple default blocks</li>
<li><a href="https://phppot.com/php/json-handling-with-php-how-to-encode-write-parse-decode-and-convert/">JSON</a> extension replaced with JSOND</li>
</ul>
<p>The above list is a summary only. Go through Ref: <a href="https://www.php.net/manual/en/migration70.incompatible.php">https://www.php.net/manual/en/migration70.incompatible.php</a> for the complete list.</p>
<h2>Deprecated features in PHP 7.0</h2>
<p>So you are going to move forward. Know about what you should not use going forward. If you have already used the deprecated features, then it is better to migrate them also. Here is a list the deprecated list.</p>
<ul>
<li>PHP 4 style constructors</li>
<li>Static calls to non-static methods</li>
<li>password_hash() salt option</li>
<li>capture_session_meta SSL context option</li>
<li>ldap_sort() function is deprecated.</li>
</ul>
<h2>More list of changes to keep an eye on</h2>
<h2>Steps to do the PHP website migration</h2>
<ol>
<li>Backup your website, application, database, data in disk.</li>
<li>Check if your hosting provider or your environment will allow to rollback the PHP version. This will be helpful if in case you are stuck at some point.</li>
<li>Check the PHP compatibility for the respective version of the dependent vendor applications, plugins, modules and extensions.</li>
<li>Prepare a checklist for items to be changed for backwards incompatibility. Refer above for consolidated list.</li>
<li>Add the deprecated items to the checklist. Refer above for consolidated list.</li>
<li>Use a well equipped IDE. Detach the old dependent PHP library and then add the new to be migrated PHP library. The IDE will warn and show errors. I promise, this will be helpful. If you are a person using a plain texteditor, then now is the time to dump it.</li>
<li>Refactor the code.</li>
<li>Deploy in a staging environment.</li>
<li>Test.</li>
<li>Go live.</li>
</ol>
<p><!-- #comments --> </p>
<div class="related-articles">
<h2>Popular Articles</h2>
</p></div>
<p> <a href="https://phppot.com/php/how-to-migrate-website-from-php-5-6-to-php-7/#top" class="top">↑ Back to Top</a> </p>
</div>


https://www.sickgaming.net/blog/2020/08/...-to-php-7/
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016