johnnyBoy
johnnyBoy

Reputation: 125

Cannot change PHP default version in Symfony 4.12

I would like to create a Symfony project. I have the same issue as many people concerning php version: Symfony uses the wrong one.

λ php -version
PHP 7.4.1 (cli) (built: Dec 17 2019 19:24:02) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

λ symfony -V
Symfony CLI version v4.12.4 (Tue Jan 14 13:09:08 UTC 2020)

λ symfony check:requirements

Symfony Requirements Checker
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> PHP is using the following php.ini file:
C:\xampp\php\php.ini

> Checking Symfony requirements:

..............WWW......W..


 [OK]
 Your system is ready to run Symfony projects

I have Xampp installed but I use Laragon with 7.4.1 on Windows 10 and wish to use that one, but Symfony tells me this:

λ symfony local:php:list
┌─────────┬─────────────────────────────────────────────┬─────────┬─────────┬─────────────┬─────────┬─────────┐
│ Version │                  Directory                  │ PHP CLI │ PHP FPM │   PHP CGI   │ Server  │ System? │
├─────────┼─────────────────────────────────────────────┼─────────┼─────────┼─────────────┼─────────┼─────────┤
│ 7.3.10  │ C:\xampp\php                                │ php.exe │         │ php-cgi.exe │ PHP CGI │ *       │
│ 7.4.1   │ C:\laragon\bin\php\php-7.4.1-Win32-vc15-x64 │ php.exe │         │ php-cgi.exe │ PHP CGI │         │
└─────────┴─────────────────────────────────────────────┴─────────┴─────────┴─────────────┴─────────┴─────────┘

The current PHP version is selected from default version in $PATH

Even though there is no trace of Xampp or php 7.3.1 in my $PATH.

λ echo %path:;=&echo.%
C:\Program Files\cmder_mini\bin
C:\Program Files\cmder_mini\vendor\bin
C:\Program Files\cmder_mini\vendor\conemu-maximus5\ConEmu\Scripts
C:\Program Files\cmder_mini\vendor\conemu-maximus5
C:\Program Files\cmder_mini\vendor\conemu-maximus5\ConEmu
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Windows\System32\OpenSSH\
C:\Program Files\nodejs\
C:\Program Files\Git\cmd
C:\ProgramData\ComposerSetup\bin
C:\laragon\bin\php\php-7.4.1-Win32-vc15-x64\php.exe
C:\Program Files\Symfony
C:\laragon\bin
C:\laragon\bin\apache\httpd-2.4.35-win64-VC15\bin
C:\laragon\bin\composer
C:\laragon\bin\laragon\utils
C:\laragon\bin\mysql\mysql-5.7.24-winx64\bin
C:\laragon\bin\nginx\nginx-1.16.0
C:\laragon\bin\ngrok
C:\laragon\bin\notepad++
C:\laragon\bin\php\php-7.4.1-Win32-vc15-x64
C:\laragon\bin\putty
C:\laragon\bin\redis\redis-x64-3.2.100
C:\laragon\bin\telnet
C:\laragon\usr\bin
C:\Program Files\Sublime Text 3\
C:\Users\User\AppData\Local\Yarn\config\global\node_modules\.bin
C:\Users\User\AppData\Roaming\Composer\vendor\bin
C:\Users\User\AppData\Roaming\npm
C:\Ruby26-x64\bin
C:\Users\User\AppData\Local\Microsoft\WindowsApps
C:\Program Files\JetBrains\PhpStorm 2019.2.3\bin
C:\Program Files\JetBrains\DataGrip 2019.2.5\bin
C:\Program Files\Git\cmd
C:\Program Files\Git\mingw64\bin
C:\Program Files\Git\usr\bin
C:\Program Files\cmder_mini

(I checked user & system $PATH)

I tried to force Symfony into using 7.4.1 by running in a project directory:

λ echo "7.4.1" > .phpversion

When I run

λ symfony local:php:refresh

λ symfony local:php:list

I get:

λ WARNING the current dir requires PHP "7.4.1" (.php-version from current dir: C:\laragon\www\CMS_test\.php-version), but this version is not available

I also tried renaming the Xampp directory name, and as a matter of fact, that "works".

C:\
λ symfony check:requirements
php does not seem to be available under C:\xampp\php


C:\
λ symfony local:php:list
┌─────────┬─────────────────────────────────────────────┬─────────┬─────────┬─────────────┬─────────┬─────────┐
│ Version │                  Directory                  │ PHP CLI │ PHP FPM │   PHP CGI   │ Server  │ System? │
├─────────┼─────────────────────────────────────────────┼─────────┼─────────┼─────────────┼─────────┼─────────┤
│ 7.4.1   │ C:\laragon\bin\php\php-7.4.1-Win32-vc15-x64 │ php.exe │         │ php-cgi.exe │ PHP CGI │ *       │
└─────────┴─────────────────────────────────────────────┴─────────┴─────────┴─────────────┴─────────┴─────────┘

The current PHP version is selected from default version in $PATH

But that solution isn't really satisfying to me.

I've search StackOverflow for several hours, tried to re-install Symfony, restart the computer, ask friends etc no one seem to have another solution.

So, why does Symfony search for php in a Xampp directory ? Is it possible to choose another default one like Laragon's ? Any idea ?

Upvotes: 2

Views: 3855

Answers (2)

alessandroAmedei
alessandroAmedei

Reputation: 63

Just delete your .php-version file and create in manually from your ide! With the from encoding (using echo from terminal) the error message was

the current dir requires PHP ��7.4.10

you can see the encoding is wrong by the question marks. Creating the file from the ide fixed my problem!

Upvotes: 1

Enhardened
Enhardened

Reputation: 164

I just had this problem on my Windows environment. For some reason, symfony is not reading .php-version correctly when I create it using echo "7.2" > .php-version.

The problem was gone once I deleted and created a new text file from my IDE. Probably creating it using vscode code .php-version or using the File Explorer would work too (I didn't try it, yet).

Edit: I just tried creating the file with VS Code and Notepad - Both worked. But I still don't know why it doesn't work when creating with echo...

Edit2: I think I got it. Looks like PowerShell's echo "" > file will create the file with UTF-16 encoding. After converting the file to UTF-8 it worked as expected.

Upvotes: 6

Related Questions