iamYannC's avatar

upgrading vsanilla php 5.4 to 8.x with laravel

Hey guys. I work at a small company and act as this guy "that's good with technology". i.e, anything related to backend, frontend and god forbid, even devops is being dumped at me. Our software was built 20 years ago by an external company that doesnt exist anymore.

I was asked to upgrade our legacy php 5.4 to recent version and i figured it would also be a great opportunity to shift to using Laravel.

I am already equipped with a docker env for php 5.6 (the earliest i could find that worked well), and the usual PHPStan, PHP_CodeSniffer and Rector.

Obviously, claude code will come to the rescue here. Since this is honestly not my strong skillset (I'm really not a backend guy) - I would love it if someone here could make themselves available to me for questions i might have along the way. I am going to write a complete test suite (again, with claude code) on top of what we currently have (not much).

Also, If there is a relativley cheap service that does such things, and you can reccomand first hand, I might just propose to my boss to outsource it completley - as i might not be the right guy for the job (I dont have seniors with me to guide me through. its basically "you know how to code - do it!"

0 likes
5 replies
martinbean's avatar
Level 80

@iamyannc Hey. I’ve done a lot of these type of re-factoring and re-platforming projects in the past. The way I’d approach it would be like this:

  • Get the application running on a newer version of PHP. So upgrade to 7, fix any usage of deprecated APIs and libraries, and then when possible upgrade to PHP 8 and do the same.
  • Once you’ve got the vanilla PHP application running on a modern version of PHP, create a new Laravel application and dump your legacy application’s file in the public directory.
    • Rename Laravel’s index.php file to something like laravel-index.php to avoid clashing with your legacy index.php file.
    • Tweak your .htaccess or nginx config to just load a file if it exists, or fall back to Laravel’s front controller.
  • You should now have a Laravel application, but with no requests actually being routed through it to start off with, and instead requests hitting your legacy application as before.
  • Slowly start re-factoring your legacy application to Laravel controllers, views, etc. Do this slowly, and one discreet part at a time. Trying to re-factor too much in one go just leads to lots of files being touched, none of them 100% converted, and the dreaded feeling of, “Urgh, I need to git reset this and start over.”
  • As you do the above, the number of files from the legacy application will decrease, and the number of Laravel files increase, until you’re left with nothing of the legacy application.

Happy for you to reach out if you have any questions. DM me on Twitter 𝕏 (https://x.com/martinbean) and I can share my email address.

3 likes
iamYannC's avatar

Hey Martin. I replied to a post of you on X, as I cant DM you anywhere. I appriciate your advice, and coupled with the other advices on reddit, that's what I'll do: backup test upgrade upgrade upgrade laravel :)

and for sure would appriciate if i could get you mail, can you DM me on one of the platforms so i can reply there?

jlrdw's avatar

Also before doing anything and while converting at various times:

Backup your data

1 like
iamYannC's avatar

lol. FOR SURE! that deserved font size 50, at least :P

1 like
vincent15000's avatar

I've already done this in the past too.

Rather than upgrading, it's sometimes faster to create a new application.

Here is what I did :

  • backup all data
  • keep all views and actions
  • create a new application
  • implement all functionalities, one by one
1 like

Please or to participate in this conversation.