When I develop with the server on my workstation I can use XDebug from my IDE and debug variables, etc.
Many times the server is on a remote machine where I have only SSH, so I only edit with vi. In that case is there a way to use XDebug? Is there a client I could use from terminal?
You can use X forwarding with ssh, if allowed at the server end (see the ForwardX11Trusted directive for the server's ssh configuration file). On your client you would start ssh using the -X argument to allow X forwarding. This requires the client to support X (e.g. if your local machine is running Linux, OS X, etc...)
Related
I'm setting up xdebug for php within sublime text, and xdebug keeps on logging errors related to being unable to connect:
Log opened at 2016-08-18 21:06:01
I: Connecting to configured address/port: localhost:9988.
E: Could not connect to client. :-(
Log closed at 2016-08-18 21:06:01
I hoped that debugging directly by going to http://localhost:9988 in my browser might help, but it simply displays the google chrome error page: "localhost refused to connect". Perhaps the error exists on the other end, that data can't be pushed to the sublime text client, I don't know. Sublime text xdebug does show the message "Reloading /var/log/xdebug/xdebug.log" when I run tests/etc, so it seems to be aware of the php code being run, just doesn't get any further.
So, I never thought I would have to debug xdebug itself, but: How can I debug the xdebug to code editor connection? If this were nginx, I would start debugging the virtualhost, but since it's xdebug... ...I have no idea where to start debugging the lack of an app to connect to?
## Various Configuration Settings ##
I am on ubuntu linux 14.04.
Here is my xdebug.ini conf if pertinent:
[xdebug]
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host="localhost"
xdebug.remote_handler="dbgp"
xdebug.remote_port=9988
xdebug.remote_mode = req
xdebug.overload_var_dump=0
xdebug.idekey = sublime.xdebug
xdebug.remote_log="/var/log/xdebug/xdebug.log"
;https://github.com/martomo/SublimeTextXdebug
Xdebug installed:
apt-cache policy php-xdebug
php-xdebug:
Installed: 2.4.0-5+donate.sury.org~trusty+1
Candidate: 2.4.0-5+donate.sury.org~trusty+1
Version table:
*** 2.4.0-5+donate.sury.org~trusty+1 0
500 http://ppa.launchpad.net/ondrej/php/ubuntu/ trusty/main amd64 Packages
100 /var/lib/dpkg/status
Module active:
php -m | grep -i xdebug
xdebug
Xdebug
phpinfo xdebug settings:
PHP debugging requires two components that collaborate: a PHP extension that acts as server and a software that knows how to talk to this extension and drive its functionality (it is the client).
However, despite the usual client-server protocols where the client connects to the server, the PHP debugger works the other way around: the server is the one that connects to the client (that should be started and listening on port 9000).
xdebug is the most known PHP extension for debug. There are many programs and program extensions/plugins that acts as clients for it. I didn't work with Xdebug package for Sublime (I didn't work with Sublime, in the first place) but the principles are the same.
How a debugging session works?
The client software (Sublime with the Xdebug package in your case) starts listening on port 9000 of localhost, waiting for the server to start the connection. It probably doesn't listen on the port all the time but only when the developer tells it so.
You start the PHP script to debug. xdebug doesn't kick in on all requests to the server but only when it finds a marker in the request. Depending on the SAPI used to run the script, the marker is either an environment variable (for CLI scripts) or a cookie or a GET or POST argument (for web pages). Read more on the "Starting The Debugger" section of the documentation.
When the PHP interpreter starts the execution of the PHP script, if xdebug finds the marker explained above then it tries to connect the xdebug client. Otherwise, it stays out of the way and lets the script run at its full speed.
When the debugging marker is present in the environment, the xdebug extension (the server) tries to connect to the xdebug client (by default on port 9000 of localhost but these settings can be changed as needed). If it cannot connect (because the client is not listening) then it logs the failure then puts itself out of the way and lets the script run at its full speed.
After it successfully connects to the client, the xdebug PHP extension either stops before running the first statement of the PHP script or runs the script until its execution reaches a breakpoint. This behaviour and the list of breakpoints are sent by the client to the server during their initial communication as the connection was established. Then the extension waits for commands from the client. The client displays to the developer the current state of the running script (the next statement to run, the values of the variables in the current scope etc) and waits for commands (run next statement, continue, add/remove breakpoints, watch some variable etc).
Why it doesn't work for you?
It's not very clear for me from your question but I'll assume you run the webserver (with the PHP interpreter and the xdebug extension) on the same computer you run the xdebug client (localhost). If this is not the case, don't despair. The solution is a command line away (read at the end of the answer).
From the information you posted in the question is clear that xdebug is installed, enabled and it works properly. The output of telnet localhost 9988 says nobody is listening on port 9988. The xdebug client should listen there.
I never worked with Sublime Text (and its packages). This article explains how to install and make it work. However, it doesn't explain how to configure it to listen on port 9988.
I would start by setting the PHP xdebug extension to connect to the default port (9000):
xdebug.remote_port=9000
and then, if everything works, I would try to find out how to configure the Sublime Text xdebug package to listen on a different port. Do you really need it to listen on a different port?
What if the web server and the xdebug client are on different computers?
If you need to debug a PHP script that runs on a remote machine the xdebug client listens on the local machine (on port 9000) and the xdebug extension tries to connect to port 9000 on the remote machine. A solution that is possible in intranets and VPNs is to configure xdebug to connect to port 9000 of the local machine but, apart from these conditions, it usually also requires changes in the firewall and/or other security software.
The easiest way to debug the PHP scripts in this situation if you have ssh access to the remote machine is to create a ssh tunnel from port 9000 of the remote machine to port 9000 of the local machine.
Assuming you use ssh to connect to the remote machine (to put the files on it), all you have to do is to append -R 9000:localhost:9000 to the command line you use to connect and start a ssh session to the remote machine.
As long as this connection is open, any connection request on port 9000 (the first 9000 on the command line above) of the remote machine (-R) is forwarded through the tunnel to the port 9000 (the second 9000 from the command line) of the local machine (localhost). This way the remote xdebug PHP extension is able to contact the remote xdebug client (assuming it is listening).
If you are using xdebug-v3, please try:
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=1
This should solve your issue.
Ok, so after extensive testings of different settings, here are my suggestions for debugging the problem for people who come after me:
Do not rely on testing with only 1 xdebug client! It's trivial to install two editors/IDEs, so get an alternate editor running to make it possible to see whether there is a problem with xdebug, or with the specific client!
There can be 3 locations that carry configuration for the xdebug+xdebug client combination! The client(or editor plugin) configuration, the 20-xdebug-conf.ini file (or in php.ini equivalent), and your project-specific configuration. Make sure all 3 locations are in sync in terms of port, path_mapping, etc.
I have a PHP app runing on local network server (Mac Mini server with OS X Lion). There are several local clients (also Macs) accessing this app. Client machines are put to sleep from time to time. I need to be able to check from PHP server if the local clients are running (wake) or in sleep mode.
I have been successful of doing this with AJAX polling script, where I periodically ping the local machines and display status of a local machine in PHP app. The problem I have is that PING command initiates wake-on-lan on client machines if they are in sleep mode, and this is something I do not want. I would just like to see the status without waking the machine.
Can this be done?
check
pmset -g | grep hibernatemode
http://www.tuaw.com/2010/10/20/safesleep-lets-you-use-safe-sleep-on-demand-on-your-mac/
I would say you need to correctly configure the Wake-on-lan for those machines. Aparently they get awakened for every packet, which is probably not what you require. Usually WoL is configured to wake only on Magic Packet (on Windows it can be configured in Device Manager in the properties of network card driver). Then you will be able to use ping (or any other type of network traffic) to check if PC is online.
I have dual boot mode with Windows 7 and Ubuntu 10.
On Windows 7 I have XAMPP installed, on Linux I have LAMP installed.
Is it possible to force the MySQL DB servers installed onto different operating systems (even though they would be of identical versions, they are different) to use the same physical files?
So in dual boot mode, independently from the fact that I ran another operating system, I would be able to use the same physical data. Sometimes I'd like to switch OS but it would be great to be able to use the same databases.
in your my.ini (in Windows it's located somewhere like C:\Program Files\MySQL\MySQL Server 5.1. It's the main configuration file for MySQL) file, you should have this line:
datadir="C:/ProgramData/MySQL/MySQL Server 5.1/Data/" for example
change it in both Windows and Linux Ubuntu to point to one single physical folder (on a partition with a file system which Windows could recognize). It will work. File formats are identical.
Whether you boot from Ubuntu, or Windows 7, it won't matter, 2 different builds of MySQL will be looking for data in the same place. Once data is modified in Windows environment, you boot up from Ubuntu and the data is there, modified.
Whilst not ideal, this should be fine as long as:
You're using identical versions of MySQL on both operating systems.
You shutdown mysqld before you copy the data files across. (If you're going to be copying the data files between partitions rather than keeping them on a shared fat32 partition).
In essence, as long as MySQL is running on an architecture of the same "endianness", then the file formats should be transferable.
As a suggestion, you could just close ICQ, etc. and use the free memory to run Ubuntu within a VirtualBox virtual machine on top of Windows 7 - hence ensuring you can trivially access your development environment without having to restart, etc.
This is actually quite a nice set up as it means you can use a Windows development environment if you want and simply host the site web site data on a Samba mount on the Ubuntu virtual machine.
As long as the data is sharedable/reable/writeable on both OS, and both file format are identical on both OS, it should be doable
The first problem I can imagine is the case insensitivity in windows.
so, convert your database/table ti camel_case (or camelcase) if you are always using CamelCase.
More information to read up - http://dev.mysql.com/doc/refman/5.0/en/limits-windows.html
Of course you can.
But I dont think, it is possible for your dual boot system.
Lets assume, your MySQL server is installed under Win7 machine. You can perfectly access it from Win7 enviroment, and even from Linux enviroment (if you do not deny access in your MySQL server settings).
The system, which is your MySQL installed under, has to be running! Then you can access it from multiple systems if allowed ;-)
I goggled a lot of time and found that running a Linux kernel is a solvable way and feasible solution.
Vagrant
It is a tool for building and managing virtual machine environments in a single workflow. The main reason why I argue you using vagrant is that it is not too heavy and does not swallow much of your computer resources. I believe you get through Vagrant documentation that will allow you to launch a Linux based machine on your physical machine.
Let's assume that the host machine is assigned IP 192.168.1.2 and the virtual machine has the IP address as 192.168.1.10, and make sure that the host and guest machine could see each other. Please read thoroughly Networking section to customise the network configuration.
Verifying connection between host and guest machine
Install MySQL Server
MySQL is a database management system. Basically, it will organise and provide access to databases where our site can store information.
Open a terminal in the machine has been set up from the above step. Run the following command:
sudo apt-get install mysql-server-5.6
Notes: It's up to the version of Linux distribution installed, the above command would be adjustable to suit your need. For install, I used the core of Ubuntu 14.04, see the link.
During the installation, your server will ask you to select and confirm a password for the MySQL root user. This is an administrative account in MySQL that has increased privileges.
Verifying the installation
From a terminal in the guest machine (i.e. the virtual machine), run the following command:
mysql -u root -p
will ask the MySQL password, then provide the one you have set up during MySQL Server installation. The following is the screenshot if you feed correct information to MySQL server.
Turn MySQL Server remotely accessible
Because we need a centralised database server where other computers could access and connect to the database of interest. Again, open a terminal and run the following MySQL commands:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'192.168.1.2' IDENTIFIED BY PASSWORD '*4ACFE3202A5FF5CF467898FC58AAB1D615029441' WITH GRANT OPTION;
GRANT PROXY ON ''#'' TO 'root'#'192.168.1.2' WITH GRANT OPTION;
FLUSH PRIVILEGES;
which 192.168.1.2 is the IP address of the host machine and hashed string of password gets from user table in mysql database.
Okay. You might take a rest and enjoy your drink if there is no issue so far.
Verifying the remote access
From a terminal on the host machine, fire up the following command:
mysql -h192.168.1.2 -uroot -p
which is asking you to enter the password. If the root credential is correct, you would see a screenshot like the above one. One thing needs to be paid attention is to add -h192.168.1.2 following mysql command because we are not in the machine where MySQL server is installed.
All in all, we have set up a MySQL server used for both host and guest machine. In reality, if I have another machine assigned 192.168.1.3 can also connect to the database server and exchange data between server and client.
I've first installed the WAMP server on my system.
It used http://localhost to show my files in the www directory.
But then I installed visual studio 2008. It too uses the http://localhost/
But it doesn't show up. What should I do?
I assume you mean IIS? Cassini (the build in "debugging" webserver) uses high ports when you fire an app up. Either way you need to configure either WAMP or IIS to listen on a port other than port 80, then you can access one on http://localhost/ and one on http://localhost:MYPORT/.
VS uses it's own development server, and usually VS starts his own server in debug mode, and there isn't a common server executable. Since VS needs to start it's own server in debug mode to test .NET driven applications, it can't show your WAMP applications because it usually runs in other port. Also, you can't run PHP applications under VS.
Try looking at server connection that the browser brings you at the application URL.
How do you setup a multi-developer XDebug PHP environment?
I have the following setup:
I have a linux machine with Apache and Xdebug loaded and a php.ini file that I think is correct.
I found a python proxy script that I'm using to proxy the calls from the PDT Eclipse IDE's my developers are using to the Apache/Xdebug running on the same web server.
I set the idekey in php.ini to "ECLIPSE_DBGP" and for Xdebug to autostart
From the log information from the proxy it says that there is no server with the key "ECLIPSE_DBGP" and it stops the request.
Has anybody run into this or has a step by step setup to get this to work?
I have exhausted what I have found using google.
You can use ssh to tunnel the debug-connection back to your client machine. Eg. from your client machine, connect to the server with something like:
ssh -R 9000:localhost:9000 you#example.com
Then fire up your (local) debugger, and start the remote script. Xdebug (at the server) will now establish a connection to its localhost:9000, but since this port is forwarded back to your local machine, your (local) debugger will receive the connection.
If you use Windows on your client side, you can do the same thing with PuTTY.
See the documentation for Spectator for some more details.