I’m using iis and vscode to do php work. I recently updated iis from php7.3 to php7.4. My problem is that vscode is still using php7.3. I googled how to change the version in vscode and almost all the resources say that there’s a JSON file that can changed under php settings in File > preferences > settings. When I search for php I’m not seeing any of these options. What am I doing wrong?
Question posted in PHP Versions
You can find a list of all versions here.
You can find a list of all versions here.
4
Answers
You can set the value directly as seen in your screenshot. Entry is named PHP Version. If you do so for that particular workspace, a file will be created at
If you don’t see the folder .vscode in Explorer, you have to change the settings in Explorer to see hidden folders.
If you did set the PHP version on the page in your screenshot for that particular workspace then you should find in settings.json an entry that looks like the following
change that to
If you want to change the setting globally for all of your projects you can do the the following:
Open Explorer, or command line (cmd.exe) and type or copy the following line
Usually this will start vscode if not already running and open settings.json.
In that file at the beginning add after the opening bracket
Before you change these files manually, it might be a good idea to make a backup of these files.
While you can set the version for the intelephense addon, this won’t help much because it appears that this setting doesn’t apply to VSC itself. However you can set the
php.validate.executablePath
setting to the path to your php.exe file, for example"php.validate.executablePath": "C:/wamp64/bin/php/php7.4.9/php.exe"
. This should override a possibly wrong php path VSC takes from the system PATH env setting whenphp.validate.executablePath
is not set.Code -> Preferences -> Settings
Look for "php version". Then change it
Since the above answers did not solve my problem, I’d like to give an additional solution that handled my issue of having the right PHP version in VS code. I got to this problem during installation of Laravel and the terminal in VS code was giving me the error that my platform is using PHP 7.4 and Laravel 9 requires PHP 8.0.2. It just caused me a headache to figure out where VS Code is taking the info that my platform is using PHP 7.4 (however my WAMP server was using PHP 8.2) (and I also set in VS code settings, according to the above answers, the following:
But during creating a new Laravel project, VS code terminal still gave me the above error and did not recognize my PHP 8.2 version.
So my final working solution in Windows 11 (same in windows 10) was to setting the Path variable (to PHP executable) in Environment Variables.
1. in windows Start menu click and search for Environment Variables -> you can just open that control panel and click and open the Environment Variables settings:
2. You will get a new modal window and you have to click on Path in System variables like in the image below:
3. and you will find the PHP path and you have to just edit the path value to your own required PHP folder and then click OK. (I am not sure whether it is optional but I restarted my VS Code editor and everything was OK with PHP version from then on in VS Code regarding PHP version).
Some important warning on this
I’ve been using WAMP for a bit more than 10 years ago now as far as I remember, never had any problem with setting PHP path variable in windows, and only in the last few years WAMP raises a warning when you set a PATH variable to PHP executable in windows, since WAMP does not need that and also some developers considers that a bad practice, most importantly because it is a bit unnecessary and later on, it could cause some problems as well if we forget that setting in windows and we want to use another version of PHP. So the usual problems, it is not because of an ugly security reason in windows first of all, but because we as developers have very bad memories. It is just increasing our stupidity factor that can influence our life in the future. And there are more optimal solutions on this issue.
My suggestion is to check this subject a little more deeply as someone has a short time and you can read more details about how you can set PHP versions for VS Code. So my solution above is good, no problem with that as a short term solution, however keep this warning in mind too when you solve this issue and study this subject a little more here on SO.
Helpful links I have read on this too:
How To Run PHP From Windows Command Line in WAMPServer
And this one if you want to launch VS Code with different PHP versions, very helpful post:
Problems with php versions on xampp and vs code
And this one:
How To Run PHP From Windows Command Line in WAMPServer