Managing different PHP Versions while testing Laravel Modules.
Tags: laravel, php, versions, modules
Published: 2021-12-09 12:35:47

## Introduction

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;

### 1. Force composer installation to ignore PHP version requirements

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.

### 2. Temporarily change the PHP version to the version required

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

[https://sourceforge.net/p/xampp/activity/?page=0&limit=100#619f851aaa0ec74743cc7a56](https://sourceforge.net/p/xampp/activity/?page=0&limit=100#619f851aaa0ec74743cc7a56)

(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

![Different version of PHP downloaded and unzipped](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a1ta7hy91k3wk522ifvg.JPG)

As mentioned, each version only contains the Apache and PHP folders only. 

![We only need the Apache and PHP folders](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ow0ykfww9uagqv2z0rfu.JPG)

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.

![All services stopped](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3i00j3pzec07o5fbkq3o.JPG)

Next delete the Apache and PHP folder from the c:\xampp folder (or wherever your XAMPP installation files are).  

![Delete the current PHP and Apache folders](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lt1nv48xwalff7hpliwt.JPG)

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.