Tag Archive: phpstorm


Editing CSV’s in PHPStorm

I was looking for a CSV plugin for PHPStorm, but it turns out there is no need. Open your CSV (which you associate with a plain text file), right click, and select edit as table!

Notice how much better that looks!

table

Configuring this REALLY did my head in,but in reality there are only a few steps to hook up your puPHPet Vagrant box (however miss something and you’ll be left scratching your head)  so here’s the quick vibe:

First up create a file in your site root called debugrun.php or whatever:

require_once 'vendor/codeception/codeception/autoload.php';

use Symfony\Component\Console\Application;

$app = new Application('Codeception', Codeception\Codecept::VERSION);
$app->add(new Codeception\Command\Run('run'));

$app->run();

Then goto Edit configurations in the debug menu.

Screen Shot 2015-09-28 at 23.44.41
replacing ‘yoursite’ with a valid path of course. Ok that and then go into your preferences. Click on deployment and connect with SFTP using your ssh key  puphpet/files/dot/ssh/id_rsa :
Set the path mappings tab to /var/www/yoursite or whatever.

Screen Shot 2015-09-28 at 23.47.31

Goto Languages > PHP and add a remote interpreter:

Screen Shot 2015-09-28 at 23.50.33

Lastly go into Tools SSH Terminal and choose default remote interpreter. Now hit the debug button and codeception should launch! Dont ask me how to change the terminal colours!

This is insanely easy to set up. Run this, or stick it in your .bashrc. If you are running your server on a VM or remote server, change localhost to the IP of your dev box.

export XDEBUG_CONFIG=”idekey=PHPSTORM remote_host=localhost profiler_enable=1″

Now you can start listening for conections in your IDE.

 

XDebug your Production Server

I love IRC. My friend just doesn’t get it however. But he isn’t looking in the right places.

For instance, we are having a hellish time with our server migration in work today. Our site was transferred to a bigger better CentOS cPanel server, only to act very strangely and mess up. Checking logs only tells us so much, so I tried to get XDebug installed on the server. I was having issues, and so went into freenode and joined the ##php channel, where I was redirected to #xdebug, where I received direct help from XDebugs main contributor, Derick Rethans! You couldn’t ask for better assistance!

Anyway, lets get it installed. Log in to your server as root, and download the xdebug source code. Then run the following from within the source folder:

phpize
./configure
make
make install

Then edit your php.ini, with the following:

zend_extension=xdebug.so
xdebug.remote_enable=On
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.remote_autostart=0
xdebug.remote_connect_back=0
xdebug.idekey = PHPSTORM
xdebug.max_nesting_level = 250
xdebug.remote_log = "/home/allagent/xdebuglog"
xdebug.remote_host = 127.0.0.1

Now there are a couple of settings to be aware of. As I am in work and behind a router, connect_back = 1 wouldn’t work. If you can set up port forwarding on your router, then do so! And remove the remote host 127.0.0.1 line. If not, we set it as 0, and set up an SSH tunnel. Derick sent me his blog link explaining how this is done so check it out here:

http://derickrethans.nl/debugging-with-xdebug-and-firewalls.html

In PHPStorm (you are using storm, right?), goto your run/debug configurations and add a PHP Web Application. I called mine LiveDebug, but you can call it whatever you like. In the server drop down, add your server, tick use path mappings,  find your index.php, and stick in the absolute path for the same file on the remote server (something like /home/username/public_html/index.php). You should do the same with the document root, which means it shopuld find all the rest without having to manually set each page/file.

Now for the good bit! Set a breakpoint in your code by clicking to the left of the code but to the right of the line numbers. A red spot should appear to signify you wish to pause the code at that point for inspection. Click the Run menu, and click debug. Then select LiveDebug, or whatever you called it. a browser window should open, and in Storm the debug frame will pop out. Click the variables tab. You can see every variable as it is set at that line of code. To the right of the tabs you have buttons for skipping over code, and stepping into functions etc! Have fun!

Now hopefully I can figure out why this new server is acting up!

I love LESS! However having to run lessc every time I edit my less file is LAME! Adding File watchers in PHPStorm means that when you save your file, it will automatically compile your CSS! We are also going to add Javascript and CSS minification, which helps increase page load speeds and also make it harder for nosey people to examine your javascript! Lets go!

First up, lets install node.js by visiting http://nodejs.org/
Next, we install less and yuicompressor:

npm install -g less
 npm install -g yuicompressor

Also on Windows, everything cracks up unless you add a PATH environment variable for the modules. In Control Panel in System, click Advanced System Settings, click Environment Variables and add the node modules folder to the PATH variable, or add it if its not there:

C:\Users\your.username\AppData\Roaming\npm

Go to File > Settings, and under the project settings look for File Watchers. Click the green + to add a watcher. Select LESS.

All that is required is that you put the correct path into the program field. This may be slightly different depending on your setup. For windows users, the modules can usually be found in :

C:\Users\your.username\AppData\Roaming\npm\lessc.cmd
 C:\Users\your.username\AppData\Roaming\npm\yuicompressor.cmd

And on linux machines, you can find it elsewhere. I cant remember offhand, but just take note of the output while you are installing it and you wont go far wrong.

Now you can edit the head section of your website, replacing style.css with style.min.css, and the same also for your javascript! Awesome 🙂