Debugging PHP in Quanta Using xdebug

Quanta is a full featured KDE programming editor. Quanta now has support for DBGp debugging protocol. Install quanta by by issuing following command.

sudo apt-get -y install quanta

Configuring xdebug

Install xdebug using previous blog post on Debugging PHP using xdebug. After installing xdebug add following configuration options to your /etc/php5/apache2/php.ini.

xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.remote_port = 9000
xdebug.remote_host = localhost

Now restart your apache using following command.

sudo /etc/init.d/apache2 restart

Configuring quanta

You can debug php scripts only in projects. Create a new project in quanta and add /var/www to it. Open project properties, select DBGp from Debugger combo box and accept remaining default settings. If you followed previous steps and debugging on local machine then you don't have to do anything else. If you have to change debug port and server url then click on Options button and change those settings.

By now you should have a debug menu and debug toolbar. If quanta is ready for debugging then all those debugging buttons on toolbar will be enabled by default. If not then start a new debug session from debug menu in menubar.

From now you can set breakpoints, watch variables and get call stack(backtrace) information during debug session.

Generate "lorem ipsum" in unlimited quantity

lorem ipsum generator is used to generate lots of dummy text to fill gui and web desgins.Lorem Ipsum generator is a an application hosted on Google code. It generates lots of dummy text that can be used to fill your GUI designs and web page mockups. This text is particularly useful in designing gui with out any distraction.

Installation

Get lorem ipsum generator deb package from following link

http://code.google.com/p/lorem-ipsum-generator/

Now click on downloaded to deb package to install it in GUI way.

Usage

Just launch the application using the command lorem-ipsum-generator. After launching your application you will be presented with options to generate either Paragraphs or Sentences with specified quantity. Later you can copy generated text to clipboard and use it in your application design.

How to setup lighter, faster & minimal Ubuntu

ubuntu penguin march

There are many variants of Ubuntu. One of them is Ubuntu JeOS where JeOS stands for Just enough Operating System. JeOS is a lean version of Ubuntu server and optimized for running in virtual machines like VMWare. But it can also be used to setup your own Ubuntu that matches your taste without extra luggage. I will get you started by showing you how to setup minimal GUI. Later you can make customizations by installing applications that you like. So lets get started.

Download Ubuntu JeOS

Download Ubuntu JeOS iso image from following url and install it either in VMWare or VirtualBox.

Download Ubuntu JeOS

Installing GUI

This part of guide can be used to install GUI on ubuntu server. First update your apt cache by issuing following command.

sudo apt-get update

You may install either xdm/gdm/kdm for login manager. Since xdm is lighter than others I prefer installing it.

sudo apt-get -y install xdm

Install core of gnome with out any extra baggage.

sudo apt-get -y install gnome-core

Install xorg since gnome needs it.

sudo apt-get -y install xorg

Your gui setup is now complete but since we didn't install any theme default desktop is not that eye friendly. Just install Ubuntu human theme by issuing following command.

sudo apt-get -y install human-theme

Start xdm by issing following command.

sudo /etc/init.d/xdm start

Your basic Ubuntu desktop now ready without extra baggage like open office and other applications. This basic setup works nicely in either VMWare or VirtualBox. Remember to install either VMWare or VirtualBox guest addons to speedup your virtual machine.

Art work used in this post is cc licensed and you can get it from flickr.

phonetooth: Chat with mobile users

phonetooth on ubuntu, transfer files, chat with others using bluetoothphonetooth can be used to chat with mobile users and transfer files from ubuntu desktop system. Its written in python. phonetooth uses gammu as its backend and because of this reason it supports most of the phones from Samsung, SonyErricson, Nokia & Motorola.

Installation

Download sources from Google Code and unpack. Now execute following command to prepare build environment

./configure --prefix=/usr

Now execute following command to install it.

sudo make install

Circular Menu for Gnome

circular application menuThere is a new circular menu project that is being hosted on Google code. This program runs in composite environment like compiz. Currently there is no package for this application you have to compile and run it from command line. You can navigate this application by using keyboard keys PageUp, PageDown,Home & End keys.

Visit Circular application menu project.

Guide to Faster Ubuntu

Optimize ubuntu boot sequence by profiling it

  • While you are in grub menu highlight your preferred kernel version and press "e".
  • Highlight the line beginning with kernel and press "e" again. Press End key in order to goto end of that line.
  • Add a word "profile" without quotes to that line and press Enter.
  • Now press "b" to continue booting.

This one time special boot may take more time than ordinary boot. But during this boot ubuntu monitors file usage and preloads those files during subsequent boots.

prelink

Any executable that makes heavy use of shared libraries can benefit from prelinking. Prelinking resolves addresses of shared libraries in advance this reduces number of relocations.

Prelink is also useful in the context of security since we can tell prelink to make libraries load at random addresses until next run of prelink. This is useful since libraries won't load at fixed addresses on every system.

You can install prelink by issuing following command.

sudo apt-get -y install prelink

Change a line inside the configuration file /etc/default/prelink from

PRELINKING=unknown
to
PRELINKING=yes
We will do our first prelinking by executing following command
sudo /etc/cron.daily/prelink

Thats it you don't have to do anything else. Prelink daemon will run periodically to optimize your newly installed executables.

preload

Preload is a little application that monitors files of frequently used applications and and loads them in to the memory when system is idle. This usually results in lesser startup times for those applications. Install preload by executing following command.

sudo apt-get -y install preload

deborphan: Find orphan packages

After doing several installs and removes apt leaves lot of packages that are not needed anymore. You can find these packages using deborphan. Install deborphan by issuing following command.

sudo apt-get -y install deborphan

Now to see the list of packages which are not needed anymore just run following command.

deborphan

To remove these packages give following command.

sudo apt-get remove `deborphan`

To get full list of packages that are not essential for functioning of the system execute the following command.

deborphan --guess-all

This command will list data,dev and many other types packages that are not essential for system functioning. Please see man page of deborphan to find out more options.

localepurge

Remove locale information(language tables) of the applications that are not needed for you. localepurge maintains specified locales and removes the remaining. To install localepurge issue following command.

sudo apt-get -y install localepurge

During installation localepurge will ask you to select locales that you want to preserve. At this step select what you need and press OK. From now on localepurge will maintain only those locales which you selected during configuration step.

Use Flickr Images as Ubuntu Wallpapers

webilder logowebilder is a convenient little application that downloads and sets flickr photos as your desktop wallpapers. webilder no longer provides repository sources for either gutsy or hardy. But getdeb provides Debian packages for both gutsy and hardy including 32 & 64 bit architectures.

Installation

Goto http://www.getdeb.net/app/Webilder and download debian packages that correspond to your processor architecture & ubuntu version. Now install both webilder & webilder-gnome packages using following command.

sudo dpkg -i webilder*.deb

Usage

Gnome applet list Click on your gnome panel add choose +Add to Panel menu item. You will see list of gnome panel applets. Select Webilder Desktop Applet and drag and drop it on to gnome panel. Right click on webilder icon on gnome-panel and select Download Photos. webilder by default downloads interestingness photos from flickr. These interestingness photos are usually high quality photos tagged by flickr community. Beware that these photos some times contain material that may be NSFW. You can configure webuilder to download photos with specific tags.

Enjoy your beautiful desktop.

Offical webilder site.

fusion-icon - Tray Icon to Manage to Manage Compiz

fusion-icon application for compizfusion-icon is a nice little applicaion that sits in system tray and provides GUI means of doing compiz common operations. With fusion-icon you can easily do following things without touching terminal.

  • You can launch compiz settings manager & emerald theme manager.
  • Reload or select a new window manager.
  • Allows you to choose either gtk window decorator(metacity) or emerald.

Execute following command to install fusion-icon.

sudo apt-get -y install fusion-icon

And add fusion-icon command to your sessions.

Profiling PHP Using xdebug & kcachegrind

See the blogpost on xdebug installation before continuing.

Enable Proiling

You need to add following line to /etc/php5/apache2/php.ini to enable profiling of php scripts.

xdebug.profiler_enable=1

Now restart the apache server by issuing following command.

sudo apache2ctl restart

When ever you access a php page through apache, xdebug will create a file something like cachegrind.out.15093. xdebug by default uses /tmp directory to dump files which contain profiling information. You can change this target directory by using xdebug option xdebug.profiler_output_dir and you can change result file name by using the option xdebug.profiler_output_name.

See more xdebug profiling options.

Some times you don't want to profile all requests. xdebug provides a selective mechanism to trigger profiling of specific requests. In order to enable this option you have to add following configuration option to php.ini.

xdebug.profiler_enable_trigger=On

Now you can trigger profiling of specific requests by adding XDEBUG_PROFILE to the query part of the GET request.

Analyzing Profiling results

We need to use kcachegrind to analyse profile file results. We can install kcachegrind by issuing following command.

sudo apt-get -y install kcachegrind

Now open your profle result file in kcachegrind and you can visuall inspect which part of your script is eating cpu resources. Callmap & Callgrap provide easy to understand visualizations to find bottlenecks in your script.

Debugging PHP Using xdebug

xdebug is an open source debugger available for PHP. xdebug can be used to display more information in error traces. It can also be used to collect detailed code coverage & profiling information.

Installation

You need to install following packages to prepare environment for installation of pecl module xdebug.

sudo apt-get -y install php-pear php5-dev build-essential

Now we install xdebug using pecl.

sudo pecl install xdebug

Above command will download, compile & install xdebug on your system.

Configuration

Open /etc/php5/apache2/php.ini and append following line.

zend_extension=/usr/lib/php5/20060613/xdebug.so

Be careful about that number part in the path as it could be different for you. Now restart apache by issuing following command.

sudo apache2ctl restart

Now try to view the output of your phpinfo() function. If you find xdebug word in that then it means you have successfully installed xdebug.

Stacktrace

xdebug stack trace of php scriptxdebug.collect_params accepts values from 1 to 4. Where 1 refers to less verbosity & 4 refers to maximum verbosity while displaying stack traces. The easiest way of setting this option is using function ini_set in PHP.

ini_set("xdebug.collect_params", <verbosity level>)

Get to know more stack trace options of xdebug.

var_dump

Once after installing xdebug when ever you call var_dump you are actually calling xdebug version of var_dump instead of built in one. By default xdebug version of var_dump gives you friendly info on the variables you are trying to inspect.

See more options on controlling display of var_dump information.

Debugging

xdebug uses DBGp protocol to communicate with external debuggers. Vim already has a plugin to do that. So you can debug php scripts from within vim.

Download php debugger plugin for vim.

Installing LAMP Server Stack.

Apache

Apache is a free & widely used web server. To install it on your local system execute following command.

sudo apt-get -y install apache2

You might get following warning when starting apache web server.

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

Add following line to /etc/apache2/apache2.conf to slience the warning.

ServerName localhost

To test the installation enter http://localhost in addressbar of your browser and you should see the message It works!.

Visit Apache HTTP Server site.

PHP

PHP is one of the most easiest scripting language available for quickly writing backend code. Install php by executing following command.

sudo apt-get -y install php5 libapache2-mod-php5

By default you will not be able to save anything to /var/www. To make /var/www writable execute following command.

sudo chmod -R 755 /var/www/

To test php installation enter following snippet into /var/www/hello.php file and save it.

<?php
phpinfo();
?>

Open your browser and enter http://localhost/hello.php into address bar and you should be able to see the information about php version, environment settings and modules installed.

Visit PHP scripting language site.

MySQL

MySQL is a popular open source database server commonly used along with LAMP stack. Execute following command to install it.

sudo apt-get -y install mysql-server

During installation you will be asked to set root user password of MySQL server. It's up to you whether you want to set a new password or leave it blank. Ont the side note linux root account and mysql root accounts are not related at all.

Visit MySQL database server site.

phpMyAdmin

phpMyAdmin is the web interface to work with your database server. You can use phpMyAdmin to manage databases,tables. You can also export and import data into/from database. Execute following command to install phpMyAdmin program.

sudo apt-get -y install phpmyadmin

You can test phpMyAdmin installation by entering http://localhost/phpmyadmin into address bar of your browser.

Visit phpMyAdmin site.

How to enable kerning in Firefox 3 ?

If you don't know about kerning please visit wikipedia article on kerning. Kerning deals with space adjustments between letters to make words more readable. Now a days most of the fonts are shipped with kern hinting but very few applications make use of this extra information. Firefox 3 now officially supports kerning for text elements.

Please make sure you only apply kerning to the elements which use larger font sizes because you won't observe much difference with smaller ones. And use kerning carefully as it could slowdown page rendering because of extra math calculations.

With Firefox 3 you can use the css property text-rendering to enable or disable kerning. text-rendering takes following 4 possible values.

  • auto - If the font size is less than 20px then Firefox uses fast text rendering method provided by operating system otherwise it enables both ligatures and kerning.
  • optimizeSpeed - will disable font kerning.
  • optimizeLegibility - this option enables both kerning & ligatures.
  • geometricPrecision - this option too enables kerning.

And the syntax is

text-rendering:optimizeLegibility;

Firefox 3 automatically enables kerning for text with font-size greater than 20px.

You can change 20px boundary limit by editing the following key in about:config.

browser.display.auto_quality_min_font_size

This blog now uses kerning for headings and all other kinds of text elements. And I am no longer going to use inferior letter-spacing techniques. Firefox 3 is the only browser on the market to support kerning. Safari guys have disabled kerning so that they can drum up about their benchmarks.

Mozilla documentation on text-rendering property.

List of Popular PPA Repositories

Mozilla

deb http://ppa.launchpad.net/mozillateam/ubuntu intrepid main
deb-src http://ppa.launchpad.net/mozillateam/ubuntu intrepid main

Google Gadgets

deb http://ppa.launchpad.net/googlegadgets/ubuntu hardy main
deb-src http://ppa.launchpad.net/googlegadgets/ubuntu hardy main

Ubuntu Netbook Remix

deb http://ppa.launchpad.net/netbook-remix-team/ubuntu hardy main
deb-src http://ppa.launchpad.net/netbook-remix-team/ubuntu hardy main

Banshee Team

deb http://ppa.launchpad.net/banshee-team/ubuntu hardy main
deb-src http://ppa.launchpad.net/banshee-team/ubuntu hardy main

Ubuntu Backporters

deb http://ppa.launchpad.net/ubuntu-backporters/ubuntu hardy main
deb-src http://ppa.launchpad.net/ubuntu-backporters/ubuntu hardy main

Mythbuntu

deb http://ppa.launchpad.net/mythbuntu/ubuntu hardy main
deb-src http://ppa.launchpad.net/mythbuntu/ubuntu hardy main

KDE4

deb http://ppa.launchpad.net/kubuntu-members-kde4/ubuntu hardy main
deb-src http://ppa.launchpad.net/kubuntu-members-kde4/ubuntu hardy main

Compiz

deb http://ppa.launchpad.net/compiz/ubuntu hardy main
deb-src http://ppa.launchpad.net/compiz/ubuntu hardy main

Gnome DO

deb http://ppa.launchpad.net/do-core/ubuntu hardy main
deb-src http://ppa.launchpad.net/do-core/ubuntu hardy main

TimeVault - Backup your files

timevault is a file backup and snapshot solution for ubuntu linux TimeVault is a little python application that runs on Linux. timevault is mainly used to create snapshots of the files on your system, here a snapshot is close to restore point on windows xp. And only super user can delete these incremental snapshots to conserve space on disk.

The beauty of this system is timevault uses links to take backup of these files and linux filesystem won't delete these files until link count reaches to zero. SQLite is used to store meta information of snapshot.

This application nicely integrates with nautilus so that you can see snapshot properties from within nautilus. Color coding is used to easily understand snapshot status. TimeVault uses filesystem watches for changes so when ever you change or delete files they will be automatically backed up. You can download timevault deb binaries from launchpad.

Download timevault binaries.

Autostart Emerald

emerald window border on ubuntuPeople who are using compiz have two ways to automatically start emerald upon login.

Using Sessions

This method involves adding following command to sessions.

emerald --replace &

Using compiz-decorator

This method involves changing a line inside the file /usr/bin/compiz-decorator from

USE_EMERALD="no"

to

USE_EMERALD="yes"

Speedup rdesktop

rdesktop is used to login into windows machines from linux/unix machines. By default rdesktop won't enable caching. Because of this default behavior rdesktop fetches portions of the screen that weren't updated at all. This is particularly painful if your target machine is geographically situated somewhere else.

You just have to add two flags -P -z to your rdekstop command to enable local disk based caching and compression of transmission.

rdesktop -P -z [target machine ip]

I have no clue why this option was not enabled by default since it consumes very little disk space.

apt-get Easter Egg

Execute following command to see the easter egg.

apt-get moo

Enjoy ubuntu. :)

Open new firefox tab in background

firefox logo for ubuntu linuxThere are situations where you don't want a new tab to take focus in Firefox. Its been pain since you don't find any option under Firefox preferences to change this behavior.

Now there is a fix and you can force new tabs to open in background. Start your firefox browser, enter about:config in address bar and search for following key.

browser.tabs.loadDivertedInBackground

Now change this key to true by double clicking on it. If the above entry doesn't exist then create a new boolean key with above name and set it to true.

Enjoy Firefox. :)

NewWave - Intrepid Ibex Theme

newwave intrepid ibex theme

Ubuntu art team is working on look & feel of next ubuntu release Intrepid Ibex. The theme pack is called New Wave which is still in alpha stage but looks cool.

This theme pack contains gtk, metacity, emerald, compiz-fusion elements. Give it a try on existing ubuntu installations and let ubuntu art team know what you think about it.

Download "New wave theme pack".

Install Different Types of Servers

According to ubuntu help section, tasksel is a command line application that can be used to install tasks. Here a task is nothing but meta package for other packages. Except that you can define your own tasks by editing the file /usr/share/tasksel/ubuntu-tasks.desc.

Tasksel presents curses based interface by default if you don't specify any command line arguments. Following are some of the predefined tasks you can install.

  • dns-server
  • edubuntu-server
  • lamp-server
  • ubuntu-desktop
  • ubuntu-live
  • mail-server
  • openssh-server
  • print-server
  • samba-server
  • myubuntu-desktop
  • ubuntustudio-desktop

You can get complete list of tasks by executing following command.

tasksel --list-tasks

Here is the command to install any given task.

sudo tasksel install [task name]

Enjoy ubuntu :)

Speedup SSH Authentication

Did you wait like 10 seconds to ssh into another machine which is just within one feet ?, Well the problem seems to be ssh authentication requires a time consuming DNS lookup.

Fix for this problem is to disable DNS lookup during authentication. Follow steps below to fix this. Open up the file /etc/ssh/sshd_config file as root user and append the following line to it.

UseDNS no

Save the file and exit the editor.Now restart ssh service by executing following command.

sudo /etc/init.d/ssh restart

From now on your ssh logins should work like a breeze.