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
3

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.

 

This article was written quite a while ago (9 years), please keep this in mind when using the information written here. Links, code and commands might be outdated or broken.

Random articles

  • Hacked french TV channel exposed passwords in TV interview (video, screenshots, links)Hacked french TV channel exposed passwords in TV interview (video, screenshots, links)
  • Extremely simple deployment with PHPloyExtremely simple deployment with PHPloy
  • GitHub introduces revert button / rollback for merged pull requestsGitHub introduces revert button / rollback for merged pull requests
  • Adobe offers Photoshop for $9.99 per month (limited deal)Adobe offers Photoshop for $9.99 per month (limited deal)
  • How to install latest PHP 5.4.x on Ubuntu 12.04 LTS (Precise Pangolin)How to install latest PHP 5.4.x on Ubuntu 12.04 LTS (Precise Pangolin)
  • Berlin, prepare for TOA conference (15th – 17th of July)Berlin, prepare for TOA conference (15th – 17th of July)
  • How to show memory usage (Ubuntu)How to show memory usage (Ubuntu)
  • Dangerous Performance Myths in the Web (video talk by Thomas Lohner, PHPUG Latvia)Dangerous Performance Myths in the Web (video talk by Thomas Lohner, PHPUG Latvia)
  • A quick guideline on how to fix the Hearthbleed bug (and update OpenSSL) on UbuntuA quick guideline on how to fix the Hearthbleed bug (and update OpenSSL) on Ubuntu
Share this

3 Comments

  • stef
    October 30, 2014 1:50 am

    Awesome. Thanks.

    Reply

Leave A Comment Cancel reply

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

ilovepreloaders – A tumblr collection of preloader animations

An excellent collection of preloaders (GIFs, Movies and real ready-to-copy&paste code) here in this wonderful blog: http://ilovepreloaders.tumblr.com/ This thing just

php

How to install the mcrypt php extension (to use Laravel 4)

When installing Laravel 4 on a fresh Ubuntu or Debian system, you’ll probably get this error message: “Laravel requires the

hearthbleed-ssl-bug

A quick guideline on how to fix the Hearthbleed bug (and update OpenSSL) on Ubuntu

If you still haven’t fixed your servers after mainstream discovery of the legendary Hearthbleed bug, then do it now –

vagrant

A preinstalled Vagrant box with PHP HipHop / HHVM and Ubuntu 12.04 (Precise Pangolin)

This is the same post like this one, but this time with Ubuntu 12.04 Precise Pangolin. If you need to

js javascript

Push database changes to all clients in real-time (!) with AngularJS and Firebase

The coolest talk I’ve seen this week: Anant Narayanan of Firebase shows how to build a simple but really impressive

digitalocean coupon

Free $10 coupon for DigitalOcean SSD cloud VPS hosting

DigitalOcean puts out another coupon, this time for free $10 with the code SSD2014. The company offers small and big

php

Awesome list of Design Patterns with PHP code examples

Probably one of the most useful GitHub repositories ever: Dominik Liebler has published a well-reseached and well-written (PSR coding guidelines

php uk conference

PHP Opcache Explained by Julien Pauli (video from PHP UK Conference 2014)

The title says it all. A VERY deep explanation on how OpCache works. If you never heard of this excellent

Meet the developers behind Ableton (14min video)

An excellent short documentation about the developers behind Ableton, the legendary creators of Ableton Live and Push. Without doubt, Live

1/4

Categories

Search

zend framework 3
First view on Zend Framework 3 by Matthew O’Phinney
“Fuck you. Pay Me.” How to deal with clients, the professional way. An excellent talk with Mike Monteiro.
O’Reilly’s Learning JavaScript Design Patterns by Addy Osmani for free
js javascript
Push database changes to all clients in real-time (!) with AngularJS and Firebase
phpstorm 7.0 php
PHPStorm 7 has been released!
bitdeli git github stats
php-login goes #2 PHP script worldwide in BitDeli stats
How to show the available version of a package (before doing apt-get install)
set up a local virtual machine for development with vagrant and puphpet / puppet (and ubuntu, linux, php, apache, mysql)
A super-simple pre-configured Vagrant box with HipHop, Hack and Hack code examples
All new features of WordPress 3.9 in this 2 minute video
hiphop php
[Link] How to set up HipHop, Nginx and Laravel in Ubuntu 12.04 LTS (in a Vagrant box)
vagrant
A preinstalled Vagrant box with PHP HipHop / HHVM and Ubuntu 12.04 (Precise Pangolin)
Quick fix for 404 error in WordPress category / tag page
php
Is there a JSFiddle for PHP ? Yes !
JavaScript ECMAScript6 – A short video introduction (5min)
the-php-login-project
How to install php-login-one-file on Ubuntu 12.04 LTS

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
 
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT