<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Phpstorm on PHP Boy Scout</title><link>https://blog-570662.gitlab.io/tags/phpstorm/</link><description>Recent content in Phpstorm on PHP Boy Scout</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><copyright>Matt Cockayne</copyright><lastBuildDate>Wed, 06 Feb 2013 00:00:00 +0000</lastBuildDate><atom:link href="https://blog-570662.gitlab.io/tags/phpstorm/index.xml" rel="self" type="application/rss+xml"/><item><title>Debug PHP CLI on Remote Server with Xdebug and PHPStorm</title><link>https://blog-570662.gitlab.io/debug-cli-remote-server/</link><pubDate>Wed, 06 Feb 2013 00:00:00 +0000</pubDate><guid>https://blog-570662.gitlab.io/debug-cli-remote-server/</guid><description>&lt;p&gt;This was a head scratcher when I ran into this yesterday and I thought I would share my solution to the following scenario:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;I need to debug PHP Command Line script, located on Remote LAMP Virtual WebServer running in Virtual Box with a Shared Folder, using local PHPStorm 5.0.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The solution:&lt;/p&gt;
&lt;p&gt;You first must set PHPStorm to use remote file paths. To set these go to the following:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;PHPStorm -&amp;gt; Peferences -&amp;gt; PHP -&amp;gt; Servers&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This gives the following display:&lt;/p&gt;
&lt;p&gt;&lt;a class="link" href="http://phpboyscout.uk/wp-content/uploads/2013/02/PHPStorm-Peferences.png" target="_blank" rel="noopener"
 &gt;&lt;img alt="PHPStorm Peferences" class="gallery-image" data-flex-basis="656px" data-flex-grow="273" height="312" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://blog-570662.gitlab.io/debug-cli-remote-server/PHPStorm-Peferences.png" srcset="https://blog-570662.gitlab.io/debug-cli-remote-server/PHPStorm-Peferences_hu_a6aad5ce5c233f20.png 800w, https://blog-570662.gitlab.io/debug-cli-remote-server/PHPStorm-Peferences.png 854w" width="854"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Replace the Name, Host and Absolute path on the server, to match your own settings. Note keep the Name and Host the same for ease.&lt;/p&gt;
&lt;p&gt;Next add some breakpoints in PHPStorm and set it to listen for any debug connections using the listener icon:&lt;/p&gt;
&lt;p&gt;&lt;a class="link" href="http://phpboyscout.uk/wp-content/uploads/2013/02/Listen-to-debug-connections.png" target="_blank" rel="noopener"
 &gt;&lt;img alt="Listen to debug connections" class="gallery-image" data-flex-basis="546px" data-flex-grow="227" height="90" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://blog-570662.gitlab.io/debug-cli-remote-server/Listen-to-debug-connections.png" width="205"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now login to your Remote Server via SSH etc.&lt;/p&gt;
&lt;p&gt;You now need to change settings for Xdebug in either xdebug.ini or php.ini depending on how you installed it. You also need to know the IP of the local machine. This can permanently set in the Network Setting of your VM in Virtual Box, so you will never have to change it. In my example the local machine running PHPStorm is:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;192.168.56.1&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now edit the ini file that contains your Xdebug settings and set the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;xdebug.remote_host = 192.168.56.1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;xdebug.remote_connect_back = 0
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;xdebug.remote_port = 9000
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;xdebug.remote_handler = dbgp
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;xdebug.remote_mode = req
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;xdebug.remote_enable = 1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;xdebug.idekey = phpstorm1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Be aware you might have to change the &lt;strong&gt;remote_host&lt;/strong&gt; and the &lt;strong&gt;idekey&lt;/strong&gt; based on your own environment. To better understand what each option does, see &lt;a class="link" href="http://xdebug.org/docs/all_settings" title="Xdebug Settings"
 target="_blank" rel="noopener"
 &gt;Xdebug Settings&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Finally, when running the script you must set the following variables:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;PHP_IDE_CONFIG=&amp;#34;serverName=dev.example.com&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;PHP_IDE_CONFIG will tell PHPStorm how to map the Remote File Paths to what it sees Locally. Again replace the URL with the Name/Host you set in PHPStorm. &lt;strong&gt;Note:&lt;/strong&gt; You can export this, if your system is only running one site; mine is not.&lt;/p&gt;
&lt;p&gt;You can run this inline with your script:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;PHP_IDE_CONFIG=&amp;#34;serverName=dev.example.com&amp;#34; ./testscript.sh
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This should send you to PHPStorm where you earlier placed breakpoints.&lt;/p&gt;
&lt;p&gt;Happy Debugging!&lt;/p&gt;</description></item></channel></rss>