Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
October 22, 2013
Chris
PHP
Comments Off on How to debug code on a remote server (or in vagrant box) with PHPStorm

How to debug code on a remote server (or in vagrant box) with PHPStorm

PreviousNext
phpstorm 7.0 php

Please also note: There are several methods to do remote debugging. This is the one that works without any browser plugins etc. and integrates seamless into your PHPStorm-&-Vagrant-workflow.

 

Requirements

You have part 1 of this tutorial (How to setup a professional local server (in a virtual machine) with Vagrant in PHPStorm) successfully finished, therefore you have PHPStorm open and a Vagrant box running.

 

Setting up xdebug on the server

Start your Vagrant box (Tools > Vagrant > Up) and log into your box via SSH (Tools > Start SSH session). As we have used Ubuntu 12.04 (Precise Pangolin) while installing this box, we can install xdebug easily with a one-line-command:

sudo apt-get install php5-xdebug
sudo service apache2 restart

Unfortunatly, we ll have to enter some configs into the php.ini manually now (why is linux/xdebug not doing this automatically ???). Open the php.ini with sudo rights:

sudo nano /etc/php5/apache2/php.ini

Your php.ini is somewhere else ? Find it that way:

find / -name 'php.ini' 2> /dev/null

Scroll down to the end of the file and add the following:

[xdebug]
zend_extension="/usr/lib/php5/XXXXXX/xdebug.so"                                  
xdebug.default_enable = 1                                                            
xdebug.idekey = "PHPStorm"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9000
xdebug.remote_handler=dbgp
#xdebug.remote_log="/var/log/xdebug/xdebug.log"
xdebug.remote_host=YYYYYYYYYYYYY

The path in the first line is the location of the xdebug.so file, you can find the path via

find / -name 'xdebug.so' 2> /dev/null

For easy handling simply mark the result of “find” with the mouse, it’s then automatically copied in the clipboard. The last line contains your IP, which means the public IP of your computer you are running PHPStorm on [it’s also possible using the private internal IP, but I’m not sure about it]. Find your IP easily via

http://www.whatismyip.com/

Note: Your IP might change every 24hrs, depending on your internet provider. When your scripts seem to “load forever”, then your IP might have changed.

Restart the server:

sudo /etc/init.d/apache2 restart

 

Remote debugging time

After you have restarted the apache, click on the little “telephone icon” in the menu bar in PHPStorm. PHPStorm will now listen for incoming debugging sessions (from the Vagrant server, which know your IP and will therefore be able to communicate with PHPStorm).
It’s extremely important to click that icon, otherwise a) PHPStorm will not be able to debug your remote code and b) your remote scripts will “hang” and wait forever… Set some red markers left to some lines in the code and run a php file on your server, like

http://192.168.33.101/index.php

and see the debugging box pop up in PHPStorm. Yeah! Business as usual here: Press the green triangle on the left side to go on with the application (F9) or press the red square to completely stop running the app (CTRL+F2). By the way, it’s also possible to override all markers with the two-red-circles icon or manipulate variables by right-clicking them.

 

When suddenly the server is “not reachable” anymore

Probably your IP changed and xdebug hangs therefore. Check your new IP and change it in the php.ini, restart the server. Everything should work fine now.

 

Share this

Quick fix for 404 error in WordPress category / tag page

Just a quick fix for a common problem: Sometimes, especially after switching themes, wordpress will generate 404 errors on the

[Link] Improving Smashing Magazine’s Performance: A Case Study

The title says it all: A very interesting guide through the optimization process on one of the largest blogs in

Material Design – How Google designed Android L (7min video)

A very interesting insight into Android L’s (= Android 5.0) new design and the ideas behind. Android was always #3

Beautiful, minimal WordPress theme ZUKI by Elmastudio (with 30% discount)

First a little disclaimer: I’m not affiliated with the company, don’t get money (or anything else) for saying this and

Google I/O 2014 – HTTPS Everywhere (video)

Excellent, essential and game-changing talk by Ilya Grigorik and Pierre Far (both of Google), explaining why you should always use

[Link] Making a website vertically responsive

Very useful tutorial by Ian Yates: How to make a website VERTICALLY responsive, adapting its content for small heights. Interesting

java

Interesting: code of the same application in PHP, Python, Ruby, Closure, node.js, Java and Go

Definitly worth a look: Adam Bard created a tiny application in 4 different languages (PHP, Python, Ruby, Closure), just to

hack-php

Wow! Facebook devs have rewritten and fixed PHP, releasing it as new language called “Hack” today

Exciting stuff is happening: Some years ago Facebook has released an early preview of HipHop, a virtual machine that precompiles

The architecture of StackOverflow

One of the most interesting talks these weeks, and a rare insight into one of the most active pages on

GitHub introduces revert button / rollback for merged pull requests

Once again GitHub delivers an excellent feature: Clean one-click rollbacks / reverts / undos of pull requests, very very useful,

1/4

Categories

Search

Soundcloud’s “VP of Engineering” about using SSDs
java
Interesting: code of the same application in PHP, Python, Ruby, Closure, node.js, Java and Go
Microsoft announces “holographic” 3D interfaces (promo video)
offf-2014
Europeans: Get ready for OFFF conference / festival in Barcelona, May 2014
php
Must-read PHP blog: PHPweekly.com
Adobe releases Firebug-like developer tools to edit and extract PSDs
pdo-debug
Debug PDO with this one-line function. Yeah!
ilovepreloaders – A tumblr collection of preloader animations
DigitalOcean coupon voucher 50
Only today: $50 coupon for DigitalOcean SSD VPS / hosting
php
New GitHub repo: simple php-long-polling for creating real-time apps
php
PHP 5.7 gets refactored core, is 10%-30% faster than PHP 5.5! Wow!
mod-rewrite-ubuntu-14-04-lts
How to enable mod_rewrite in Ubuntu 12.04 LTS
js javascript
How JavaScript really works – An introduction into the JavaScript call stack by Philip Roberts (20min video)
laracon-2014-eu-amsterdam
Laracon 2013 – Jordi Boggiano: In Depth Composer (47min video)
Berlin, prepare for TOA conference (15th – 17th of July)

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy