Archive for the ‘Tips and Tricks’ Category

PHP Remote CLI Script Debugging with PHPStorm

February 9, 2016 Leave a comment

PHPStorm is one of the best IDE’s to develop in PHP. I recently came across tons complex php cli scripts and needed a way to debug them.

Follow this PHPStorm Docs post first to set up php storm and the server.

Most important things to configure are

  • Set up xdebug correctly on the remote server. Dont use xdebug.remote_connect_back. Instead use xdebug.remote_host
  • Xdebug must be set up for php cli – check with the command php -i | grep xdebug and you should see many entries
  • Set up deployment path mapping correctly in your project settings – a lot of people miss this and wonder why debug is not working
  • Check your firewalls on both machines, make sure required ports are open, especially port 9000
  • Check debugger settings in phpstorm and make sure you have break at first line set up

In the PHPStorm tutorial, it asks you to set up SSH tunnel. If you are not doing tunneling, you should set these environment variables on the remote server

Eg, if my remote server is centos, i will set these 2 variables

export PHP_IDE_CONFIG="serverName=myDeploymentServerName";

serverName is the name of the server you set up for deployment in phpstorm deployment settings

these variables are valid for the session, if you logout and log in, you have to set them again.

You can add these to your .bashrc file in your home folder to make them permanent

In case you want to use xdebug.remote_connect_back, you might have to run your php scripts on the command line with additional args like this

php -dxdebug.remote_enable=1  -dxdebug.remote_host= -dxdebug.remote_connect_back=0 /path-to-php-script



Better Putty Color Scheme for existing Sessions on Windows

December 18, 2015 Leave a comment

Putty is a versatile tool for remote SSH access – however the color schemes are not too impressive. The blue especially is really bad. You can change the blue color in the settings but what if you already have a ton of putty Saved Sessions. You will have to painfully modify each. There is a better way by directly modifying the registry entry for all sessions at once.

I am doing this on Windows 7.
A word of caution, we will be modifying registry entries. I have done this many times without problems, however I will still say, do it at your own risk.

Right, lets get to it then.

Press Windows Key + R to get the Run prompt
Enter regedit and press Ok. This will open the registry editor
Navigate to HKEY_CURRENT_USER -> Software -> Simontatham -> PuTTY
Expand Sessions and you should see all your Saved Sessions listed there
Right Click on Sessions and select Export
Save the file as putty-original.reg somewhere where you can locate it
Dont modify this file, this is your backup file
If something goes wrong or you dont like the changes, you re-import this file and you are back where you started
Make a copy of the file call it putty-new.reg
Open putty-new.reg in your text editor ( i am using notepad++ or sublime )
This will have color value blocks for all your Saved Sessions.
You have to replace the entire color block with the new color block

Replace the color blocks with this new color block – do this for all color blocks


Once you have replaced blocks for all sessions in the file, save putty-new.reg
Double click on putty-new.reg to import the new settings.
Windows will ask for permissions and display warnings, go ahead click ok

Exit out of your current putty sessions and re connect.
You should see the new colors and color scheme.

If something went wrong, or you did not like the color scheme, double click putty-original.reg to get back to your old settings.
Keep putty-original.reg safely.

There are many links on the web which will let you build your own color schemes – try them

This color scheme I found here

Categories: Tips and Tricks Tags: ,

Linux Cron not running ?

April 13, 2015 Leave a comment

There are 2 ways to set up periodic cron jobs in linux

  1. Put them directly in the crontab
  2. Put them in one of the cron directories – below are available

So you can create a script and put it in one of the directories and they will run according to schedule

For example, if i put a script in cron.hourly, it will be executed hourly etc

Before you do that, you have to take care of the below things

  • Make sure your script does not have an extension, else cron might ignore it. If you have a script named, just rename it to myScript
  • Make the script executable, use sudo chmod +x myScript
  • If using bash script remember to declare the #!/bin/bash at the top

Once you copy your script to the required directory, use this utility to test and see if cron will execute your script ( change cron directory as required )

sudo run-parts --test /etc/cron.hourly

Your script should show up here – else it wont be run

Categories: Linux, Tips and Tricks

Windows 7 – record WAV files

February 24, 2015 4 comments

The default audio recorder in Win 7 save the file as WMA. However, you can use this simple command to record audio and save to WAV instead

Go to Start Menu search bar and type the below command and hit enter

soundrecorder /file output.wav

The recorder will open up – record your audio and it will ask you to save the file as a WAV file instead of WMA

Categories: Tips and Tricks

MySQL command prompt auto-complete

September 25, 2014 1 comment

If you work on the mysql command line, its nice to have an autocomplete similar to the linux bash where you press the TAB key and the commands complete.

In mysql, we can set it up to a degree to provide some hints when we type. Though it might not complete everything you type, it does complete table names etc.

2 ways to do it ( I am on CentOS 6.5 )

when you log into mysql, use the auto-rehash config option like

mysql --auto-rehash -u root -p

if this does not work, then try creating a file called .my.cnf in your home directory and put the below into it


Clear Screen for MySQL Command Prompt – Linux

On Linux, if you have logged into mysql on the command prompt  and want to clear all text on screen you can use

mysql> \! clear

\! system-command is the command format

\! tells mysql to pass the command to the system


[naveen@localhost ~]$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.73-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
| Database |
| information_schema |
| drupal |
| employees |
| mysql |
| phpmyadmin |
| test |
| zabbix |
7 rows in set (0.00 sec)
mysql> \! clear
Categories: MySQL, Tips and Tricks Tags: ,

MySQL root login without password

January 3, 2014 Leave a comment

You must be on localhost and have Linux root permissions

I had to create a MySQL account for myself on a Linux box. So here it is

# kill the running mysql process
sudo service mysql stop

# start mysql in safe mode and skip grant tables 
sudo mysqld_safe --skip-grant-tables --skip-networking &

# log in with root 
mysql -u root 

# ( optional ) flush privileges, create new user, grant privileges 
CREATE USER 'new-user'@'localhost' IDENTIFIED BY 'password';

# stop mysqld_safe process 
ps -A | grep mysql
sudo kill < mysql-pid-here >

# start mysql normally 
sudo service mysql start
Categories: Linux, MySQL, Tips and Tricks