Getting IDE like debugging behavior within VIM using php, xdebug, vdebug, and Ubuntu 12.4.

resources:

https://jtreminio.com/2012/07/xdebug-and-you-why-you-should-be-using-a-real-debugger/

https://github.com/joonty/vdebug

http://xdebug.org/download.php

Download the latest stable release of xdebug.


$ tar -xzf xdebug-file-you-downloaded
$ cd xdebug-2.2.2
$ phpize
$ ./configure --enable-xdebug
$ make
$ sudo make install

We’re looking for xdebug.so module and it should have been dropped into xdebug/modules after it compiles.
I moved mine into the following path: /usr/lib/php5/20090626/xdebug.so

Take heed on the above location as I initially installed xdebug from the ubuntu repos but it was not the latest version so i then decided to compile from source. I did a find on existing xdebug location which was the path shown above. I then replaced the old version with the newly compiled version.

Update php.ini:


zend_extension=/usr/lib/php5/20090626/xdebug.so                                 
xdebug.remote_autostart = On                                                    
xdebug.remote_enable = On                                                       
xdebug.remote_host = localhost                                                  
xdebug.remote_port = 9000 

restart apache

Use phpinfo() and check if xdebug modules are appearing.

Install vdebug for vim. Once this is done be sure your help tags are updated and run :help Vdebug . I read over this and it does a great job of helping setup your environment. The following is taken from the help file.

Setup a script that sits in your path to help debug:


#!/bin/bash                                                                     
export XDEBUG_CONFIG="idekey=xdebug"                                            
/usr/bin/php "$@"

Make the above executable and put it in your path somewhere. I called mine php-xdebug.

My optimal Vim configuration

Preferred color scheme: SOLARIZED
Other good tips.

Ubuntu terminal needs some setting adjusted for the colors to work correctly (drop into a terminal):


gconftool-2 --set "/apps/gnome-terminal/profiles/Default/use_theme_background" --type bool false
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/use_theme_colors" --type bool false
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/palette" --type string "#070736364242:#D3D301010202:#858599990000:#B5B589890000:#26268B8BD2D2:#D3D336368282:#2A2AA1A19898:#EEEEE8E8D5D5:#00002B2B3636:#CBCB4B4B1616:#58586E6E7575:#65657B7B8383:#838394949696:#6C6C7171C4C4:#9393A1A1A1A1:#FDFDF6F6E3E3"
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/background_color" --type string "#00002B2B3636"
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/foreground_color" --type string "#65657B7B8383"

To run solarized under tmux we need to add an alias to our .bashrc:


alias tmux="TERM=screen-256color-bce tmux"

Mass find and replace using grep for matching files that need to be changed and sed to make the change.

sed to replace characters in a file based on match.


sed -i "s,getenv('APP_PATH').\",\"/home/me/site.com,g" -i index.php

-i to replace the file inplace (careful, this will mangle your file if you mess up. I was using git to correct anything i destroyed).

The comma after the first “s is the delimiter and you can use whatever delimiter you like. You often see ‘/’ used here but that makes it difficult to match directory paths so i used a comma instead.

So to do a whole directory lets grep for the match first so we don’t process files that don’t need it.


grep -rl "getenv('APP_PATH').\"/inc/template" /path/to/directory

-r process recursivly.
-l only returns file names where the match occured wich we pipe to sed for processing.

Now lets put both commands together to complete our objective:


grep -rl "getenv('APP_PATH').\"/inc/file" . | xargs sed -i "s,getenv('APP_PATH').\",\"/home/me/site.com,g"

Backup based on existing UUID

Our raid copys to one of two existing exteral drives in the system based of UUID. If one or the other is plugged in, it detects the drive and rsyncs the raid to the drive. Just plug in the drive, remove the other and take off site. That simple.


#!/bin/bash

UUID=$(ls /dev/disk/by-uuid | grep 9702537b-b84c-44cf-b417-eaaf95a6d240) 
STATUS=$?
if [ $STATUS == 0 ] ; then
  echo "detected:$UUID"
  DEVICE=`ls /dev/disk/by-uuid/9702537b-b84c-44cf-b417-eaaf95a6d240 -l | awk -F/ '{print $NF}'`

  if [ _"`grep /dev/$DEVICE /etc/mtab`" = _ ] ; then
      echo "Device /dev/$DEVICE is not mounted"
      mount -t ext3 -U 9702537b-b84c-44cf-b417-eaaf95a6d240 /mnt/usb_raid_rotate_1 -o rw,acl
      if [ $? -eq 0 ] ; then 
        echo "Mounted $DEVICE" 
      fi
  else
      echo "Device /dev/$DEVICE is already mounted"
  fi

  echo '##############################'
  echo '  raid_copy_rotate_2 '
  echo '##############################'

  rsync -avA --delete -e "ssh -p 34011 -i /root/.ssh/identity" --exclude=vdi/ root@x.x.x.x:/mnt/raid5/ /mnt/usb_raid_rotate_1/full_raid_copy/
  if [ $? -eq 0 ] 
  then 
    echo "****************************  usb_raid_rotate_2 synced nicely" 
  else 
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!  errors while syncing usb_raid_rotate_2" 
  fi

  umount /mnt/usb_raid_rotate_1
  if [ $? -eq 0 ] 
  then 
    echo "****************************  usb_raid_rotate_2 unmounted nicely" 
  else 
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!  errors unmounting usb_raid_rotate_2" 
  fi
fi

UUID=$(ls /dev/disk/by-uuid | grep 668260a9-1f6e-4091-978e-89425ad33cf5) 
STATUS=$?
if [ $STATUS == 0 ] ; then
  echo "detected:$UUID"
  DEVICE=`ls /dev/disk/by-uuid/668260a9-1f6e-4091-978e-89425ad33cf5 -l | awk -F/ '{print $NF}'`

  if [ _"`grep /dev/$DEVICE /etc/mtab`" = _ ] ; then
      echo "Device /dev/$DEVICE is not mounted"
      mount -t ext3 -U 668260a9-1f6e-4091-978e-89425ad33cf5 /mnt/usb_raid_rotate_2 -o rw,acl
      if [ $? -eq 0 ] ; then 
        echo "Mounted $DEVICE" 
      fi
  else
      echo "Device /dev/$DEVICE is already mounted"
  fi

  echo '##############################'
  echo '  raid_copy_rotate_2 '
  echo '##############################'

  rsync -avA --delete -e "ssh -p 34011 -i /root/.ssh/identity" --exclude=vdi/ root@x.x.x.x:/mnt/raid5/ /mnt/usb_raid_rotate_2/full_raid_copy/
  if [ $? -eq 0 ] 
  then 
    echo "****************************  usb_raid_rotate_2 synced nicely" 
  else 
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!  errors while syncing usb_raid_rotate_2" 
  fi

  umount /mnt/usb_raid_rotate_2
  if [ $? -eq 0 ] 
  then 
    echo "****************************  usb_raid_rotate_2 unmounted nicely" 
  else 
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!  errors unmounting usb_raid_rotate_2" 
  fi
fi

My optimal Git configuration


git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

source: Bart’s Blog

Another format that is easy to pipe to email


git log --pretty=format:"%h%x09%an%x09%ad%x09%s"

Set git to always use vimdiff to merge conflicts.


git config --global diff.tool vimdiff
git config --global merge.tool vimdiff

Best way I’ve found to use vimdiff for fixing merge conflicts with vimdiff:

Have git automatically build your ctags file. Create a script called “.git/hooks/ctags”.


#!/bin/sh                                                                       
rm -f .git/tags                                                                 
ctags --tag-relative -Rf.git/tags --exclude=.git --languages=-javascript,sql -h ".php, .ctp" --PHP-kinds=+cf --langmap=PHP:.php.ctp

Set up these git hooks automatically on any new git init command.