2

In a Symfony 3.4 project which I develop using PhpStorm I use the PhpStorm Terminal Window for running the Symfony server like

php bin/console server:run

This works fine. However the terminal uses the PHP version that is set in the windows environment path variable.

I don't get it to use the PHP version configured in the project setting (Settings -> Languages & Frameworks -> PHP) in the field CLI Interpreter.

Why is the terminal ignoring this setting totally?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
user3440145
  • 793
  • 10
  • 34
  • lol - thanks for the edit :D – user3440145 Dec 16 '18 at 21:33
  • 1
    PHP Interpreter is used by IDE only (when IDE is calling it directly -- e.g. executing/debugging PP script in CLI environment). PHP Interpreter does not influence your terminal environment. Your actual command gets executed with whatever you have got set there in your environment. So instead of just `php` you may specify the path to specific PHP executable. – LazyOne Dec 16 '18 at 21:33
  • ah OK - so I can specify the php excutable to be used by adding the path to the call? like [my_path_to_php]/php bin/console... ? – user3440145 Dec 16 '18 at 21:35
  • Another possible alternative (not sure how well it will work though) is to try executing your command via Command Line Tools (`Tools | Run Command`) -- it should use currently selected interpreter. Check more: https://www.jetbrains.com/help/phpstorm/command-line-tool-support.html – LazyOne Dec 16 '18 at 21:36
  • Thank you! I just tried to call the specific php version - that works! It's a bit much to write though. Will try your other suggestion too. If you write me an answere I will accept it gladly. – user3440145 Dec 16 '18 at 21:39
  • *"like [my_path_to_php]/php bin/console..."* Yes, that's what I meant. It's inconvenient ... therefore you may try setting up an alias for that (e.g. `php71` will be `/path/to/php/php71/php`) then your command may look like `php71 bin/console ...` – LazyOne Dec 16 '18 at 21:40
  • OK. Cool. I am not sure how to define an alias though... – user3440145 Dec 16 '18 at 21:41
  • For Linux/Mac that should not be a problem (just google "bash create alias" or alike). For Windows you may use batch script if you cannot find a way to create an alias... Symbolic links will do as well. – LazyOne Dec 16 '18 at 21:44

1 Answers1

1

You can configure the terminal for current project and set a custom PATH so php runs whatever interpreter you want. Open the Settings dialogue and head to Tools/ Terminal.

I think the neatest option is to tweak Shell path like this:

"cmd" /k "PATH=C:\php-5.6.0-Win32-VC11-x64;%PATH%"

Shell path

Terminal

You can also do the obvious thing and edit the environment variables to set PATH.

Environment variables

It works just fine but this variable totally overrides the parent PATH and I couldn't find a way to just prepend my value (neither $PATH nor %PATH% work).

Some other ideas:

  • Use "cmd" /k to load a custom configuration script.
  • Set PowerShell as shell and create aliases.
Álvaro González
  • 142,137
  • 41
  • 261
  • 360