configuring php files in vscode - php

I run php files in Apache server. Also, i've added in user settings the code as
"php.validate.executablePath": "C:\wamp64\bin\php\php7.0.10\php.exe",
Still, i cant run php files? Help;

You have to install php debug extension in visual studio code
Try this
https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
or you can try below one using php xdebug extension(this works for me)
http://www.accella.net/knowledgebase/debugging-php-with-visual-studio-code/

As the name suggests, php.validate.* directives are used to configure linting (i.e. parsing PHP source code to detect syntax errors):
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.
To run PHP scripts from within the editor you have a number of choices or none at all depending on what you want to do exactly. You can run command-line scripts from the integrated terminal, with an extension like Runner or Code Runner. As far as I know there's no way builtin way to lauch a browser in the preview pane that reloads as you save if that's what you mean. And you can certainly configure a debugger.

Related

Debug CLI PHP script in PhpStorm, cannot establish connection to Xdebug 2.6.0

I'm trying to run a CLI script in PhpStorm and use the debugger to step through it.
It took some doing, but I now have Xdebug installed and the PhpStorm CLI Interpreters dialog confirms that:
I created a Run/Debug config and when I try to execute/debug it, the script runs all the way through without breaking at my breakpoints and I get this error at the bottom of PhpStorm:
The PhpStorm docs say that xdebug for CLI scripts can configured with an environment variable like this:
export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"
I've confirmed that PhpStorm sees that environment variable:
Here is my Run/Debug config:
I'm at a complete loss here. How the heck can I get this thing to debug a CLI php script? Any help is appreciated.
Gah, I hate it when I spend a couple of hours trying to fix something and discover it's totally unrelated.
The problem was that I'm using short tags and my cli php.ini file had short_open_tag=Off. The code I'm running is normally run in a web context and the php.ini for that web context had short_open_tag=On so the code was working.
This code is an api endpoint and I needed to be able to step through and see what was going on and there's nothing that inherently requires it to run in the web context (except for the input params, but I'm faking those for testing purposes anyway).
So, my debug configuration was fine.
I discovered it by trying to reduce the problem further and further and I just tried running the code directly from a command line (php sync.php) to see that it was at least working and producing the correct output.
It wasn't producing the normal api json output, it was just echoing all of the code in the file. That's what led me down the path to realizing my stupid mistake.

Disable lack of PHP executable path in Visual Studio Code

I use Windows10 home and I'm having this notification in Visual Studio code:
Cannot validate since no PHP executable is set. Use the setting
'php.validate.executablePath' to configure the PHP executable.
I don't want to have it, so I went to preferences > settings.JSON and added:
{
"php.validate.executablePath": null
}
I saved, closed the program, and then opened a PHP file but I still get the notification.
How could I totally remove that notification?
The reason I want to remove it is because I usually don't do PHP development on windows, rather, on Linux and I want to keep my Windows environment minimal without installing PHP on it.
Edit: I don't have any extensions on VSCODE besides "ESLint" for JavaScript.

VSCode - php not installed?

I have VSCode installed, but don't seem to have php - i.e. there is no "php.exe" anywhere on my computer. No guides that I can find on the web about setting VSCode up for PHP suggests that I need to download and install php itself seperately (only debuggers and linters)... my question is:
Do I need to install PHP seperately? Should I have had to do this, or is there a bug in my VSCode installation...
Yes you need to install PHP from the php website and then tell VSCode where PHP.exe is located.
VSCode is an editor not an interpreter.
I think if you install PHP at the default location VSCode will automaticly pick it up but if not you need to specify its path in options.
If you install XAMPP you will get apache,php and mySql in one installation.
EDIT: an interpreter is software that translated your code(in your case PHP) into code that the CPU can understand and then executes.
#kpollock it' not you. Yes, it should seem obvious that the language should be installed manually or separately, so you should have gotten that part, sorry. But no, there doesn't seem to be information anywhere about defining the underpinnings. This "understanding" seems to be left to the individual through research as you're doing.
After I installed PHP I manually set my environment PATH to include the PHP folder. OR in VS Code you can go to menu>File>Preferences>User Settings, the settings are maintained as a JSON object (unlike VS) and there is a PHP section for the .exe path.
Since you mentioned Node, you may not have installed Node.js manually. (I don't know if Node comes with VS Code either.) It might have come in with a VS2015 extension like Gulp or some other higher-level functionality, or maybe it was an installation option with VSC. If you can't use node or npm from a console, set your environment PATH to include it.

Using Eclipse - No option to run or debug PHP as a script?

I wanted to try pick up PHP again and decided to try out Eclipse as well.
I've just done a fresh install of Eclipse PDT, as well as the relevant php/mysql/apache servers with EasyPHP. Zend-debugger and Xdebug have also been installed.
However, I don't have an option to Run or Debug as a PHP script. The only option available is to Run As a "PHP Web Application". I've seen guides and videos that refers to a Run As PHP Script option, but I don't have that.
What do I need to configure to get this?
same problem here i choose run as > run configurations > on the left there is php cli application double click on it to create new then choose alternate php and from it set the directory for your php executable which i found in /usr/bin/php5 and php.ini the browse to your php file to run it
the problem here is that you'll have to set the the directory for the php script file each time you run a new script
hope this will help

Is there a interactive debugger for php like ruby's debugger?

I watched the Creating a weblog in 15 minutes with Rails 2 and after 9 minutes in the video he shows ruby's interactive debugger, which allows you to call functions/methods from within a running script.
This goes way beyond breakpoints and looks very useful.
Is there something for PHP that gives similar functionality?
Install xdebug and then use one of the debug clients mentioned here.
Although Milen's answer is the only correct one circa 2009, and Xdebug is still a useful tool, using it requires you to recompile your PHP or to edit your php.ini runtime configuration to load it as a shared object. It also means using a specific client application that supports its network protocol, such as an IDE like PhpStorm.
An alternative is phpdbg, which is an interactive debugger that ships with PHP core versions 5.6 and later and can debug PHP scripts written to conform to PHP 5.4 or later.
Using it is simple:
phpdbg php_script_i_want_to_debug.php
Once in the debugger, type help to access the help menu.
If you don't already have phpdbg on your system, it may be because your PHP was configured without the --enable-phpdbg option. You can either:
Recompile your PHP, being sure to add --enable-phpdbg when you run ./configure (this will simply also build the phpdbg binary), or
download the phpdbg source independently and compile it against your installed PHP (assuming you have the PHP source available). Instructions for doing that, while sparse, are here.

Categories