16
Managing different PHP Versions while testing Laravel Modules.
Though I like to work with the latest version of PHP, which is 8+, many times while testing some Open-source modules of Laravel framework, I encountered problems such as finding some of the module’s dependencies require a different PHP version.
Example while trying to install this module with PHP 7.4 installed on my laptop;
composer require postcode-nl/api-magento2-module
However, the installation failed this error:
`Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- feedbackcompany/module-reviews 1.0.0 requires php ~7.1.3||~7.2.0||~7.3.0 -> your PHP version (7.4.18) does not satisfy that requirement.
- feedbackcompany/module-reviews 1.0.0 requires php ~7.1.3||~7.2.0||~7.3.0 -> your PHP version (7.4.18) does not satisfy that requirement.
- feedbackcompany/module-reviews 1.0.0 requires php ~7.1.3||~7.2.0||~7.3.0 -> your PHP version (7.4.18) does not satisfy that requirement.
- Installation request for feedbackcompany/module-reviews ^1.0 -> satisfiable by feedbackcompany/module-reviews[1.0.0].
`
If you ever faced a problem like this, there are two ways to handle this;
A new feature in Composer v2 allows you to selectively ignore platform requirements.
composer install --ignore-platform-req=php
Composer already had the --ignore-platform-reqs option, but it ignored all platform requirements, including PHP version, extensions (ext-*), and composer-plugin-api. However now we can just use it to set specific requirements that Composer can ignore.
Now this can be a hassle to uninstall the entire XAMPP installation and reinstalling especially since XAMPP don’t even allow installing on a folder if it exists already.
Now assuming you already have some XAMPP version running, you can download multiple portable version of PHP that you wish to work from the link below
(Remember to click on show all activity, to see all the different versions available)
Download the version of PHP’s you want, ensuring you are selecting the portable version, and not the executable version. (Either .zip or .7z)
Here are some versions I downloaded
XAMPP released /XAMPP Windows/8.0.13/xampp-portable-windows-x64-8.0.13-0-VS16.zip
XAMPP released /XAMPP Windows/7.4.26/xampp-portable-windows-x64-7.4.26-0-VC15.zip
XAMPP released /XAMPP Windows/7.3.33/xampp-windows-x64-7.3.33-0-VC15.zip
And so on.
Unzip them one by one in their own folders and then delete everything inside them except the Apache and PHP folders. I have arranged them as follows in my laptop
As mentioned, each version only contains the Apache and PHP folders only.
Copy the current PHP version’s php.ini (c:\xampp\php\php.ini) to the correct versions PHP folder here, so that you don’t lose any configuration you had made and want it back when you put your original PHP version back.
Next, you need to stop all services in the XAMPP control panel.
Next delete the Apache and PHP folder from the c:\xampp folder (or wherever your XAMPP installation files are).
Now copy the Apache and PHP file from the version you want here. Restart the services from XAMPP, and that’s it. You have got the PHP version you want installed.
When you have done testing, you can revert back to the original version by doing the same steps as described above.
16