Sublime XDebug , PHP - 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

Related

Xdebug starts the connection and than closes automatically

I am using Visual Studio Code and Xdebug is by default installed in it with version v3.x.x.
Sharing configuration below,
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9001,
"stopOnEntry":true,
"log": true,
"hostname": "localhost",
"pathMappings": {
"/var/www/html": "${workspaceRoot}",
"/app": "${workspaceRoot}/app"
}
}
]
}
php.ini,
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=1
test.php
<?php
echo "<script>alert('Welcome');</script>";
phpinfo();
?>
Now when I start the debugger at port 9001 on my local host (note no remote hosting is there). And on accessing it via, http://localhost:9001/test.php
It gives following comments on Debug console,
new connection 1
new connection 2
It gets started, but for some strange reason gives me, two new connection and they are printed only after I have access it via browser.
Now I wait for 5-10 seconds (meanwhile, browser keep loading, but nothing is visible and its still attempting to access test.php) I have placed Debugger point on all lines.
And suddenly after 10 seconds, its closes connection with below comments,
<- outputEvent
OutputEvent {
seq: 0,
type: 'event',
event: 'output',
body: { category: 'console', output: 'connection 2 closed\n' }
}
connection 2 closed
<- continuedEvent
ContinuedEvent {
seq: 0,
type: 'event',
event: 'continued',
body: { threadId: 2, allThreadsContinued: false }
}
<- threadEvent
ThreadEvent {
seq: 0,
type: 'event',
event: 'thread',
body: { reason: 'exited', threadId: 2 }
}
<- outputEvent
OutputEvent {
seq: 0,
type: 'event',
event: 'output',
body: { category: 'stderr', output: 'connection closed\n' }
}
**connection closed**
I have checked everywhere, but unable to to find answer to my problem. Request for help
Finally I was able to start Xdebug with Visual Studio code on XAMPP server. I am sharing my solution so that others don't face similar issues.
Install XAMPP on Ubuntu
Configure it to route it to code outside htdocs folder
Follow this link, https://askubuntu.com/questions/64095/change-xampps-htdocs-web-root-folder-to-another-one
Create index.php file and run,
phpinfo();
open browser and execute localhost/index.php
Copy the text to https://xdebug.org/wizard
The resultant will be a page with list of instrcutions, just follow them one by one and make sure Xdebug is successfully installed on Ubuntu
Now the important piece, open file /opt/lampp/etc/php.ini (I was trying to configure my local Laravel php.ini in my code, that's where its failing to recognize)
and paste following commands,
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.client_host = localhost
zend_extension = "/opt/lampp/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so"
Now go Visual Studio Code and open apply debugger points on your index.php
If running and debugging is not yet configured (no launch.json has been created), VS Code will show that and you can configure it by Running. Leave launch.json settings default.
Go to Run --> Start Debugging -> "Listen for Xdebug" and configure same for PHP for first time.
That's it !

Configuring Xdebug (PHP) path_mapping and php.ini for Sublime3

I'm trying to configure Xdebug to work with Sublime Text 3 but I can't get anything to show in the Context, Watch or Stack tabs e.g. by setting a breakpoint and clicking Start Debugging (Launch Browser). The browser opens the index.php file with ?XDEBUG_SESSION_START=sublime.xdebug appended to the url but execution of the code does not stop when the breakpoint is reached.
I've also tried adding xdebug_break() to index.php to no effect.
From what I've read, specifying path_mapping in the .sublime-project file seems the most likely solution. The documentation states that:
path_mapping
For remote debugging to resolve the file locations it is required to configure the path mapping with the server path as key and local path as value.
I'm using IIS on Windows 10 so the app's files are stored in C:\inetpub\wwwroot\ and the homepage's url is http://localhost/index.php which I'm assuming are the server path and local path respectively and as such the .sublime-project file looks like this:
{
"folders":
[
{
"path": "."
}
],
"settings": {
"xdebug": {
"url": "http://localhost/index.php",
"path_mapping" : {"C:\\inetpub\\wwwroot\\" : "http://localhost/index.php"}
}
}
}
Is this correct? If it is, is my php.ini file configured correctly?
[ExtensionList]
.
.
.
zend_extension = "C:\Program Files (x86)\PHP\php-5.6.30-nts-Win32-VC11-x86\ext\php_xdebug-2.5.1-5.6-vc11-nts.dll"
[XDEBUG]
xdebug.default_enable=1
xdebug.remote_autostart=0
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_host=localhost
The path_mapping and php.ini settings were both incorrect.
Based on #LazyOne's comment, removed the incorrect path_mapping in the .sublime-project file so it now looks like this:
{
"folders":
[
{
"path": "."
}
],
"settings": {
"xdebug": {
"url": "http://localhost/index.php"
}
}
}
Then added xdebug.remote_log="C:\Windows\Temp\Xdebug\remote.log" to php.ini and inspecting the log showed:
I: Remote address found, connecting to ::1:9000.
E: Time-out connecting to client. :-(
Searching this error lead to #Axel's answer to this SO question and based on this, changed xdebug.remote_connect_back=1 to xdebug.remote_connect_back=0 in php.ini
Breakpoints then started working and the Context, Watch and Stack tabs started showing the relevant data on reaching them.

PHP - XDebug on WAMP/XAMPP with Sublime Text - How to map to specific pages

I setup xdebug to work with sublime text 3 on my WAMP server. The problem is, that when I go to:
Tools -> XDebug -> Start Debugging (Launch Window)
The window it launches is localhost/nutri/ every time. This is a problem because I might need to debug localhost/nutri/other_page.php so I do this:
Tools -> XDebug -> Start Debugging (Launch Window)
So for example, say I need to launch the debugger on localhost/nutri/otherpage.php
but it opens the browser on the page:
http://localhost/nutri/?XDEBUG_SESSION_START=sublime.xdebug
So the xdebug is configured right I think:
enter link description here
Heres from php.ini:
; XDEBUG Extension
[xdebug]
zend_extension = "c:\\wamp\\bin\\php\\php5.6.19\\zend_ext\\php_xdebug-2.4.1-5.6-vc11.dll"
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9001
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1
xdebug.remote_log= "C:\\wamp\\tmp\\xdebug.log"
xdebug.profiler_enable=0
xdebug.profiler_output_dir = "C:\\wamp\\tmp"
xdebug.collect_params = 4
xdebug.collect_return = on
xdebug.collect_vars = on
xdebug.show_local_vars = 3
Heres my sublime text project file:
{
"folders":
[
{
"path": "test",
"follow_symlinks": true,
},
{
"path": "wp-content\\plugins\\genomics",
"follow_symlinks": true,
},
{
"path": "wp-content\\plugins\\decodify-members",
"follow_symlinks": true,
},
{
"path": "wp-content\\plugins\\decodify-terminology",
"follow_symlinks": true,
},
{
"path": "wp-content\\themes\\decodify",
"follow_symlinks": true,
}
],
"settings":
{
"xdebug":
{
"url": "http://localhost/nutri/"
},
"sublime-view-in-browser": {
"baseUrl": "http://localhost/nutri",
"basePath": "C:\\wamp\\www\\nutri"
}
}
theres nothing really interesting in the XDebug config file:
// Example:
// "/absolute/path/to/file/on/server" : "/path/to/file/on/computer",
// "/var/www/htdocs/example/" : "C:/git/websites/example/"
"path_mapping": {
},
// Determine which URL to launch in the default web browser
// when starting/stopping a session.
"url": "http://localhost/nutri/",
// An IDE key is used to identify with debugger engine
// when Sublime Text will start or stop a debugging session.
//
// This package does not filter sessions by IDE key,
// it will accept any IDE key, also ones that do not match this configured IDE key.
// It is merely used when launching the default web browser with the configured URL.
"ide_key": "sublime.xdebug",
// Which port number Sublime Text should listen
// to connect with debugger engine.
"port": 9001,
// Show super globals in context view.
"super_globals": true,
// Maximum amount of array children
// and object's properties to return.
"max_children": 32,
// Maximum amount of
// variable data to initially retrieve.
"max_data": 1024,
// Maximum amount of nested levels to retrieve
// of array elements and object properties.
"max_depth": 1,
Is there a way to add a page variable to the path that xdebug uses to load pages?
EDIT:
I managed to get the keyboard shortcut to start the debugger and run the browser at the same time by adding this keybinding to my sublime.keymap file:
{
"keys": ["ctrl+shift+1"],
"command": "xdebug_session_start",
"args": {
"launch_browser" : true
}
}
Which helps a lot, but I still can't figure out how to make it launch the right file. It always launches whats in my project file:
"xdebug":
{
"url": "http://localhost/nutri/"
}
which is the root page of my website. Is there a way I can add a variable to it like:
"url": "http://localhost/nutri/{$file}"

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.

SublimeLinter: PHP linting not working

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

Categories