首页 > 解决方案 > 在 Ubuntu 的 VS Code 中设置 PHP 可执行路径

问题描述

版本:


错误:

得到Unexpected 'Unknown', ';' expected.,'VariableName' expected.错误。

这些行导致错误

namespace App\Http\Controllers; //Unexpected 'Unknown' and ';' expected Error

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

在这里,我的错误截图:

在此处输入图像描述


试过了

我已经添加了 PHP 可执行路径VS Code 文章。但仍然无法正常工作

settings.json

{
    "php.validate.executablePath": "/usr/bin/php"
}

$ whereis php

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

$ which php

/usr/bin/php

添加反斜杠

settings.json

{
    "php.validate.executablePath": "usr\\bin\\php"
}

给我以下消息

无法验证,因为 usr\bin\php 不是有效的 php 可执行文件。使用设置 'php.validate.executablePath' 来配置 PHP 可执行文件。


谢谢。

标签: phplaravelubuntuvisual-studio-code

解决方案


我用这个可执行路径解决了在 VS Code 中配置 PHP 可执行文件:

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

推荐阅读