I finally had an afternoon free, to test the upgrade of the base PHP framework CodeIgniter, on one of my websites.
We need to search for the constant “CI_VERSION” defined inside the code. In my case the starting point was version 1.7.2.
Now we neet to understand which one is the latest version in the download section (currently 2.1.3) of CodeIgniter’s website.
The next step is to find out our upgrade path defined on the upgrade page and to download the required packages.
In my case I downloaded my current version 1.7.2 and the latest 2.1.3.
NOTE: If for any reason you are still running PHP 4, you will not be able to upgrade to CodeIgniter 2.x. It only supports PHP 5.1 and above.
Let’s actually get to work
Now that we have all the info, we just need some elbow grease and get to work!
We unzip the original CodeIgniter package and then diff the “system” folder, excluding obviously the code inside the “application”, “logs” and “cache”, to make sure that we did not change anything on the core code, that we will need to carry across later on after the upgrade. The command should look something like this:
diff -auNwr -x "application" -x "cache" -x "logs" ci1.7.2/system/ my1.7.2/system/ > ci172_to_prod_system_folder.diff
The last command I want to share, is the diff I used inside the application folder for sanity check, excluding the standard folders already present in version 1.7.2. It is useful to see if we missed any changes on the application folder (eg: third_party did not exist for me, and errors folder changed slightly):
diff -auNwr -x "config" -x "controllers" -x "models" -x "cache" -x "views" -x "language" -x "helpers" -x "hooks" -x "plugins" -x "libraries" ci2.1.3/application/ my2.1.3/application > ci2.1.3_to_my2.1.3_additionals_in_application_folder.diff
We have to keep in mind few things while proceeding with the upgrade:
- We need to follow the upgrade guide, and make sure not to miss any of the steps. That should complete the bulk of the job.
NOTE: To upgrade from 1.7.2 to 2.1.2 you will have to follow all the instructions, including all the intermediate version’s upgrades. All the steps of the 8 upgrade processes are required
- Make sure to replace the main index.php with the most recent version
- For simplicity, I suggest to move the “application” folder out of the “system” folder (as the clean CodeIgniter >= 2.0.0 package does). With this step we would also move the cache and logs folders, so that the “system” folder contains only the main application files. This will definitely make subsequent upgrades easier
- Make sure to merge all the config files, so that they will contain the most recent options added on the release package
- For cleaning and tidying up purposes, make sure to remove unnecessary folders from the upgraded system (See the first diff command above). An example that comes immediately to mind is the “system/codeigniter” folder that can be removed since version 2.0.0. The Scaffolding functionality has also been removed, etc
- Make sure that the application folder (apart from your application’s code) has the same files and structure of a clean package (eg: check for .htaccess and index.html missing, few files inside the “application/errors” folder changed over time, etc). (See the second diff command above)
- The *nix command “diff” is really your friend, to help you find out any difference or missing files
- Backup, backup backup! :)
Based on this upgrade experience, the most time consuming part of my upgrade has been between version 1.7.2 and 2.0.0. The refactoring part of all models and controllers (upgrade steps 6 and 7 of 1.7.2 to 2.0.0) took a while, especially if the application has plenty of controllers and models! The merging of configuration files was quite tedious as well. Overall, I must say that the experience was quite smooth.
That’s all from me, good luck with your upgrades and let me know how it goes!