Debugging php-cli scripts with xdebug and netbeans? - command-line

I have managed to initiate php-cli script debug session from the IDE itself, but I need to start the debugging session from the shell / command line. These are rather complex maintenance PHP scripts which take a lot of input parameters, so entering arguments from within Netbeans is a bit cumbersome.
I have done it before with Zend studio: https://zend18.zendesk.com/hc/en-us/articles/203838096-Debugging-PHP-CLI-Scripts, but now I need to get it working with Netbeans.

I got this working on Ubuntu/Netbeans by:
copying the xdebug config lines from the /etc/php5/apache2/php.ini file into /etc/php5/cli/php.ini
setting an environment variable with the name of the debug session (you can get this from the query string in the url of the page netbeans launches when you start debugging) so the command is: export XDEBUG_CONFIG="idekey=netbeans-xdebug"
Then it's simply a case of starting debugging in netbeans and doing php myscript.php at the command line.
Note:
If you want to debug remotely using netbeans you need to use Debug File on the file that is being run from the command line, not normal Debug.

Add xdebug.remote_autostart=On to your php.ini file or add -dxdebug.remote_autostart=On as parameter to the PHP binary call (php -d... script.php).
See http://xdebug.org/docs/remote

I will put all together, the following is that works for me.
file:
/etc/php5/cli/php.ini
zend_extension="/usr/lib/php5/20121212/xdebug.so" -> xdebug bin path
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_port=9000 -> same port configured in netbeans debugging tab
xdebug.idekey="netbeans-xdebug" -> same ide configured in netbeans debuggin tab
xdebug.remote_autostart=1
then, without any other parameter
php script.php

I had the same problem, my solution was this:
Environment: Netbeans 8.2 under windows (apache+php)
Assuming you already have PHP and NetBeans configured to debug
code using Xdebug (http://wiki.netbeans.org/HowToConfigureXDebug#Notes_on_Windows_Configuration)
On netbeans create new Configuration (“Project Properties” > “Run configuration” > “New…”
In the new Configuration set Do Not Open web Browser (“Advanced” > “Do Not Open web Browser”)
Set active the new configuration created (drop down in tool bar)
Set breakpoint for debug
Open debug (CTRL+F5)
Open Terminal window (“Tools” > “Open in Terminal”)
Type in terminal: $ export XDEBUG_CONFIG="idekey=netbeans-xdebug" (the value "netbeans-xdebug" must coincide with “Tools” > “Options” > “Debugging” > “Session ID”)
Type in terminal: $ php.exe -f "C:\Apache24\htdocs\www.SiteName\ScriptName.php" -- "Arg1=x&Arg2=y"
Follow debug…

I had the same problem my solution was this:
In Netbeans > the project window > right click on the php project > properties > Run configuration.
Create a New Configuration.
Fill the correct values:
Run as "script"
set php interpreter
change index file in my case it was "cron/index.php".

You can use the Dephpugger project if you dont want to configure xDebug for your IDE (i hate configurations).
https://github.com/tacnoman/dephpugger
You can run the debugger in terminal, like ipdb for Python and byebug for Ruby.

Make sure you also setup DBGP_IDEKEY value, because usually it is not idekey.
For example on Linux:
export DBGP_IDEKEY="netbeans-xdebug"
export XDEBUG_CONFIG="netbeans-xdebug=netbeans-xdebug"

Related

Error with autocomplete in Eclipse

I am running Eclipse 4.6.3 with GoClipse and NodeClipse installed. I have configured Go in Preferences -> Go.
I want autocomplete to work for Go. However, it is giving me the error: writing to process input broken pipe
See screenshots below for error and configuration.
How do I fix this problem?
At least on the second page, all of the paths seem wrong. You supplied the path to the source code where the dialog asks for the path to the executable.
To make sure you have all the tools installed run the following commands in the terminal:
go get -u github.com/nsf/gocode
go get -u golang.org/x/tools/cmd/guru
go get -u github.com/rogpeppe/godef
Now, for each of the tools run
which <tool>
# example:
which guru
# => /Users/user/gocode/bin/gocode
Copy the output into the Executable: field in the config screen.
For gofmt you should be able to simply tick "Use default location"

Call ./.../bin/spark-submit pythonfile.py in eclipse (Pydev) console when running program

Current situation which works fine:
I'm currently programming my Pyspark files in eclipse with the Pydev plugin
I manually execute these files in the ubuntu shell with the following command:
./.../bin/spark-submit pythonfile.py
Desired situation:
When I press the "run" button in eclipse, eclipse will call the command mentioned above and show the console output in the eclipse console.
Is this possible and if yes, could someone give me a clue on how to do it?
Thank you!
I would recommend an external launch.
From the Run menu, choose External Tools | External Tools Configurations... and then create a launch configuration specifying the command you want to run.
You can generalize the command a little by using Variables For example:
Location: ${workspace_loc:/myprojectname}/../bin/spark-submit
Working Directory: ${workspace_loc:/myprojectname}
Arguments: ${workspace_loc:/myprojectname/myscript.py}
This is what a screenshot of the configuration looks like.
Additionally, in the Common tab you have a control over whether the output is captured in a console (the default) and/or redirected to a file. In this example screenshot, the output comes to a console and is written to a file back in my project:
Output file: ${workspace_loc:/myprojectname/build_output}

Scrapy + Eclipse PyDev : how to setup the debugger?

I've successfully setup Eclipse with my Scrapy project.
I did it by setting a new Run/Debug configuration :
Whose main module links to Scrapy /usr/local/bin/scrapy for me (I've found suggestion to use cmdline.py but that failed on my computer (OSX Lion & scrapy installed through easy_install)
Defining the arguments to send "crawl ny" in my case as I would if I used the Scrapy command line
Setting the correct working directory (${workspace_loc:My Project/src} in my case)
Eclipse can successfully launch my project, but I've no debbuger. I'm missing my breakpoints and variable inspection, does anyone know how to setup the debbugger with this environment ?
Keep the whole scrapy project folder under PyDev.
You Need to set the main module to scrapy/cmdline.py
Set arg to crawl ny in your case
None of the suggestions above worked for me. Things would run, but no break points would fire.
I added a main.py file to my local project and hooked into the scrapy command line like so:
import scrapy.cmdline
def main():
scrapy.cmdline.execute(argv=['scrapy', 'crawl', 'wiki'])
if __name__ =='__main__':
main()
This could easily be further refined to pass in the spider name to have different debug configs per spider.
Well, if you're running it properly from inside Eclipse already, isn't it just a matter of running it in debug mode?
I.e.: if you followed the instructions from: http://pydev.org/manual_101_run.html (regarding the setting to "Always launch the previously launched application"), after running your module in regular mode, just press F11 to run it in debug mode.
Here's how I solved this for my environment, with the Scrapy package in a virtual environment outside the project directory:
1) Create a simlink to your cmdline.py from inside the project, something like:
ln -s ../venv/lib/python3.4/site-packages/scrapy/cmdline.py cmdline.py
2) Refresh the project so you can see it, then set that as the main module in the debug configuration.
3) In the "Arguments" tab in the debug configuration, where it says "Working Directory", select Other and then enter, or navigate to using the buttons, the Scrapy directory in your project.

How to open a directory in PHPStorm or IntelliJ (or any JetBrains IDE) from the command line?

Is there a way to open up a directory in PHPStorm or an equivalent Jetbrains IDE from the command line? For example, in Textmate, I would just do:
mate .
to open the working directory.
Use Tools -> Create command line launcher and then you can execute pstorm .
Here's how I got IntelliJ Command-line launcher to work with MAC Sierra
(v 10.12.2).
This works with IntelliJ IDEA:
Tools -> Create Command-line Launcher..
Replace 'idea' in the string '/usr/local/bin/idea' with whatever you wish.
(I use 'ij'), so for me its '/usr/local/bin/ij'.
Open your terminal
Navigate to the project/folder you want to open.
Write the chars you wrote after 'bin/' and then '.'
For me its ij .
On OS X: open -a 'phpstorm.app' file-or-folder
For PhpStorm on Windows:
Add the PHPStorm's installation path to the Environment Variables "PATH" variable,
Scroll to the project folder in the command line
Issue the command phpstorm64.exe . if it is 64 bit machine or phpstorm.exe . for 32 bit machine.
I presume the same strategy will work for IntelliJ as well.
Here is the menu entry for v2016.2:
After that you can open folders with pstorm {myfolder}.
Hope it helps.
If you see this message
for Intellij 2019.+ please check this answer. It uses Jetbrains toolbox.
You just need to set path in Generate shell scripts option to /usr/local/bin/ in Jetbrains toolbox
https://stackoverflow.com/a/56050914
and then just run idea .
or pycharm . , phpstorm . etc.
On MacOs
edit ~./bash_profile
add this line
alias pst="open -a 'phpstorm.app'"
Source it
source ~./bash_profile
Now you can open phpstorm in a directory with
pst .
If you are using the JetBrains toolbox, you can configure the shell script for each IDE by going to
settings of the IDE in the toolbox (three dots > settings)
configuration
shell script name
Set it to any text you want
So the method Tools > Create command line launcher... no longer exists in OSX Intellij 2019.1
You can manually make this change via:
vim /usr/local/bin/idea
Change these lines appropriately from old version to new. should be something like this:
RUN_PATH = u'/Users/blahblah/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/191.6183.87/IntelliJ IDEA.app'
CONFIG_PATH = u'/Users/blahblah/Library/Preferences/IntelliJIdea2019.1'
SYSTEM_PATH = u'/Users/blahblah/Library/Caches/IntelliJIdea2019.1'
If you don't know the new path then run something like:
ls /Users/blahblah/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U
or manually navigate via finder, then drag/drop the IntelliJ IDEA.app icon from finder into your cli to copy across the full path.
I`m using JetBrains Toolbox to get the latest updates. And the only solution which worked for me (macOS) is:
Add the following function into ~/.bash_profile
phpstorm-open-current-path() {
PHP_STORM_CH=~/Library/Application\ Support/JetBrains/Toolbox/apps/PhpStorm/ch-0
PHP_STORM_LATEST_VERSION=$(ls -rA1 "${PHP_STORM_CH}" | head -1)
open -a "${PHP_STORM_CH}/${PHP_STORM_LATEST_VERSION}/PhpStorm.app"
}
Reload the changes by opening a new terminal, or running the following command in the current one:
. ~/.bash_profile
Use it:
cd <PROJECT_DIR>
phpstorm-open-current-path
It should be pretty easy to adopt it for any other IDE/OS.
1- add the phpstorm installation path to the path system variable
2- in project folder in address bar type "cmd".
3- in cmd type "phpstorm64 .".

Open multiple Eclipse workspaces on the Mac

How can I open multiple Eclipse workspaces at the same time on the Mac?
On other platforms, I can just launch extra Eclipse instances, but the Mac will not let me open the same application twice. Is there a better way than keeping two copies of Eclipse?
This seems to be the supported native method in OS X:
cd /Applications/eclipse/
open -n Eclipse.app
Be sure to specify the ".app" version (directory); in OS X Mountain Lion erroneously using the symbolic link such as open -n eclipse, might get one GateKeeper stopping access:
"eclipse" can't be opened because it is from an unidentified developer.
Your security preferences allow installation of only apps from the Mac App Store and identified developers.
Even removing the extended attribute com.apple.quarantine does not fix that. Instead, simply using the ".app" version will rely on your previous consent, or prompt you once:
"Eclipse" is an application downloaded from the Internet. Are you sure you want to open it?
By far the best solution is the OSX Eclipse Launcher presented in http://torkild.resheim.no/2012/08/opening-multiple-eclipse-instances-on.html It can be downloaded in the Marketplace http://marketplace.eclipse.org/content/osx-eclipse-launcher#.UGWfRRjCaHk
I use it everyday and like it very much! To demonstrate the simplicity of usage just take a look at the following image:
EDIT: Milhous's answer seems to be the officially supported way to do this as of 10.5. Earlier version of OS X and even 10.5 and up should still work using the following instructions though.
Open the command line (Terminal)
Navigate to your Eclipse installation folder, for instance:
cd /Applications/eclipse/
cd /Developer/Eclipse/Eclipse.app/Contents/MacOS/eclipse
cd /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse
cd /Users/<usernamehere>/eclipse/jee-neon/Eclipse.app/Contents/MacOS
Launch Eclipse: ./eclipse &
This last command will launch eclipse and immediately background the process.
Rinse and repeat to open as many unique instances of Eclipse as you want.
Warning
You might have to change the Tomcat server ports in order to run your project in different/multiple Tomcat instances, see Tomcat Server Error - Port 8080 already in use
To make this you need to navigate to the Eclipse.app directory and use the following command:
open -n Eclipse.app
Actually a much better (GUI) solution is to copy the Eclipse.app to e.g. Eclipse2.app and you'll have two Eclipse icons in Dock as well as Eclipse2 in Spotlight. Repeat as necessary.
If the question is how to easily use Eclipse with multiple different workspaces, then you have to use a kludge because shortcuts in OS X do not provide a mechanism for passing command line arguments, for example the "--data" argument that Eclipse takes to specify the workspace. While there may be different reasons to create a duplicate copy of your Eclipse install, doing it for this purpose is, IMNSHO, lame (now you have to maintain multiple eclipse configurations, plugins, etc?).
In any case, here is a workaround. Create the following script in the (single) Eclipse directory (the directory that contains Eclipse.app), and give it a ".command" suffix (e.g. eclipse-workspace2.command) so that you can create an alias from it:
#!/bin/sh
# open, as suggested by Milhous
open -n $(dirname $0)/Eclipse.app --args -data /path/to/your/other/workspace
Now create an alias to that file on your desktop or wherever you want it.
You will probably have to repeat this process for each different workspace, but at least it will use the same Eclipse installation.
2018 Update since many answers are no longer valid
OS X Heigh Sierra (10.13) with Eclipse Oxygen
Go to wherever your Eclipse is installed. Right-click -> Show Package Contents -> Contents -> MacOS -> Double-click the executable called eclipse
A terminal window will open and a new instance of eclipse will start.
Note that if you close the terminal window, the new Eclipse instance will be closed also.
To make your life easier, you can drag the executable to your dock for easy access
Instead of copying Eclipse.app around, create an automator that runs the shell script above.
Run automator, create Application.
choose Utilities->Run shell script, and add in the above script (need full path to eclipse)
Then you can drag this to your Dock as a normal app.
Repeat for other workspaces.
You can even simply change the icon - https://discussions.apple.com/message/699288?messageID=699288&#699288
One another way is just to duplicate only the "Eclipse.app" file instead of making multiple copies of entire eclipse directory. Right-Click on the "Eclipse.app" file and click the duplicate option to create a duplicate.
If you're like me, you probably have terminal running most of the time as well.
You could just create an alias in /Users//.bash_profile like this
alias eclipse='open -n path_to_eclipse.app'
then all you have to do is just open the terminal and type eclipse.
Based on a previous answer that helped me, but different directory:
cd /Applications/Eclipse.app/Contents/MacOS
./eclipse &
Thanks
You can create an AppleScript file to open Eclipse with a given workspace. You can even save the AppleScript file as an Application, which is equivalent to creating an alias with arguments in Windows OS.
Open Script Editor and type the following:
do shell script "open '/path/to/your/Eclipse/installation' -n --args -data /path/to/your/workspace"
For instance:
do shell script "open '/Applications/Eclipse.app' -n --args -data /MyWorkspaces/Personal"
Press the Run button to check it's working.
This script can be saved as such, but I prefer to save it as an Application. That way I can customize the icon by copying the *.icns icon from the original Eclipse.app bundle to the script application bundle.
To open an App folder, use the "see contents" contextual menu option. It should look like this:
Where "main.scpt" is the AppleScript file and "applet.icns" is the icon from the original Eclipse bundle.
Launch terminal and run open -n /Applications/Eclipse.app for a new instance.
I found this solution a while back, can't remember where but it still seems to work well for me.
Create a copy of Eclipse.app for each workspace you want to work in (for this example ProjectB.app), then open ProjectB.app/Contents/MacOS/eclipse.ini and add these two lines at the beginning of the file:
-data
/Users/eric/Workspaces/projectb
... substituting where your workspace is located. When you launch ProjectB.app it will automatically start with that workspace instead of prompting for a location, and you should be able to run it at the same time as other Eclipse instances with no problem.
In Terminal simply paste below line and hit enter ..
/Applications/Eclipse.app/Contents/MacOS/eclipse ; exit;
If you want to open multiple workspaces and you are not a terminal guy, just locate the Unix executable file in your eclipse folder and click it.
The path to the said file is
Eclipse(folder) -> eclipse(right click) -> Show package
Contents -> Contents -> MacOs -> eclipse(unix executable file)
Clicking on this executable will open a separate instance of eclipse.
A more convenient way:
Create an executable script as mentioned above:
#!/bin/sh
cd /Applications/Adobe\ Flash\ Builder\ 4.6
open -n Adobe\ Flash\ Builder\ 4.6.app
In you current instance of Flashbuilder or Eclipse, add a new external tool configuration. This is the button next to the debug/run/profile buttons on your toolbar. In that dialog, click on "Program" and add a new one. Give it the name you want and in the "Location" field, put the path to the script from step 1:
/Users/username/bin/flashbuilder
You can stop at step 2, but I prefer adding a custom icon to the toolbar. I use a the Quick Launch plugin to do that:
http://sourceforge.net/projects/quicklaunch/files/
After adding the plugin, go to "Run"->"Organize Quick Lauches" and add the external tool config from step 2. Then you can configure the icon for it.
After you save that, you'll see the icon in your toolbar. Now you can just click it every time you want a new Flashbuilder/Eclipse instance.
You can run multiple instances of Eclipse by creating a pseudonym for Eclipse application in it's folder and using it for running new Eclipse instance
Lets try downloading this in your eclipse on Mac you will be able to open multiple eclipse at a time Link
Name : macOS Eclipse Launcher
Steps :
Go to eclipse Market place.
Search for "macOS Eclipse Launcher" and install.
It will restart .
Now under file menu check for open option > there you will find other projects to open also at same time .
Window -> New Window
This opens a new window and you can then open another project in it. You can use this as a workaround hopefully.
It actually allows you to work in same workspace.