Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Monday, January 05, 2009

Easy Remote PHP Debugging with VIM and Firefox

Happy new year !

I've write a post bout how you can setup debugging environment for PHP using xdebug, so now assuming you have xdebug setup and loaded, I'm going to write bout how you actually debug your PHP code.

Basically there are 2 type of debugging, local or remote debugging, the difference is that whether or not the debug engine separated with the debug client. If you debug a desktop Java code using IDE like Eclipse, most likely you are doing local debugging, where as the debug engine comunicate directly to the eclipse interface (there is no need of debug client). XDebug is a remote debug engine, which mean to actually debug some code we need a debug client to send command to and receive debugging information from the debug engine. From XDebug page we can get alot information bout how this can work, and some option of debug client that you can use (this page should be your first reference).

Now lets get to the chase, I'll write about how to have a remote debugging session with Vim (with plugin) and firefox to debug your PHP code easily.
  1. After you have successfully load xDebug module into php, enable remote debugging in your php configuration (php.ini) by adding
    xdebug.remote_enable = "1"
  2. download the debugger plugin (or watch my blog for an update)
  3. extract the file (debugger.vim and debugger.py) to your home vim plugin directory
    $ unzip debugger.zip
    $ cp plugin/debugger.* ~/.vim/plugin/
  4. fire up Vim!, make sure your build equiped with signs and python support or the plugin won't work!, I'm using ubuntu and a Vim-full package for this, no hush, no mush..
  5. if vim loaded without any error it means the plugin already loaded correctly, if not check your vim build, make sure the +signs and +python is there when you type in vim command
    :version
  6. open firefox, and install this addon
  7. open the PHP application you wish to debug using firefox, make sure the source code is accessible. for example if the source is in (assume you are using xampp)
    /opt/lampp/htdocs/testdebug/index.php
    then you can type in firefox url
    http://localhost/testdebug/index.php
  8. click the xdebug helper icon (the one you've just add) on firefox status bar (default on lower right corner), now the icon should flash green
  9. switch to your vim window and press F5 (the message window would say waiting for connection...)
  10. switch to your firefox window and reload by pressing F5,
  11. now switch to your vim window (again) and there you have it, a debugging interface of your application in vim.
let me explain a few of those steps a little bit (step 1 to 7 should be clear enough), step 8 means you have start a debugging session for the next http request, it is the same as if you append the url with XDEBUG_SESSION_START=1 so the url would be
http://localhost/testdebug/index.php?XDEBUG_SESSION_START=1
ofcourse clickin on xdebug helper icon is alot more convenience than appending the url each time we start a debugging session.

now for step 9 we prepare our beloved Vim to wait a connection from the debug engine at this point vim will kind of hang (waiting mode), the script default timeout is 5 second, if within that there are no debugging session requested, vim will return to normal mode. This means than we have to quckly run step 10, switch to firefox and reload, but again make sure the xdebug helper icon is already flash green (activated/clicked). After you have reload the page if you notice the loading status of the page is keep on spinning, the page wont finish loading until the debugging session stopped or vim is closed or request timeout

Now if we switch back to Vim, our debugging interface should up and running there are source, watch, help, stack and trace window. From this interface you can trace the code using F2 (step into), F3 (step over), F4 (step out). To end a session you can press F6. One of most common task is to put a breakpoint in our code, to do that open the file you wish to debug, position your cursor on a line you wish to stop and type :Bp in vim command window, now everytime the debugging session start, just press F5 to run until execution point reach the breakpoint. You can see other debugging command from the help window.

one thing about this vim plugin, there aren't that much debugging command available, either from the plugin or xdebug itself, from what I can tell it is more than enough to do my daily-debugging-basis. There are some lacks though, but I'll address this issue later on, considering this post is already bloated enough to make people sick from reading it :p

happy vimming (and debugging) !

keyword: ubuntu, vim, firefox, xdebug, php

Tuesday, October 21, 2008

VIM

Since my migration to linux I've set myself on a quest to find the ultimate text editor (haiiah, lebay :p). well anyway I have my own requirement for such a tool
  • lightweight and fast
  • syntax highlighting and formatting
  • tab-editing
  • auto-complete
  • flexible and configurable (support custom script)
when I'm still using windows, I didnt really pay attention on those criterias, coz most of the time I'm stuck with an IDE(not just a text editor). Komodo, eclipse to name a few. and just lately I realized that most of the tool those IDE provided is less usefull for me(well mostly because some of em isn't free :D), I just need the editor, and yes syntax highlight and formatting is a tempting feature for sure. So I started to googling, to find a good editor which presumably free, been trying this and that, and there it is VIM !.

VIM (Vi IMproved) is a console based / command line editor a charityware wrote by Bram Moolenaar, and available as default in most of linux distro (the silly part is that the whole time the one I'm looking for is right under my own nose yet I'm searching or downloading from various places). With a default plugin gVim (gnome version of vim) load up less than a second in my 1420 inspiron box, whoossh.... It support syntax highlight and formatting for most of programming/scripting language, and my favorite is the omni completion feature, its an auto-complete feature with a dozen of option and preferences to suit my need, it can use a dictionary file or just simply scan a whole directory to find the completion words.

Highly configurable, vim support custom script called vimscript (beside it's support on phyton, perl, and other script), which make it a lot more usefull for many editing purpose, theres a lot of ready made script from it's main site, some of the script I've been using are
  • NerdCommenter, this plugin helps to do any function of commenting and uncommenting, and it support comment for huge number of programming language and script,
  • snippets_emu, this is a wonderfull one, just type few letter and shift+tab(my mapping keys) and boom!the whole snippet of code is there! save a lot of time of typing, you could define your own snippet especially for something you'd type frequently
  • NerdTree, its like an explorer built in the editor, you can browse file and directory from it
  • TagList, you can tag a file of code or a whole directory ( in *nix u can use ctags), and jump between various tag in a file, this is a lot faster than using pageup-pagedown, or scrolling your mouse up and down to go to different section in your file
  • VimTip, for any of you that just start learning vim this plugin is a must!, every day it pops a tip bout what you can do with vim, contributed from various user all over the world.
  • and a lot of any other I cant mention here, I cant thx enough to every of you that develop these vimscript and plugins !
One unique thing about it, is that VIM is a modal-based editor, which means it responds input differently based on its mode(state), for example vim has (from several other modes) input-mode and command-mode, when in input-mode vim behave like any other editor, everything I type is considered as text input, but when in command-mode the typing goes as command, I love it so much coz it allows me to use most of vim's editing function without have to move my finger off my keyboard home keys !!, it makes editing process a lot more efficient!

Gosh, theres a lot of feature and advantage I just wont have enough time and space to tell em all, and yes, every day I always learn something new bout this editor, not so much different with most of you, I'm still a newbie vimmer.

Well, I have admit there are some drawback. The first maybe because of the learning curve, it takes some amount of brain power to at least start editing efficiently, and for me, it kind of hogging my short term memory the first time I learned it(but trust me, its a worthy investment)

until the day I post this, vim development is still going active (thx Bram!!), the last stable version was Vim 7.2, unfortunately it seems ubuntu wont put these updates in the main repo for at least another release cycle, well we can always download the source and compile it for ourself cant we :p

happy vimming !!

Friday, June 06, 2008

java 6 + applet + firefox 2 = hang

fyuuuh...

finally I can get my applet working in firefox,

I'm writing an applet application in my ubuntu box, and here's the first configuration
  • eclipse 3.3
  • jdk1.6.0_03
  • firefox 2.0.0.14
  • sun java plugin 6
I can write, compile and run the applet using applet-viewer built in eclipse, but some how everytime I try to deploy the applet to a web page, and view it with firefox, it crash! even until now I dont know why it crashed, been searching on forum and googling, I didnt find anything sufficient to solve my problem(or just me being dumb).. I was thinking maybe theres something wrong with java6 especially with applets, because not only my applet wont work, applet from another site doesn't work either(I've tried with realapplets).

so, I tried my luck with java5, and here's the second configuration
  • eclipse 3.3
  • java-1.5.0-sun-1.5.0.13
  • firefox 2.00.14
  • sun java plugin 5
I've flush everything related with java6 in my laptop away, and replace it with java5, and ofcourse change the default java build path on my eclipse. I can write it compile it, but can't run it!!, it says

java.lang.UnsupportedClassVersionError: Bad version number in .class

oops, forgot to change the JDK compliance setting on my eclipse from 6.0 to 5.0 (window->preferences->java->compiler), voila, it run :)

if any of you wondering whats the error above, basically because you've build a java program using newer compiler, but running it under older jre. For example you've compiled your program using JDK 1.6, on eclipse, and when you tried to run it with your default jre set to 1.5, then you'll get those error throw at you.

And yes, with java5 I was also able to run applet from another site..
so for now my conclusion is,
don't use java6, if you want to write, or run applet application
I hope they'll fixed it soon..

and just a tip:
when you deploy your applet on web page, if you've put your .class file(s) under a directory inside your web root, don't prefix the code properties of applet tag with "./", or browser will say applet loading failed.
dont use :
<applet code="./control/HelloWorld.class" height="400" width="400"></applet>
instead use :
<applet code="control/HelloWorld.class" height="400" width="400"></applet>

keyword : applet, firefox, java 6 plugin, ubuntu, hang, crashed

Monday, April 28, 2008

gnome-network-manager vs wicd

here's some sort(maybe a little bias)review bout network manager in ubuntu.

the first, and the default one is gnome network-manager, its suck!, especially its trey icon(nm-applet), because most of the time it just hang, I cannot disconnect without have to wait, and then it doesnt always succesfull, switching between available wireless network is a PITA! when i kill my wifi using it's switch while it's still connected, nm-applet just hang. the network manager had profile feature, so that laptop user can easily switch their network places, Dunno bout you guys, but the profile thing never really work for me. although the functionallity is sufficient, personally I'm not quite comfortable with it.

luckily theres another alternative called wicd this network manager gives me full control bout my network, i can connect and (specially) disconnect at any given time i wish to be, and it just felt more responsive. wicd based on gtk, so theres no dependency on gnome, most of window manager can easily use it(although GTK is required), it also provide a working profile feature, the only drawback is that wicd doesnt detect my wifi interface automatically like gnome network manager does, but we can easily enter the interface name manually in its preferences window. Just try it.

keyword: nm-applet, wicd, network manager gnome

Tuesday, April 08, 2008

My harddrive is killing it self !!

this is a shocking news -for me atleast-, just found out that there are some cases, where people using ubuntu on their laptop had some issues with their harddisk. unfortunately those people include me T_T...


i've learn that my harddisk come with installed firmware that control power_management so called APM(advanced power management) most of modern harddisk does, so what this APM do? dont know exactly but from what i've read it control anything that can be set in harddisk's firmware to reduce power consumption, one of them is how often a head of an harddisk parked(stop hovering on the plate). The more often harddisk's head parked, more power are saved -CMIIW-, an this is the one that cause trouble. Because default power_management setting on my laptop's harddisk is just to aggresive, it keeps parking it head down even when i'm still using it!, i can tell this from looking at my harddisk loadcyclecount, time to time.


$ sudo smartctl -a /dev/sda | grep Load_Cycle_Count

this number increasing too fast! about 1 load cycle per-minute O.o!!
Yes this will save power -eventually also reduce harddisk temperature- but the scary thing is, this number is limited! average modern harddisk's max loadcycle is at least 600.000, so if i calculate my harddisk will only last for about 3-4 years max!!. I just dont like it!, luckly theres a workaround(ofcourse there's always a workaround :p), first check your default apm value(just incase something went wrong)

$ sudo hdparm -I /dev/sda | grep Advanced

then, we can just shut down apm with (they said this wont work in some laptop)

$ sudo hdparm -B 255

or use less aggresive setting (this one work for me)

$ sudo hdparm -B 254

one thing to kept in mind, this setting may increase harddisk's temperature, and this may do more harm than good, so make sure you really want to do this, and do this carefully! keep watching your harddrive status(loadcycle, temperature, etc..) use smartctl for this, until you sure this is ok! otherwise revert back.



if above configuration is working for you we can make this a little easier and automatic. make sure you have laptop-mode-tools installed


$ sudo apt-get install laptop-mode-tools

then edit file /etc/laptop-mode/laptop-mode.conf

# let laptop-mode tool control power management setting
CONTROL_HD_POWERMGMT=1

# this is hdparm -B values, use your own configuration with care
BATT_HD_POWERMGMT=128 # value to be used in battery mode
LM_AC_HD_POWERMGMT=254 # value to be used in AC mode with laptop-mode enable
NOLM_AC_HD_POWERMGMT=254 # value to be used in AC mode without laptop-mode

then, update file /etc/default/acpi-support, and change the value in line

# off by default
ENABLE_LAPTOP_MODE=true

reboot.



hmm, thats about it, my opinion is this isnt ubuntu's bug, because ubuntu doesnt change nor override harddisk firmware configuration, it is left as is, (well.. maybe they should)

Monday, March 24, 2008

XAMPP+XDEBUG+UBUNTU

ok, my ubuntu seem to work as expected(after 3 day struggling with the network !^^). so now i'll just take a break and writing down some small, common, boring, newbie tutorial :)

hmm.. the first thing that i want to do with this box, is to do some PHP coding, and debugging. To accomplish this one could just do

$ sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server
to install LAMP(Linux, Apache, MySql, PHP), and there you have it, simple huh? i remember doing this in slackware few years back ^^. next just start the apache, and mysql services by doing
$ sudo /etc/init.d/apache2 start
$ sudo /etc/init.d/mysql start

you might want to change default root password for mysql database by
$ mysqladmin -u root password newpasswd

now debugging part, I've been using xdebug for the last year, before that I used DBG, my personal opinion, xDebug felt better, cause its free and opensource. but before we can debug our code, we have to install it first by downloading the source for linux(in windows box, I've use the precompiled binary one) from hereTo install and configure xdebug for our local server is straight forward, I'll try to brief it here(you could see the README file in the tgz file for complete how-to)
  1. unpack the tarball, and cd to it
  2. run phpize ( if you have install php with apt-get this shouldn't be a problem) to generate configure script
  3. run ./configure, next run make, and there you have it, xdebug.so on modules directory
  4. then open /etc/php5/apache2/php.ini, using your fav editor
  5. add the line
    zend_extension="/wherever/you/put/it/xdebug.so"
  6. restart apache with
    $ sudo /etc/init.d/apache2 restart
  7. xdebug, should be loaded, you can check using phpinfo()on your page script, and search the XDebug section on that page
fyuhh.. now thats a brief ^^

the problem is, i didnt use ubuntu's LAMP :), I'm using XAMPP for Linux, formerly known as LAMPP, why ? because they have it all here, PHP4, PHP5, LAMP, ProFTPD, and PHPMyAdmin, sweet! just install it and you'll have the whole family with you.

Then why is it, using XAMPP for linux than Ubuntu's LAMP would be slight a problem? because if you only download the xampp default package, you cant compile xdebug o.O !!. To compile xdebug you need the XAMPP source (development package), so here's another brief way to install XAMPP and xDebug on ubuntu
  1. Download XAMPP for linux, and XAMPP development package from here
  2. Untar both tarball into /opt/ directory with (this is a must)
    $ tar -xzvf xampp-linux-1.6.6.tar.gz -C /opt
    $ tar -xzvf xampp-linux-devel-1.6.6.tar.gz -C /opt
    and you'll have /opt/lampp/ directory
  3. at this point you already have local server setup, you can check whether its working or not by
    $ /opt/lampp/lampp start
  4. unpack xDebug tarball, and cd to it(wherever you unpack it doesnt matter)
  5. run XAMPP's phpize to generate configure script(there's a slight different here)
    #pick one
    $ /opt/lampp/bin/phpize-5.2.5 #if you use php 5
    $ /opt/lampp/bin/phpize-4.4.8 #if you use php 4
  6. run
    $ ./configure --with-php-config=/opt/lampp/bin/php-config
    $ make
    and there you have it xdebug.so on /opt/lampp/modules directory, remember!, if you try to build xdebug package without aqquiring XAMPP development package, you'll stumble with some error that said missing this, missing that, etc..
  7. then open /opt/lampp/etc/php.ini, using your fav editor
  8. add the line
    zend_extension="/wherever/you/put/it/xdebug.so"
  9. next start your server, just like step #3
  10. done :)

ok, i might be missing some detail back there, (just typing what's in my head ^^), anyway the idea is, if you want to compile xdebug, you'll need PHP's sources (my case it was XAMPP development package)

have a nice day.. :)

Wednesday, March 19, 2008

Finally! migration!

at approximately, Sunday march 16 10am, i have execute single entry on my wish-list, that is migration to Linux!!


so which distro?


my first love was slackware, but i choose Ubuntu Gutsy Gibbon, cause actually i did (*try) to migrate before, using Slackware, but found a little cumbersome, instead of actually "work with it" my time waste tryin to "make it work" !, and yes i am definitely a noob, and yes i will give slackware another shot, but for now i have more important things to finish, than just some obsession ^^


so i hope i can get down to "business" with this babe :p


wish me luck !