Moving project from PHP 5.6 to PHP 7 - how easy is this?

Hello. Due to my shared hosting only offering one version of PHP per account (a friend has shared hosting where he can apply a different version of PHP to different vhosts - so it does exist!) and having websites that won’t currently run on PHP 7 (mainly to the use of mysql and not mysqli or PDO) I’m in the possition where I have to start a new Yii2 project using PHP 5.6 as the base environment variable for the install.

However, once I potentially get this project finished, it will replace the current PHP 5.6 website and I can switch the server to PHP 7, but the question then is, how easy would it be to move the PHP 5.6 based Yii2 install, over to a PHP 7 Yii2 based install? Would all the models and over code just work with the different PHP 7 based dependencies installed in the background?

Thanks.

Yii itself is compatible with PHP 7+ so there should be no problems on the core side. As for your custom code there - read https://www.php.net/manual/en/migration70.php and check if you are using anything that has been changed/removed/deprecated before migrating.

Hi Bizley, thanks.
My concern is that Yii2 installs different dependencies based on the version of PHP Composer detects, i.e. If it detects PHP 7+, there are a lot of Symfony components installed, if not, none are. Thanks, I’ll check out the link though, cheers.

No, it’s not the case as far as I know.

Hi mate.

Just an update in case anyone with the same question is reading this. I am a bit of a noob when it comes to using CLI and composer etc for web design… I’m pretty old skool.

Tl;dr: using the composer upgrade command (> composer upgrade), worked.

I installed Yii 2 under PHP version 5.6, which installs a completely different set of components than if you install under PHP v7.0+ (namely, a lot of Symfony components). I had concerns about eventually wanting to upgrade the project from using 5.6 set of components to the Symfony-heavy PHP 7.0+ components.

So I switch my local environment to PHP v7.3 (ran: > php --version ,in terminal just to check it was correctly detected). Using Git created a test branch, then in the test branch, ran: > composer update, and sure enough, composer detected the newer PHP version and just installed everything.

Sorry if this seems like a really obvious thing to folks, but it’s new to me who is used to fighting with FTP programs and folder permissions etc etc to install and upgrade packages… it’s pretty mind blowing to me that composer does all this for you!

EDIT, it seems like even if I run composer upgrade on a different branch, the composer lock files will get updated on the master branch too! So, perhaps I need to make a copy of the repo for an upgrade as it’s too major to contain in a branch?