@devharm I’ve worked on numerous refactoring and re-platforming projects like this.
First, I’d completely ignore things like Inertia. You just want to concentrate on moving code from your CodeIgniter codebase to a Laravel one. I’d also strongly suggest you set up version control, given you’re going to be changing lots of files, and you really need confidence in being able to roll back if something hasn’t gone as you expected it to.
First, I’d complete this set-up tasks:
- Get your CodeIgniter checked into a Git repository as it is now.
- Get a deployment pipeline set up that can deploy your Git repository, to your server.
So, before you’ve even started on the Laravel conversion, you can confidently track changes and have those changes deployed to your server without manually FTP-ing or SSH-ing into your production server, or however you’re manually deploying currently. You can then focus on the re-platforming:
- Create a new Laravel application.
- Use the
php artisan schema:dumpcommand to get a “squash” migration that represents your database schema as it currently is. - Update your nginx server configuration to first try and pass the request through Laravel’s public/index.php front controller, then to fall back to your CodeIgniter app’s front controller. This means that Laravel will attempt to handle requests first, and then to CodeIgniter if Laravel cannot handle the request. To start off with, all requests will end up going to CodeIgniter.
- Pick a simple page. Create a controller and route for it in your Laravel application, and copy the view over. Extract any plain PHP logic to appropriate classes. Delete that route and controller action from your CodeIgniter application.
- Create “smoke tests” in your Laravel app for this new route. Basically just assert that hitting the expected URL returns a
200 OKresponse. This will give you decent test coverage out of the box, and you can then flesh these tests out with more test cases and in-depth assertions at a later date. - Deploy. The new route should be handled by the Laravel application rather than CodeIgniter.
If you keep re-doing points 4 through 6 (picking pages and lifting them into your Laravel application), you should find over time that your CodeIgniter codebase starts to decrease in size, and your Laravel application codebase increases in size. Once all requests are being handled by Laravel, you can then just discard what’s left of the CodeIgniter application, and go forward with Laravel solely.
Also meant to mention: be sure to create migrations for any database changes after you’ve ran the schema:dump command. You’ll also want to structure your directories on your server to avoid exposing any sensitive, server-side files. I’d recommend a structure like this:
.
├── codeigniter
│ ├── app
│ ├── system
│ ├── tests
│ └── writable
├── laravel
│ ├── app
│ ├── bootstrap
│ ├── config
│ ├── database
│ ├── resources
│ ├── routes
│ ├── storage
│ └── tests
└── public_html
├── index-codeigniter.php
└── index-laravel.php
You will need to update the public paths for your CodeIgniter and Laravel applications since they slightly deviate from their norms. But it means your sensitive CodeIgniter and Laravel files will be outside of the public, web-accessible directory.