0

One project needs an older PHP version 7.0.

I followed this guide from JetBrains to configure the PHP Interpreter, but even after restarting Apache, terminating the shell, restarting PhpStorm it didn't work.

enter image description here

So I decided to try it differently, so I followed this guide on how to run two PHP versions at the same time with XAMPP, I followed everything to the letter, but when typing php -v it still does not show the wanted PHP version.

Am I missing out on something?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Samuel Gfeller
  • 840
  • 9
  • 19
  • 2
    If you want the cli version, this has nothing to do with apache. – Nigel Ren Jun 24 '21 at 07:49
  • Okay, thank you but how do I change the cli version? – Samuel Gfeller Jun 24 '21 at 07:56
  • If you need another PHP version **for CLI only**... then download PHP from windows.php.net (since you are on Windows OS) and do a minimal needed configuration in php.ini. – LazyOne Jun 24 '21 at 07:58
  • If it **has to be the part of XAMPP** (so they both can use 2 diff PHP) .. then it's a diff question. **In any case:** the path to PHP executable should be different for different versions. Type `where php` to see the current path for `php` executable (e.g. when you run `php.exe artisan xx` command from Laravel or alike). The terminal (to be precise: Windows) looks for executable from folders from `PATH` environment variable. If you need to put your PHP version for CLI -- prepend such path there .. or use full path to the executable file. – LazyOne Jun 24 '21 at 08:03
  • Well it's a Symfony application that I need to run locally. I intended to use the Symfony local https://symfony.com/doc/current/setup/symfony_server.html, but that is to open in the browser, right? I need to update composer packages first, and I get the error that my PHP version is too recent, that's why I need a 7.0 CLI. I already downloaded PHP 7 for windows and tried to configure it in PhpStorm. I don't see the relation to "do a minimal needed configuration in php.ini" though. – Samuel Gfeller Jun 24 '21 at 08:05
  • BTW -- setting up different PHP Interpreter in PhpStorm and switching between them there will NOT affect the Terminal in any way. The PHP Interpreter in PhpStorm is used for: 1) to run/debug your PHP file using "PHP Script" type of configuration (a CLI environment); 2) to run PHP based tools (e.g. PHPUnit, CodeSniffer, Composer and alike); 3) by PhpStorm's built-in simple web server (limited one, not worth using when you have proper web server). – LazyOne Jun 24 '21 at 08:07
  • As you can see in the image, I typed `which php` and that gives me the same result as `where php` and that is not the path to the version I want. "switching between them there will NOT affect the Terminal in any way" oh alright that explains, I didnt know this. Now the question is: how can I change the php in the CLI for this specific project (that `where php` shows the path to php7) do I have to change something in the `PATH` variable? – Samuel Gfeller Jun 24 '21 at 08:10
  • Do you really need that to be for `php` command? Have you tried using the full path to the needed php.exe instead of just `php`? It may work. – LazyOne Jun 24 '21 at 08:13
  • If you need this then I may suggest this: 1) launch `cmd.exe`; 2) just type `PATH` there and execute it -- it will show the current paths used by OS to find executable files. 3) Add path to your PHP 7.0 version (`C:\xampp\php7`) in front -- e.g. `SET PATH=C:\xampp\php7\;%PATH%` -- something like that should work. *If I'm not mistaken this should work for the current session only (especially if cmd is not run as Admin)* – LazyOne Jun 24 '21 at 08:15
  • If you need to alter the `PATH` permanently -- do it via GUI I guess. You need to go into the System Properties for that, e.g. 1) press `Win + I` 2) Go to `System`, then `About`. 3) Scroll down to the end to "Related Settings" section -- choose `Advanced System Settings` there. 4) On that new old-style dialog, on "Advanced" tab, click on `Environment variables` button, find the `PATH` and edit it there. Once done you may need to restart apps/session as evn vars are part of process on Windows (have own copy when launched). – LazyOne Jun 24 '21 at 08:20
  • It was a really good idea to use the full path for this one command but there is exception after exception with composer. – Samuel Gfeller Jun 24 '21 at 08:29
  • In such case: see the previous 2 comments about changing the `PATH` variable. You can also try the following but I think it may not work as desired: place the symlink in the current folder (at least temporarily) -- `php.exe` and point it to the needed `C:\xampp\php7\php.exe`. May work .. but I think it most likely will fail to load php extensions/correct php config. – LazyOne Jun 24 '21 at 08:54
  • Exceptions were not related to this I think I posted an answer. Thank you so much @LazyOne genuinely, I appreciate your time. Means a lot to me. – Samuel Gfeller Jun 24 '21 at 09:43

1 Answers1

1

A thousand thanks to @LazyOne which gave me the solution.
As I only need PHP 7 to run composer update for one project, it is way simpler to use the full path instead of configuring the PATH env variable.
This worked for me:

  1. Install the right PHP version from here
  2. Extract the files in new folder (I called it php7)
  3. Copy php.ini-development to php.ini
  4. Open it and remove the ; before ; extension_dir = "ext" and ; extension=openssl
  5. Run the command with the full path
"C:\xampp\php7\php.exe" "C:\ProgramData\ComposerSetup\bin\composer.phar" update

Et voilà.

Unfortunately though, this didn't work out for me as I had many exceptions, but not really related to this question (Fatal error: Attempted to load class "Redis" from the global namespace) as the update command did start the update process.

Samuel Gfeller
  • 840
  • 9
  • 19