mac monterey phpstorm can not run php_codesniffer
I am using macOS Monterey Version 12.0.1 and PhpStorm 2021.2.3 build #ps-212.5457.49
After upgrading to macOS Monterey I got the error
4:52 PM PHP CS Fixer
PHP CS Fixer: env: php: No such file or directory
Open PHP CS Fixer Inspection Settings
When I open the setting I checked the file is there and click the validate and it says Can not run PHP_CodeSniffer.
Please sign in to leave a comment.
With Wilecoyte78, we've checked the IDE logs and it turned out that PhpStorm cannot load the Zsh shell because their profile script is trying to use the SSH key and asks a passphrase for it, but the IDE doesn't handle such requests.
Here's an article describing how to work this around: https://youtrack.jetbrains.com/articles/IDEA-A-19/Shell-Environment-Loading
This doesn't happen in the PHPStorm terminal, it happens when I run Code > Inspect code, and in the inline file validation as well. Is there a workaround for that?
This is a pretty common scenario for any user of PHPStorm I'd imagine
Are you sure you're getting exactly the same error? Also, the workaround linked above applies to Code > Inspect Code launches.
I would suggest messaging us directly over Help | Contact Support to inspect what error exactly you're getting first & what's causing.
I was getting this same error "phpcs: env: php: No such file or directory" on Mac OS 12.0.1
I had used homebrew to install php.
>> where php
> /opt/homebrew/opt/php@7.4/bin/php
> /opt/homebrew/bin/php
For me the fix was to create a symlink in my /usr/local/bin directory to point to the homebrew php.
>> cd /usr/local/bin
>> ln -s /opt/homebrew/bin/php php
I have this problem and it hasn't worked for me to make that symlink.
I've looked at this issue which has been helpful in diagnosing: https://youtrack.jetbrains.com/issue/WI-57663#focus=Comments-27-4619847.0-0
It looks like PHPStorm (2022.1) is spawning commands with an environment that has the path /usr/bin:/bin:/usr/sbin:/sbin
But I can't put a symlink into /usr/bin or /bin
The issue linked above suggests that I might not be loading the shell environment. But I'm not getting the notification that this is not happening.
So I'm very confused. Dmitry Tronin can I get any further help with this issue?
Sure. You can message us via Help | Contact Support - that way you can share with us your logs or other sensitive data that you don't want to be on the internet.
We need to check your IDE logs for any error related to shell environment loading. You can find the log file (idea.log) via Help > Show log in ...
I have the same problem. It happens in the same way as Ross Wintle's. i've put the condition in the .zshrc file as suggested as a workaround (ref. https://youtrack.jetbrains.com/issue/WI-57663#focus=Comments-27-4619847.0-0), and it no longer complains "can't get shell environment", but phpcs is still not finding php. Is there anything else I can do to load iTerm2?
Do you have php installed in your system? Could you please share the phpprops.txt file generated?
HI Dmitry, here are a few facts on my machine (Monterey):
* Installed PHP 7.4 using brew
* Did these:
> brew link --force --overwrite php@7.4
> brew services start php@7.4
* put these 2 lines in my .zshrc file:
PATH="/usr/local/opt/php@7.4/bin:$PATH"
PATH="/usr/local/opt/php@7.4/sbin:$PATH"
* PHPStorm is using the above PHP as CLI Interpreter.
* There is no php in /usr/bin (as it is Mac OS Monterey)
> php -v
PHP 7.4.30 (cli) (built: Jun 9 2022 09:30:03) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies
> which php
/usr/local/opt/php@7.4/bin/php
> ls -l /usr/local/bin/php
lrwxr-xr-x 1 myusername admin 32 Jul 12 00:30 /usr/local/bin/php -> ../Cellar/php@7.4/7.4.30/bin/php
Would you please let me know how the phpprops.txt file is generated?
Thank you so much!
It's described right in a comment you've shared: https://youtrack.jetbrains.com/issue/WI-57663/Phpstorm-is-using-macOS-builtin-PHP-version-instead-of-brew-installed-one#focus=Comments-27-4619847.0-0
Perform the actions described there & you should get the file.
By the way, what problem exactly are you facing? Could you please attach a screenshot?
Hi Dmitry, here's the output in the phpprops.txt file:
("myname" is used in place of my real username.) Here are 2 screenshots showing the problem with phpcs on PHPStorm, with part of a path crossed out for privacy. There is no problem running phpcs from the command line.
Thanks. There could be some issues loading your env variables on IDE startup. Could you please restart PhpStorm and share your idea.log file (Help > Show log in ...)? You can upload it at https://uploads.jetbrains.com/ - only JetBrains staff can browse it.
I just uploaded the beginning part of idea.log. The rest has a lot of directory and file names related to my work for the company and it has to do with file-specific operations. Hopefully, the part I uploaded is enough for troubleshooting. Would you please let me know if anything else is needed? Thank you, Dmitry!
I see this discussion is ongoing.
What I learned was that this problem only happened when I started up PHPStorm in a particular way. Specifically, I had the RayCast application on my Mac with the Jetbrains Recent Projects extension. And when this starts up PHPStorm it doesn't seem to do so with the environment set.
Using any other method of opening PHPStorrm seems fine.
Interesting, Ross Wintle! I don't have RayCast on my machine, and simply launched PHPStorm from it's .app file. The problem came out only after my machine was upgraded to Monterey. It didn't happen on Big Sur.
cmou sorry, I need an upload ID as well to look into it.
Sorry, I lost that. Here's the upload again: Upload id: 2022_07_15_iD2Uc3Tr8jgowCmuABKvD8 (file: idea.log.beginning)
Unfortunately the log file is filled with HTTP requests. Could you please close IDE, find the idea.log file, delete it, launch IDE again and then upload & share the log file one more time?
Hi Dmitry, i just uploaded the new log file according to your instructions: Upload ID: 2022_07_21_tmW4QwiSWpFvyZep7ikLjP (file: idea.log). There are a few exceptions. So besides php, the original python has also been removed from the OS, and installing using brew, then aliasing it didn't help either, even though my zsh can find them.
Thank you so much!
Thanks.
So, you're using an older IDE version that still relies on python to load shell environment. It fails with "env: python: No such file or directory".
You can either install a newer IDE version, or try this workaround: https://youtrack.jetbrains.com/issue/IDEA-290713/IntelliJ-on-Monterey-no-longer-picks-up-environment-variables#focus=Comments-27-5901393.0-0
Thank you, Dmitry! Opening PhpStorm.app from the command line works for the 2021 version.
I've facing this problem with yesterdays upgrade to MacOS Monterey 12.5 and PhpStorm 2022.2.
Is there already solution for this problem in the pipeline or what should I do in case of facing this problem with a up-to-date MacOS and PhpStorm? The above mentioned comment states out, that this problem is fixed in version 2021.2 and later but unfortunately I cannot confirm this.
I uploaded this idea.log and got the following id: 2022_08_10_LRzCQTyFM8RH3Qjx1VyWUA
Thank you for your help!
Thanks for the log. Do you have php installed locally? Could you please run which php & share the output?
Yes, of course.
It is part of my MAMP application and available from MacOS terminal:
But insides PhpStorms terminal the following output appears:
The executable has been correctly added as CLI interpreter. The configuration file and the version gets correctly determined by PhpStorm as you can see in the following screenshot.
Just for a test - would it help if you launch IDE from a command line?
It is running fine after starting PhpStorm from the command line.
Here is an output from the "php -v" command using the built-in terminal implementation:
dennis@MacBook-Pro Entwicklung % php -v
PHP 7.2.34 (cli) (built: Sep 30 2021 12:59:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
dennis@MacBook-Pro Entwicklung %
Why does it work by launching the IDE from command line and not from the normal one?
Please see this explained here: https://youtrack.jetbrains.com/articles/IDEA-A-19/Shell-Environment-Loading
There's a chance that your environment isn't correctly loaded because of customizations inside your ~/.bashrc or ~/.zshrc files.The article described a workaround that could possibly help.
I did not make any customization in those files. Former I think, the cause of this issue is, that Apple has removed PHP from macOS Monterey and that has been used by PhpStorm before the upgrade, right?
Wouldn't it be better if the configured CLI interpreter is used for the execution of tools like CodeSniffer? I always thought that this is already the case, but I am fully wrong.
To be fair, it should since 2022.2: https://youtrack.jetbrains.com/issue/WI-59980.
1. Do you have local PHP Interpreter configured & selected at Preferences | PHP?
2. At Preferences | PHP | Quality Tools open PHP_CodeSniffer Configuration using "..." button. Then add a new configuration using "+" button & select your local PHP Interpreter:
Save it & check if that config works.
Hello Dmitry,
I missed the second of your steps. After the setup of a new configuration of the PHP_Codesniffer Quality Tool with the correct PHP Interpreter it works as expected.
Maybe you can add those necessary steps to the MacOS related documentation for the setup of PHP_Codesniffer and other tools that rely on PHP Interpreter? Anyone who upgrade to Monterey and previously use the (default defined) "System PHP" Interpreter faces this problem.
Thank you for your help. I really appreciate it!