Php validate executablepath vscode linux

VsCode php.validate.executablePath, after insalled XAMPP

i’m trying to set the certain path for the php extension in my vscode (using linux) i started installing the XAMPP and after it..i tried to use the extension writing some php scripts(php extension INTELLISENSE and DEBUG), but the extension is not working properly and it’s showing that error: Cannot validate since /usr/bin/php is not a valid php executable. Use the setting ‘php.validate.executablePath’ to configure the PHP executable. i tried to set it using que path which is provided by vscode documentation, but it’s still no working. Can anyone help me !! please.

6 Answers 6

Php path in windows

And it’ll gives the path as (in my case)

I found a solution, typing in terminal

that returns the absolute path for set it in the vscode extension

Then, setting the path in the follow line

php.validate.executablePath: "/opt/lampp/bin/php", 

So, I hope this solution is helping someone behind the screen.

Just extending the answer by @Reinaldo Duguet with a ton of thanks to him !

If you are using Xampp, the PHP path can be found by running the local server and then typing localhost in the browser. This will open the Xampp dashboard. Click on phpinfo() and there you will get the exact path shown as Configuration File (php.ini) Path = /opt/lampp/etc

Please note that the path may very as per the PHP installation in your system. So you may have to use the respective path shown with above ways.

Then, to let VSCode know this path, open settings in VSCode and search for «PHP debug» and click on the PHP > Debug:Executable Path setting

Add the following line at the first place after «

Источник

PHP in Visual Studio Code

Visual Studio Code is a great editor for PHP development. You get features like syntax highlighting and bracket matching, IntelliSense (code completion), and snippets out of the box and you can add more functionality through community-created VS Code extensions.

Читайте также:  Can bus driver linux

Linting

VS Code uses the official PHP linter ( php -l ) for PHP language diagnostics. This allows VS Code to stay current with PHP linter improvements.

Tip: Using XAMPP? Install the full version of PHP in order to obtain the development libraries.

There are three settings to control the PHP linter:

  • php.validate.enable : controls whether to enable PHP linting at all. Enabled by default.
  • php.validate.executablePath : points to the PHP executable on disk. Set this if the PHP executable is not on the system path.
  • php.validate.run : controls whether the validation is triggered on save (value: «onSave» ) or on type (value: «onType» ). Default is on save.

To change the PHP settings, open your User or Workspace Settings ( ⌘, (Windows, Linux Ctrl+, ) ) and type ‘php’ to filter the list of available settings.

show PHP settings

To set the PHP executable path, select the Edit in settings.json link under PHP > Validate: Executable Path, which will open your user settings.json file. Add the php.validate.executablePath setting with the path to your PHP installation:

Windows

 "php.validate.executablePath": "c:/php/php.exe" > 

Linux and macOS

 "php.validate.executablePath": "/usr/bin/php" > or  "php.validate.executablePath": "/usr/local/bin/php" > 

Snippets

Visual Studio Code includes a set of common snippets for PHP. To access these, hit ⌃Space (Windows, Linux Ctrl+Space ) to get a context-specific list.

PHP Snippets

PHP extensions

There are many PHP language extensions available on the VS Code Marketplace and more are being created. You can search for PHP extensions from within VS Code in the Extensions view ( ⇧⌘X (Windows, Linux Ctrl+Shift+X ) ) then filter the extensions dropdown list by typing ‘php’.

Searching for PHP in the Extensions view

Disable built-in PHP support

To disable the built-in PHP smart completions in favor of suggestions from an installed PHP extension, uncheck PHP > Suggest: Basic, which sets php.suggest.basic to false in your settings.json file.

Debugging

PHP debugging with XDebug is supported through a PHP Debug extension. Follow the extension’s instructions for configuring XDebug to work with VS Code.

Next steps

Read on to find out about:

Источник

Fix ‘Cannot Validate Since No PHP Executable Is Set’ in VS Code

In the beginning, I’ve used Brackets, which is simple and beginner-friendly but doesn’t have the extra useful features that Visual Studio Code has.

Also, Brackets is used more for web design and front-end development.

Anyway, I installed VS Code, and the first thing I bumped into is this error:

Cannot validate since no PHP executable is set. Use the setting ‘.php.validate.executablePath’ to configure the PHP executable.

php validate error vs code

If you don’t set the path to the PHP executable, Visual Studio Code will still work fine, but it won’t validate the PHP code, meaning that you won’t get curly red lines whenever you have an error in your code.

After some digging around, I’ve found the solution, and I’ll share it with you ladies and gentlemen because it’s pretty hard to find comprehensive guidance in their documentation or on forums.

VS Code is not for beginners, so they won’t spoon-feed anyone, unfortunately. 😃

Fix the Validate PHP Error in Visual Studio Code for Windows, macOS or Linux

Note that I’m a Windows (10, to be more specific) user, so I’m not familiar with Linux or macOS. Therefore, I might not be so accurate when it comes to those operating systems.

Here’s what you need to do:

Step 1

You need to find out where your PHP executable (php.exe) is.

That depends on what OS and development environment you use (XAMPP, WAMP, custom installation, and so on).

I’m currently using XAMPP, which is installed on my C: drive on Windows 10, therefore the php.exe file is found in C:/xampp/php/php.exe .

For macOS or Linux users, the usual path is /usr/bin/php .

Step 2

Once you’ve found out where your PHP executable is, open Visual Studio Code and go to File > Preferences > Settings.

Step 3

In the Search Settings bar, type settings.json.

Then, click on the Edit in settings.json link.

Step 4

Add a comma after the last line of code, whatever it might be, then add this:

or this for macOS and Linux users:

Of course, your path to the php.exe file can be different, as I mentioned at step 1, so make sure you replace C:/xampp/php/php.exe with your correct path.

Don’t add a comma after it if it will be the last line of code!

Step 5

Save the file by going to File > Save or pressing CTRL+S (for Windows).

I think it’s CMD+S for macOS.

Step 6

Close Visual Studio Code and open it again for the warning to go away.

Step 7 — For Windows users

Make sure you have PHP added to your environment’s PATH. I think XAMPP adds it automatically but check anyway.

Search for “environment” on Windows.

In the Advanced tab, click on Environment Variables…

Click on the Path row to select it, then click on Edit…

Edit or add a new PHP path (e.g. C:\\XAMPP\\php ).

Don’t add the executable file (.exe) as you did in the .json file. Only add the directory.

If using a Virtual Machine on Windows

For example, for Laravel development, I’m using the Homestead environment on Windows 10, which is using Ubuntu as a server. It also comes with prepackaged software, such as PHP.

If I want to found out where PHP is on the server, I use the which php command, which will point out that PHP is found in /usr/bin/php .

Now, if I use that path in VS Code, it won’t work because it’s not on my disk. VS Code can’t look into my server.

So, if you’re running something similar for your dev environment, you’ll need to install PHP locally, on your disk, and then set the path as I showed you above.

I don’t know if there’s a workaround. If you do, let me know in the comments.

Other things to try if it doesn’t work

Some people said that it only worked for them when they added two forward slashes for the path in the settings.json file, like this:

For some people, it worked with backslashes (one or two):
Adding this in addition to the php.validate.executablePath line might also fix it:

I hope you found this guide useful and you fixed the PHP validation error in Visual Studio Code!

If some info is outdated or incorrect, or you have anything to add, say or ask, please contact me via Twitter or email.

About Radu

I’ve been working online, from home, for over 9 years. I learned a lot of different stuff related to websites. My main expertise is WordPress, but for some time, I started focusing more on web development.

Источник

Setting PHP Executable Path in VS Code in Ubuntu

Getting Unexpected ‘Unknown’ , ‘;’ expected. , ‘VariableName’ expected. error.

These kind of lines are causing error

namespace App\Http\Controllers; //Unexpected 'Unknown' and ';' expected Error use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Auth; 

Here, Screenshot of my error:

enter image description here

I’ve have added PHP executable path VS Code article. But still not working

php: /usr/bin/php8.0 /usr/bin/php.default /usr/bin/php /usr/lib/php /etc/php /usr/share/php8.0-mysql /usr/share/php8.0-readline /usr/share/php8.0-common /usr/share/php8.0-zip /usr/share/php8.0-xml /usr/share/php8.0-bz2 /usr/share/php /usr/share/php7.1-common /usr/share/php8.0-opcache /usr/share/php8.0-mbstring /usr/share/php8.0-gd /usr/share/php7.1-mcrypt /usr/share/php8.0-curl /opt/lampp/bin/php /usr/share/man/man1/php.1.gz 

Giving me following message

Cannot validate since usr\bin\php is not a valid php executable. Use the setting ‘php.validate.executablePath’ to configure the PHP executable.

1 Answer 1

I resolved with this executable path to configure the PHP executable in VS Code:

  < "php.validate.executablePath": "/usr/bin/php8.1" >whereis php php: /usr/bin/php /usr/bin/php8.1 /usr/lib/php /etc/php /usr/share/php /usr/share/php8.1-bcmath /usr/share/php8.1-xml /usr/share /php8.1-readline /usr/share/php8.1-zip /usr/share/php8.1-mysql /usr/share /php8.1-ldap /usr/share/php8.1-mbstring /usr/share/php8.1-common /usr/share /php8.1-intl /usr/share/php8.1-bz2 /usr/share/php8.1-gd /usr/share/php8.1- pgsql /usr/share/php8.1-curl /usr/share/php8.1-soap /usr/share/php8.1-opcache /usr/share/man/man1/php.1.gz 

Источник

Оцените статью
Adblock
detector