Ryan C
Ryan C

Reputation: 97

PHP not found in VS Code

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

Upvotes: 7

Views: 86512

Answers (13)

moritz.vieli
moritz.vieli

Reputation: 1807

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

Upvotes: 0

khalilonline99
khalilonline99

Reputation: 121

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

Upvotes: 12

Paula Hill
Paula Hill

Reputation: 11

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"

Upvotes: 0

Jaregui
Jaregui

Reputation: 11

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.

Upvotes: 1

Anish Prasai
Anish Prasai

Reputation: 1

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.

Upvotes: 0

alexstokin420
alexstokin420

Reputation: 1

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!

Upvotes: 0

Nafiur Rahman
Nafiur Rahman

Reputation: 46

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.

Upvotes: 0

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.

Upvotes: 2

Meher Ullah Khan Raj
Meher Ullah Khan Raj

Reputation: 449

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.

Upvotes: 9

inquisitive
inquisitive

Reputation: 21

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

Upvotes: 0

Meghanad Kheti
Meghanad Kheti

Reputation: 1

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",
}

Upvotes: 0

Álvaro González
Álvaro González

Reputation: 146330

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.

Upvotes: 2

Omar Tarek
Omar Tarek

Reputation: 28

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"
}

Upvotes: 0

Related Questions