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

  • PHP Caching Best Practices by Eli White (video from PHP UK Conference 2014)PHP Caching Best Practices by Eli White (video from PHP UK Conference 2014)
  • Postmodern PHP: appserver.io, a multithreaded application server for PHP, written in PHPPostmodern PHP: appserver.io, a multithreaded application server for PHP, written in PHP
  • Windows XP is officially dead from today. Do you know people still using it ? Punch them.Windows XP is officially dead from today. Do you know people still using it ? Punch them.
  • [german video] Modernizing and minimalizing frontend markup code at AutoScout24[german video] Modernizing and minimalizing frontend markup code at AutoScout24
  • PHPStorm 7 has been released!PHPStorm 7 has been released!
  • “Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem“Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem
  • How to show the available version of a package (before doing apt-get install)How to show the available version of a package (before doing apt-get install)
  • (Links) How to fix an extremely slow Symfony inside a Vagrant box(Links) How to fix an extremely slow Symfony inside a Vagrant box
  • A list of downloadable Vagrant boxes (CentOS 5.9 / 6.4, Ubuntu 12 / 13, Debian 6 / 7 / 7.1 / 7.2)A list of downloadable Vagrant boxes (CentOS 5.9 / 6.4, Ubuntu 12 / 13, Debian 6 / 7 / 7.1 / 7.2)
Share this

3 Comments

  • stef
    October 30, 2014 1:50 am

    Awesome. Thanks.

    Reply

Leave A Comment Cancel reply

css3-chrome-font

[Link] Retinafy your Site / Device by Nijiko Yonskai

A simple one-page Gist with all the information you need to make your sites retina-ready: Nijiko Yonskai – Retinafy your

Berlin, prepare for TOA conference (15th – 17th of July)

If you are in Berlin right now (and have 80-300 € to spend and 2-3 days of holidays (or “spontanious

New project: Building a naked PHP skeleton / boilerplate application from scratch

[This post is from November 2013. In the meantime (I’m writing this in November 2014) the project has changed its

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

Support FLARUM, the future of PHP forum scripts (with some dollars on Kickstarter)

PHP forum scripts are horrible, let’s face it. Nearly everything that’s available is hard to install, hard to handle, hard

Ghost

[FREE SERVER PROMO] Install GHOST for free on a free SSD server with this coupon

A little off-topic, but highly interesting: In April 2013 the former User Interface Head of WordPress (and WordPress expert) John

goodbye-lamp-going-hhvm-nosql-nginx-php

[RePost] Goodbye LAMP: Going Nginx, NoSQL, HHVM (41min conference talk with Arne Blankerts)

Another excellent find by Germany’s PHP Magazin in the article “Nginx, NoSQL, HHVM: Goodbye LAMP Stack?“: 41 minutes super-interesting (english)

php

[Link] Excellent PHP best practices, 2014 style

Excellent post on This interests me: A collection of useful best practices in modern PHP development, like Redirecting the user

php

Postmodern PHP: appserver.io, a multithreaded application server for PHP, written in PHP

There’s a lot of very interesting stuff going on in the PHP scene right now, I have the feeling this

mod-rewrite-ubuntu-14-04-lts

How to install / setup PHP 5.5.x on Ubuntu 12.04 LTS

Please note: This works fine. But this package will also upgrade your apache to version 2.4 which has different config

1/4

Categories

Search

php
How to prevent PHP sessions being shared between different apache vhosts / different applications
Bézier Curves – Under the Hood (4min video)
A quick history of Comic Sans, the most wrongly used font ever
php
How to setup / install PHP 5.6 on Ubuntu 14.04 LTS
Useful basic linux stuff: Show kernel version, distribution name and distribution version on Ubuntu systems
the-php-login-project
How to install php-login-one-file on Ubuntu 12.04 LTS
Compare 250+ cloud server plans with Cloud Cost Calculator
pdo-debug
Debug PDO with this one-line function. Yeah!
php
Postmodern PHP: appserver.io, a multithreaded application server for PHP, written in PHP
vagrant
A preinstalled Vagrant box with PHP HipHop / HHVM and Ubuntu 13.10 (Saucy Salamander)
modern-php
Creator of Slim framework and “PHP – The right way” writes book: “Modern PHP”, available 2015
vagrant
How to setup a local server (in a virtual machine) with Vagrant in PHPStorm
Create a fast, perfect and bootable 1:1 Windows backup (full clone of HDD) for SSD migration
composer
A short & simple Composer tutorial
php
How to use the PHP 5.5 password hashing functions

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 All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
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