PHP not found in VS Code
Asked Answered
P

13

6

I'm trying to learn PHP and am encountering some issues early on. When I setup my basic file, then select PHP serve project, I receive a message at the bottom right of the screen saying PHP not found. I've setup my settings for the default xampp php file folder location with the command: "php.validate.executablePath": "c:\xampp\php\php.exe",

Pics are attached. Any help would be really appreciated.

JSON Settings

Basic PHP File

Pintsize answered 5/4, 2021 at 10:30 Comment(5)
For me the settings is called "php.executablePath"Cullan
That doesn't seem to be a builtin command. What extension(s) are you using?Unprintable
Does this answer your question? PHP executable not found. Install PHP 7 and add it to your PATH or set the php.executablePath settingXerophagy
I'm using: PHP Intelephense and PHP Server extensionsPintsize
Having the same problem. All my settings are correct and in line with the suggestions on this page, but still the problem persists. Anyone have an answer?Anatolio
S
10

Go to the PHP Server extension setting. There you have to add the path for:

PHP Config Path: C:\xampp\php\php.ini

PHP Path: C:\xampp\php\php.exe

[Make sure to add your installed folder, if you have installed xampp in another drive, you need to give that specific location.]

My settings:

My settings screenshot here

Silva answered 4/5, 2023 at 5:15 Comment(1)
This should be the top post as it actually answers OP's question.Airlike
E
9

Go to File->Preferences->settings->User settings tab->extensions->from the drop down select php->on the right pane under PHP › Validate: Executable Path select edit in settings.json.

Then set the path as your case may be for a XAMPP user who installed XAMPP on c drive you will have:

"php.validate.executablePath": "c:\\xampp\\php\\php.exe"

If PHP is installed in your system independently or by other means simply set the path of your php.exe file like below:

"php.validate.executablePath": "C://path.to.your.php.folder//php.exe"

Found this solution from php not found visual studio.

Etherege answered 26/1, 2022 at 8:42 Comment(2)
OP is using PHP Intelephense. As per the extension instructions, you need to disable builtin PHP support, so you shouldn't even have the php.validate.executablePath directive.Unprintable
@ÁlvaroGonzález +1, this genuinely confused me for like 5 minutes. I updated the .json file directly and there was no change, it's only after reading this comment I found that I couldn't find the "php.validate.executablePath" when I searched.Airlike
B
2

The PHP Server: Serve project command is not builtin. As the prefix suggests, it's provided by the PHP Server third-party extension. The setting you changed doesn't have anything to do with this feature.

You can find documentation on the extension settings on its Marketplace page, which can also be accessed right from the extension pane within Visual Studio Code.

  • Setting: phpserver.phpPath
  • Default: null
  • Notes: Path to PHP executable. If empty, the extension will try to get the path from the $PATH environment variable.
Banville answered 5/4, 2021 at 14:24 Comment(0)
S
2

I am maybe late but the above solutions didn't work for me. My solution was I went to File > Settings > enter php into the search field > enable Suggest and Validate and after just scroll down, let's find the the config path and the php path fields and enter your path.

  • PHP Config Path C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64
  • PHP Path C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64\php.exe

and that's worked for me. I hope I can help you.

Scrummage answered 15/12, 2022 at 8:39 Comment(0)
W
1

If editing the settings.json file didn't work for you, consider adding the php path into the "advanced system settings" of your windows device (hit Windows + R, then type sysdm.cpl) Once there, go to Environment Variables and click on path, then edit. Within the path section, click on new and paste the path to your php folder (not to the .exe file), then hit okay.

Whether answered 5/4, 2023 at 11:59 Comment(1)
This line is very important!! "not to the .exe file"Goldsworthy
G
0

In VSCode go to File -> Preferences -> Settings

Then add this code

{
"php.validate.executablePath": "C:\\xampp\\php\\php.exe",
"php.executablePath": "C:\\xampp\\php\\php.exe"
}
Gesticulation answered 5/4, 2021 at 10:38 Comment(3)
Thanks, but now the "php.executablePath" line is greyed out and an Unknown Configuration Setting message shows when I hover above the linePintsize
@RyanC sometimes this line: {"php.validate.executablePath": "C:\\xampp\\php\\php.exe"} is enough. So you can leave or remove the greyed out line as long as everything worksGesticulation
You can also check the official docs for that hereGesticulation
C
0

I also run into the same problem just now. This answer is for newer people who will came for the solution:

Put these two lines in your json settings

{
"php.validate.executablePath": "C:\\xampp\\php\\php.exe",
"php.debug.executablePath": "C:\\xampp\\php\\php.exe",
}
Cocks answered 26/1, 2022 at 8:36 Comment(0)
B
0

Well, above didn't work for me. I had to add environment variable for php path. My system - Win10 64bit, VScode v. 1.64.2

Bracelet answered 16/6, 2022 at 13:2 Comment(1)
Please add some information for future reference: Which variable did you have to add? What's its value / how to determine it?Cryptogenic
S
0

I had to add environment variables to my windows 11 as well.

Environment variable is simply the path. For instance,

D:\Backend\Xampp\php

Then type environment variables and select 'Edit the system environment variables. Look for Environment Variables > click path (Top) > Edit (from the top) > New and paste the path of wherever you installed your Xampp. Make sure to point to the php folder.

Sanitary answered 3/2, 2023 at 13:27 Comment(0)
C
0

I am working on a school computer and found a way to fix all of these problems for myself!

So when installing the "PHP Server" extension, you want to have PHP installed. After that is done you find the path to the PHP binary and add it to the executable path in the extension settings. I personally installed PHP to my USB drive since these computers always reset.

Hope this helps!

Charcuterie answered 28/2, 2023 at 9:30 Comment(0)
S
0

I'm on a windows machine, so I added the following key-value pair to the json file:

"php.validate.executablePath": "C://wamp64/bin/mysql/mysql5.7.36/bin/mysql.exe"
Sortition answered 3/4, 2023 at 14:59 Comment(0)
V
0

Probably late but leaving this here for the people who may encounter this in future,

If Nothing mentioned above is working for you then go to the PHP Server extension setting on marketplace and change the default null value of Phpserver: PHP Path to c:\xampp\php\php.exe or whatever path your php.exe is in. Hope that helps.

Vicechancellor answered 5/4, 2023 at 6:22 Comment(0)
S
0

On a Mac it's enough to install PHP with brew. Run this command in a terminal:

brew install php

Right click your file in VSC afterwards -> Reload server

Seriema answered 3/10, 2024 at 5:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.