Error while running a php code in vs code

Error image

An error show's that the php executable not found and add it to your path


Solution 1:

Step 1: First, we have to download PHP from it’s official website. We have to download the .zip file from the respective section depending upon on our system architecture(x86 or x64).

Step 2: Extract the .zip file to your preferred location. It is recommended to choose the Boot Drive(C Drive) inside a folder named PHP (ie. C:\php).

Step 3: Now we have to add the folder (C:\php) to the Environment Variable Path so that it becomes accessible from the command line. To do so, we have to right-click on the My Computer or This PC icon, then choose Properties from the context menu. Then click the Advanced system settings link, and then click Environment Variables. In the section System Variables, we have to find the PATH environment variable and then select and edit it. If the PATH environment variable does not exist, we have to click New. In the Edit System Variable (or New System Variable) window, we have to specify the value of the PATH environment variable (C:\php or the location of our extracted PHP files). After that, we have to click OK and close all remaining windows by clicking OK.enter image description here

Solution 2:

you didn't set php as a local variable to use it in CLI, so:

  1. Click the Advanced system settings link.
  2. Click Environment Variables. ...
  3. Duble click on PATH
  4. click new and write your PHP path (EX: C:\wamp\bin\php\php8.0.11)