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
redaktionelle-hochlastseiten

Hochlastseiten mit PHP, MySQL und Apache am Beispiel stern.de (deutscher Artikel)

Eine grandiose Powerpoint-Präsentation die sich jeder, der mit PHP, MySQL und Apache auf Linux arbeitet, mal anschauen sollte: Nils Langner,

php

12 tools for better PHP quality

Nice selection of 12 tools every PHP developer should bookmark. I totally love how the PHP community becomes some kind

composer

The difference between “composer install” and “composer update” – nailed on the head

What a beautiful, direct and clean explaination of the often-confusing difference between composer install and composer update: Beau Simensen (Twitter,

How to fix the ugly font rendering in Google Chrome

Update, August 2014: Google has rolled out Chrome 37, which finally fixes this issue nativly. Yeah! For historical reasons the

How to get a single table out of a massive MySQL .sql database backup file (mysql dump splitter)

Imagine the following situation: Somebody backs up an entire MySQL database – a very large one – with common tools.

js javascript

JavaScript Testing Tactics (21min video by Justin Searls)

php uk conference

PHP Caching Best Practices by Eli White (video from PHP UK Conference 2014)

The title says it all: PHP Caching best practices.

ubuntu-14.04-lts

First view: Ubuntu 14.04 LTS brings PHP 5.5 and Apache 2.4

Short first view on Ubuntu 14.04 LTS (= long term service): I just tried out the alpha1 version of the

bitdeli git github stats

Get visitor stats for your GitHub repo with BitDeli

GitHub is the definitive #1 “hoster” for git repositories, no question. And this highly sympathic company has made version control

Hacking ATMs – A conference talk about the current security state of Windows XP driven cash machines

A few days ago the 30th edition of Germany’s Chaos Communication Congress took place, a high-profile event for IT-security and

1/4

Categories

Search

phpstorm 7.0 php
How to setup and use XDEBUG with PHPStorm 6/7 (locally in Windows 7/8 and Mac OS X)
compress-png
Compress png, jpeg, gif and svg up to 90% with Compressor.io
css3-chrome-font
Google rolls out Chrome 37, finally fixes horrible font-rendering
steam sale coupon voucher
-30% to -90% on Steam and Origin
sass
New features in SASS 3.3 (a talk by SASS-creator Chris Eppstein)
Ghost
[FREE SERVER PROMO] Install GHOST for free on a free SSD server with this coupon
git-php-deployment
Extremely simple deployment with PHPloy
How to hack time (KUNG FURY promo campaign)
bash-command-line-tutorial
Best introduction to unix command line / bash ever (by André Augusto Costa Santos)
php
How to install/setup latest version of PHP 5.5 on Debian Wheezy 7.0/7.1/7.2 (and how to fix the GPG key error)
O’Reilly sells EVERY ebook for -50% right now!
mod-rewrite-ubuntu-14-04-lts
EOL lists of Ubuntu, Debian and CentOS for your server plannings
hiphop php
Vote for “Hack” for HipHop/HHMV support (future style PHP) in PHPStorm 8
vagrant
Generate Vagrant boxes with Laravel, HipHop, Nginx, WordPress, MySQL, MariaDB, MongoDB, RabbitMQ etc. with one click
php
Somebody is writing a compiler for PHP, compiles down to machine code, outperforms HHVM

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