SublimeLinter: PHP linting not working - php

PHP linting is not working in SublimeLinter though it says PHP: loaded in the console. I'm working on Windows. Additionally, there are no options if I open the Command Palette except for Extract Annotations. Did anyone have the same problem and knows the solution?

Additionally, make sure you've given the path to php.exe in your user settings
-
(prefs>pkg settings>sublimelinter>settings - user)
should look like this (if your path is "C:\xampp\php\php.exe"):
{
"sublimelinter": true,
"sublimelinter_executable_map":
{ "php":"/xampp/php/php.exe" }
}

on MAC OS X in sublimeText 2 once you have installed sublimelint package
cmd+shift+p to open command palette then enter or select Preferences:SublimeLint - User
This will open the setting file
Paste this exactly:
{
"sublimelinter": true,
"sublimelinter_executable_map":
{
"php":"/usr/bin/php"
}
}
Save the file and restart sublime text 2. if you have an error such as it could not read the file, it's because you made a typo mistake. The setting file it must be a correctly formatted json.
if you have any problems do a which php in your terminal to be sure php is installed at /usr/bin/php and replace the path by what the which command gives you if it's different.

I just had the same issue. The cause for my problem was that all PHP files where opened with the HTML5 syntax. You can check the current syntax by pasting the following command in your SublimeText console:
sublime.active_window().active_view().settings().get('syntax')
To set php as a default for the current file type, you can go to: view > syntax > Open all current extensions as... > php
Hope this helps!

I had to use this in my user settings:
{
"sublimelinter": true,
"sublimelinter_executable_map":
{ "php": "C:\\Program Files (x86)\\PHP\\v5.3\\php.exe"
}
}

i sovle this problem by change setting (where are bold) ,then restart sublime and try this php code to see sublime linter error
<?php echo "hello linter" ?>
//not put semicolon
you see red dot on next line of php code
just change setting like below
"linters": {
"php": {
"#disable": false,
"args": [],
"excludes": []
},
"phpcs": {
"#disable": true,
"args": [],
"excludes": [],
"standard": "PSR2"
}
},
"mark_style": "solid underline",
"no_column_highlights_line": false,
"passive_warnings": true,
"paths": {
"linux": [],
"osx": [],
"windows": [
"put your php path or path of php.exe D:/wamp/bin/php/php5.4.3/"
]
},
this two must change
"php": {
"#disable": false,
"phpcs": {
"#disable": true,

For my Windows i had to go with this:
php.exe file path on Windows 7 didn't do the trick for me, while
php-win.exe did:
{
"sublimelinter_executable_map":
{
"php":"C:/php/php-win.exe"
}
}

Sometimes setting the php at the sublimlinter_executable_map does not work (for me). For me it just worked to add the path to the php.exe to the Windows System Environment Path Variable.

For windows I did this and it worked, use \\ and it should work!
{
"sublimelinter_executable_map":
{
"php":"C:\\Users\\Wasil\\Documents\\BitNami\\php\\php-win.exe"
}
}

Related

phpfmt php formatting extension eror: phpfmt: php_bin "php" is invalid

Recently I updated my VS code on my macOS. I'm now running vs code version 1.41.1.
Ever since the reinstall, the phpfmt extension is no longer working and giving me the
phpfmt: php_bin "php" is invalid`
pop up every time I save a file.
I tried removing VS code and installing it again. I removed the extension and reinstalled it as well yet I am still getting this error.
Is there any other settings i can clear. I can't find this error anywhere online.
Just add below code in setting.json in VS Code
"phpfmt.php_bin": "C:/xampp/php/php.exe"
in my case the location is in xampp so just add your php.exe location.
On Mac Os:
In the vscode settings (JSON view) extend the ^^ above option with the Mac Os PHP path:
"phpfmt.php_bin": "/usr/bin/php"
Cheers
assuming you have PHP installed:
Edit your vscode settings (JSON view) add this option:
"phpfmt.php_bin": "php"
If you want auto formatting on save:
All Languages:
"editor.formatOnSave": true
Just PHP:
"[php]": { "editor.formatOnSave": true }
you can always check out the plugin page too:
https://marketplace.visualstudio.com/items?itemName=kokororin.vscode-phpfmt
has this bits of info on this + further configuration
happy coding!
You have to find dir to file php.exe and then you can fig that easily by this way below:
"phpfmt.php_bin": "F:/Xampp/php/php.exe",
F:/Xampp/php/php.exe - my directory
"phpfmt.php_bin": "C:/xampp/php/php.exe"
open setting.json in VS code
You have to find your php.exe path and paste it after "phpfmt.php_bin": "php.exe path"

php runtime not found. install the php7 runtime and update "executablepath" in php

I'm running ubuntu 18.04 and trying to develop a php project using Brackets text editor. But i getting error:
PHP runtime not found.
Then I installed the php7 runtime and update "executablePath" in PHP preferences appropriately. I tried to configured Brackets using custom setting in brackets.json But now i am getting:
"Error Reading Preferences" Your preferences is not valid JSON
I am using XAMPP
Based on the issue that appear in here :
https://github.com/adobe/brackets/issues/14783
you just have to open your brackets.json file from the Debug tab then open preferences file,
and add these following syntax to your brackets.json :
"php": {
"executablePath": "C:\\xampp\\php\\php.exe"
}
so for me, it will became like this :
{
"brackets-eslint.gutterMarks": true,
"brackets-eslint.useLocalESLint": false,
"fonts.fontSize": "12px",
"fonts.fontFamily": "'SourceCodePro-Medium', MS ゴシック, 'MS Gothic', monospace",
"themes.theme": "dark-theme",
"php": {
"executablePath": "C:\\xampp\\php\\php.exe"
}
}
then restart your brackets, hope it'll work

Symfony 4.x public dir rename to public_html

I got a little struggle with renaming dir to public_html for web host.
According to latest tutorial I'm trying to successfully rename it, but every time when i'm trying to run local server using console command I'm getting an error:
[ERROR] The document root directory ".../.../App/public" does not exist.
I'm sure that I'm doing something wrong with code. But I don't know where. I'm very beginner with Symfony.
Here's my code from composer.json:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
}
"public-dir": "public_html"
},
Did I understood something wrong with it?
Thanks for help.
If the code snippet represents exactly what you have in your composer.json then I have noticed that it is not correctly formatted json file. In the "extra", after the value of "symfony" key, you need to put a separator "," then in the next line you may add more key:value pairs. AS in:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
},
"public-dir": "new_public_html_dirname"
}
A not well formatted json file will prevent it from being executed. I hope it helps.
It is important to run composer update.
composer update
As the index.php file is the first file being run (by the webserver) you should just be able to rename the public directory to public_html and it will work, and not need to change anything in the composer.json (though how that would affect the framework code, without at least running any composer-scripts, I do not know).
I've just created a new Symfony 4.2.3 project, and done nothing more than renaming the directory, and running (most) bin/console commands are not affected.
The in-built server will have issues, but you can tell it which directory to use as the docroot with:
mv public public_html
bin/console server:start --docroot=public_html/
[OK] Server listening on http://127.0.0.1:8000
The changes to composer.json are not required.

Sublime XDebug , PHP

I installed XDebug client using the package control in sublime text 3.
I have XAMPP installed on my MAC. My Document Root in the /xamppfiles/etc/httpd.conf points to the actual PHP project root directory e.g. DocumentRoot "/Users/johndoe/myproj". I saved the project and put the following as well:
{
"folders":
[
{
"path": "."
}
],
"settings":
{
"xdebug":
{
"debug": true,
"url": "127.0.0.1/app/index.html#/home"
}
}
}
However I do not see the debug working. (a) I am unable to pull a browser when I do a Tools->XDebug->Start Debugging (Launch Browser).
Can anyone please let me know what I am doing wrong ? Please suggest given the current Document Root Set as mentioned above

How to run or debug php on Visual Studio Code (VSCode)

I can't find a way to run or debug php on Visual studio code, Does anyone know how?
Debugging PHP with VSCode using the vscode-php-debug extension
VSCode can now support debugging PHP projects through the marketplace extension vscode-php-debug.
This extension uses XDebug in the background, and allows you to use breakpoints, watches, stack traces and the like:
Installation is straightforward from within VSCode: Summon the command line with F1 and then type ext install php-debug
As far as I read about it today, you can't debug anything else than node.js, JavaScript and TypeScript at the moment, but they said they want to add new languages which you can debug. The editor is still in development. Nevertheless, I don't think there will be a php debugger in the future since php is serverside, so you can't debug it on your client alone.
If you want to debug php, I can recommend xDebug.
Updated:
Now, it is possible to debug with VS code. You need to install XDebug and php-debug extension for VScode.
There is a much easier way to run PHP, no configuration needed:
Install the Code Runner Extension
Open the PHP code file in Text Editor
use shortcut Ctrl+Alt+N
or press F1 and then select/type Run Code,
or right click the Text Editor and then click Run Code in editor context menu
or click Run Code button in editor title menu
or click Run Code button in context menu of file explorer
Besides, you could select part of the PHP code and run the code snippet. Very convenient!
There is now a handy guide for configuring PHP debugging in Visual Studio Code at http://blogs.msdn.com/b/nicktrog/archive/2016/02/11/configuring-visual-studio-code-for-php-development.aspx
From the link, the steps are:
Download and install Visual Studio Code
Configure PHP linting in user settings
Download and install the PHP Debug extension from the Visual Studio Marketplace
Configure the PHP Debug extension for XDebug
Note there are specific details in the linked article, including the PHP values for your VS Code user config, and so on.
If you don't want to install xDebug or other extensions and just want to run a PHP file without debugging, you can accomplish this using build tasks.
Using Build Tasks (No extensions required)
First open the command palette (Ctrl+Shift+P in Windows, ⌘+Shift+P in Mac), and select "Tasks:Open User Tasks". Now copy my configuration below into your tasks.json file. This creates user-level tasks which can be used any time and in any workspace.
{
"version": "2.0.0",
"tasks": [
{
"label": "Start Server",
"type": "shell",
"command": "php -S localhost:8080 -t ${fileDirname}",
"isBackground": true,
"group": "build",
"problemMatcher": []
},
{
"label": "Run In Browser",
"type": "shell",
"command": "open http://localhost:8080/${fileBasename}",
"windows": {
"command": "explorer 'http://localhost:8080/${fileBasename}'"
},
"group": "build",
"problemMatcher": []
},
{
"label": "Run In Terminal",
"type": "shell",
"command": "php ${file}",
"group": "none",
"problemMatcher": []
}
]
}
If you want to run your php file in the terminal, open the command palette and select "Tasks: Run Task" followed by "Run In Terminal".
If you want to run your code on a webserver which serves a response to a web browser, open the command palette and select "Tasks: Run Task" followed by "Start Server" to run PHP's built-in server, then "Run In Browser" to run the currently open file from your browser.
Note that if you already have a webserver running, you can remove the Start Server task and update the localhost:8080 part to point to whatever URL you are using.
Using PHP Debug
Note: This section was in my original answer. I originally thought that it works without PHP Debug but it looks like PHP Debug actually exposes the php type in the launch configuration. There is no reason to use it over the build task method described above. I'm keeping it here in case it is useful.
Copy the following configuration into your user settings:
{
"launch": {
"version": "0.2.0",
"configurations": [
{
"type": "php",
"request": "launch",
"name": "Run using PHP executable",
"program": "${file}",
"runtimeExecutable": "/usr/bin/php"
}
]
}
// all your other user settings...
}
This creates a global launch configuration that you can use on any PHP file. Note the runtimeExecutable option. You will need to update this with the path to the PHP executable on your machine. After you copy the configuration above, whenever you have a PHP file open, you can press the F5 key to run the PHP code and have the output displayed in the vscode terminal.
already their is enough help full answers but if you want to see the process then
[ click here ]
Steps in Short
download php debug plugin [ https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug ]
download xDebug.dll [ https://xdebug.org/wizard.php ]
move xdebug file to [ ?? / php / ext / here ]
update php.ini file with following lines :
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
zend_extension=path/to/xdebug
[ good to go ]
make sure that you have restarted your local server
source : https://www.youtube.com/watch?v=8MLEB1qx984
It's worth noting that you must open project folder in Visual Studio Code for the debugger to work. I lost few hours to make it work while having only individual file opened in the editor.
Issue explained here
If you are using Ubuntu 16.04 and php7 you can install xdebug with below command:
sudo apt-get install php-xdebug
You can find the full configuration process here.
If you are using windows, you can download xdebug from xdebug.org.
And start debugging in VS-code with php-debug extension.
To debug php with vscode,you need these things:
vscode with php debuge plugin(XDebug) installed;
php with XDebug.so/XDebug.dll downloaded and configured;
a web server,such as apache/nginx or just nothing(use the php built-in server)
you can gently walk through step 1 and 2,by following the vscode official guide.It is fully recommended to use XDebug installation wizard to verify your XDebug configuration.
If you want to debug without a standalone web server,the php built-in maybe a choice.Start the built-in server by php -S localhost:port -t path/to/your/project command,setting your project dir as document root.You can refer to this post for more details.
XDebug changed some configuration settings.
Old settings:
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9000
New settings:
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9000
So you should paste the latter in php.ini file.
More info: XDebug Changed Configuration Settings
The best solution for me was to add a key binding to run PHP code directly in the terminal
To do so you just need to download terminal-command-keys from VS code extensions marketplace:
Then got to File>Preferences>Keyboard Shortcuts and click on the following icon at the upper right corner:
It will open up the keybindings.json file
Add the following settings
[
{
"key": "ctrl+s",
"command":"terminalCommandKeys.run",
"when": "editorLangId == php",
"args": {
"cmd":"php ${file}",
"newTerminal":true,
"saveAllfiles": true,
"showTerminal": true,
}
}
]
key is the shortcut to run your PHP file (I use ctrl+s) you can change it as you wish
when to run different commands for different file types (I set it for PHP files only) vscode's "when" clauses
See the full settings documentation from here
That's it, I hope it helps.

Categories