Debugging PHP in Ubuntu using Eclipse

This guide walks you through the necessary steps to configure the Eclipse IDE for PHP debugging. This can be very handy, especially when you’re trying to resolve an issue in a complex PHP application or plug-in.

Things you’ll need

  • Eclipse
  • Eclipse PHP Development Tools (PDT)
  • Xdebug
Assumptions
This article assumes that you are configuring Eclipse and Xdebug for development on a localhost web server. If you are not, be sure to make appropriate adjustments to accommodation your needs. Likely the only changes you will need to make will be differences in connecting to your server verses localhost.

Quick Overview

For those that are unaware, Eclipse is a very popular IDE for developing in Java. However, Eclipse is much more powerful than that and can in fact easily be used for developing in many other languages including PHP.

Xdebug is a brilliant debugging extension designed for use with PHP. Once configured, Xdebug will allow you to remotely connect to your web server… or in my case connect to my development localhost web server. Rather than using crude echo and logging techniques to debug your PHP code, Xdebug allows you to literally step through and inspect values and function flows in real-time.

If you’ve ever scratched your head at a PHP script and thrown in dozens of echos or logging statements to track the execution path then you’ll really come to appreciate the benefits of using Xdebug.

Configuring Eclipse and Xdebug isn’t difficult. In fact its painless with the correct steps on hand. That’s where this guide comes in. I found myself coming across incomplete or outdated forum posts and stackoverflow questions, so I thought I’d post what worked for me.

If you already have Java and Eclipse installed, then just jump ahead to installing and configuring the PHP Development Tools and Xdebug.

Install Eclipse

This will install ~118 new packages, assuming you’ve not already installed some of them, and will total around 255 MB that need to be downloaded.

  1. Open a terminal and enter the following command to install Eclipse:
    sudo apt-get install eclipse

     

  2. After the download completes, open Eclipse to confirm that it installed correctly. Leave it open for our next install.

Install PHP Development Tools (PDT)

  1. If you don’t have Eclipse open at this point, open it up.
  2. Navigate through the menus to: Help -> Install New Software…
  3. You will be prompted with a new window asking you to select a site or enter the location of a site. You should be able to drop down the list of sites and find one labeled “–All Available Sites–“. Select this option and wait for the list below to populate.

  4. Scroll through the list until you find a category labeled “Programming Languages” and click the arrow to expand this list.

  5. Continue to scroll through the Programming languages until you find a item labeled “PHP Development Tools (PDT) SDK Feature” and check the box to the left.

  6. Click Next and continue throw the installation. You’ll have to select that you agree to the terms of installing this software.
  7. After the installation has completed, you will be asked to restart Eclipse to apply changes. Go ahead and restart Eclipse, then move on to the next install.

 

Install XDebug

  1. Open a terminal and enter the following command to install Xdebug:


    sudo apt-get install php5-xdebug
     

  2. After installation completes, there are a couple of files that need to be configured. If you copy and paste the commands below, make sure to check that the quotes that are copied over are regular quotation characters, as they may cause problems if they are not.
    1. sudo gedit /etc/php5/conf.d/*xdebug.ini 


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

      xdebug.remote_enable = 1
      xdebug.remote_handler = “dbgp”
      xdebug.remote_host = “localhost”
      xdebug.remote_port = 9000 

    2. sudo gedit /etc/php5/apache2/php.ini 

      Scroll to the bottom and add:

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

  3. Restart your Apache server so that the new PHP configuration settings are loaded.

    sudo /etc/init.d/apache2 restart

  4. Confirm that your Xdebug installation was successfully loaded by creating a simple PHP file called “phpinfo.php” and placing it in the public root of your Apache web server. Be sure to include the following in your file, save it then navigate to it in your browser:

    <?php phpinfo(); ?>

  5. After loading the php info page, search for “xdebug”. If you find it listed, then you have successfully installed and configured Xdebug. If not, check back over the steps listed above or consult Google.
Configuring your Eclipse project to connect to Xdebug
After you’ve finally gotten everything installed, you’re probably anxious to start debugging. You’re not far off. The only thing that’s left is to import your PHP script or site and establish a Debug Configuration for your project.
To import a site, simple select: File -> New -> Project… -> PHP -> PHP Project. This will open a new window where you can open PHP files from and existing location. Assuming this location is in your public root directory in Apache, you can work with these scripts in real-time.
After importing these existing files, right click on your new project and select: Debug As -> Debug Configurations…
Make sure that you’ve selected Xdebug as the Debugger type. Click Apply and then Debug. This will open a “Debug” perspective in Eclipse, allowing you to view variables and stack traces live. Assuming you’ve created a breakpoint or selected to break at the first line of the file, you should now see your PHP script paused waiting for you to debug!
Tip: If you’re planning to debug a large project such as a WordPress, phpBB, vBulletin or any other large web application, pointing the Debug Configuration to your index.php makes debugging much easier.
Done
Congrats! By now you should be beginning a new road to a much easier life of PHP development.
If you have any questions, comments or suggests feel free to let me hear them below! I’ll try to help where I can, but I can guarantee I’ll know how to solve any of the issues you may encounter. ;)

Making CSS UL Menu’s Browser-Consistent

If you’ve ever made a web site and wanted it to look consistent from one browser to the next, then you’re well away of the difficulties that are involved. Fixing these sorts of styling issues can be a major annoyance, however, I like to hunt down issues on my own pages from time to time and stand up to the challenge.

One issue that I can across today was dealing with horizontal menu positioning using unordered lists (<UL>) and some positioning. The positioning wasn’t consistent between browsers or even operating systems.

The bad

I started by opening the affected page in multiple browsers (Internet Explorer, Safari, Chrome, Opera & Firefox) on multiple computers (Mac, Linux & Windows) and getting some initial comparisons. There were 3 different variations and (oddly enough) the same browser didn’t necessarily render the same on a different operating system. So there I was. A puzzle… and I like puzzles.

Some of the first things that I inspected were font sizes and families. It occurred to me that different operating systems may differ in fonts, so it seemed like a good starting point. I tested this by forcing a common font: Arial. That wasn’t the problem. The inconsistencies remained consistent.

I also checked into the possibility that the <UL> or <A> elements were applying different heights. Typically anchor elements, <A>, use a display style of inline. If you’re implementing a menu similar to mine then you’re likely applying a block style, which permits better dimension definition of the element. Forcing height on these elements also did not resolve the issue.

I was running out of ideas, but then it hit me. Line-Height. While the other styles appeared to be consistent between browsers and operating systems, there was one style that I’d previously worked with and knew was certainly NOT consistent: line-height.

The good

After forcing a consistent line-height in my CSS, all browsers suddenly began respecting my intended styling. Sigh of relief.

On that note, its worth bringing up the success that browser competition has brought to HTML and CSS rendering standards over the past few years. The push for the fastest and most capable browser has brought a scattered group of browsers a little closer and the result is that we get to enjoy dealing with fewer and fewer bugs.

While your average Joe web developer may have dug around for hours for this issue to no avail, I must say… I thought it was nice to face such a subtle issue rather than being forced to use some crazy IE specific hacks like for legacy IE.

[How to] Create a bootable USB stick on OS X

A couple of days ago I decided to reinstall my operating system since it was failing. I quickly realized that the only functional system that I had at the time was my MacBook Pro. After a bit of Googling, I came up with a pretty straightforward guide, but they really could have formated it to make it easier to follow.

I’m going to run you through the same steps and you should be able to use this guide to create a bootable USB stick for Windows, Ubuntu, Fedora, etc.

The Guide

  1. Download the disc image that you want to use. (I’ll use Ubuntu in my example, but you can use Windows or whatever you’ve downloaded.)
  2. Open the Terminal (in /Applications/Utilities/ or query Terminal in Spotlight).
  3. Convert the .iso file to .img using the convert option of hdiutil as shown below (replace the paths and image names to suite your needs):

    hdiutil convert -format UDRW -o ~/path/to/target.img ~/path/to/ubuntu.iso

    Note: OS X tends to put the .dmg ending on the output file automatically, creating the file target.img.dmg. I’ve always removed the .dmg extension.

  4. Run diskutil list to get the current list of devices.

    diskutil list

  5. Insert your flash media.
  6. Run diskutil list again and determine the device node assigned to your flash media (e.g. /dev/disk2).

    diskutil list

  7. Run diskutil unmountDisk /dev/diskN (replace N with the disk number from the last command; in the previous example, N would be 2).

    diskutil unmountDisk /dev/diskN

  8. Execute sudo dd if=/path/to/downloaded.img of=/dev/rdiskN bs=1m (replace /path/to/downloaded.img with the path where the image file is located; for example, ./ubuntu.imgor ./ubuntu.dmg).

    sudo dd if=/path/to/downloaded.img of=/dev/rdiskN bs=1m

    Using /dev/rdisk instead of /dev/disk may be faster
    If you see the error dd: Invalid number ‘1m’, you are using GNU dd. Use the same command but replace bs=1m with bs=1M
    If you see the error dd: /dev/diskN: Resource busy, make sure the disk is not in use. Start the ‘Disk Utility.app’ and unmount (don’t eject) the drive.

  9. Run diskutil eject /dev/diskN and remove your flash media when the command completes (replace N with the disk number).

    diskutil eject /dev/diskN

  10. Restart your PC and enter the boot options to choose the USB stick. If you’re installing to your Mac, restart and press alt/option key while the Mac is restarting to choose the USB stick.

If you’ve made it this far, then you should be well on your way to installing a new operating system. Good luck!

Ubuntu Software Center vs. Mac App Store

As many of you may already know, Mac OS X now comes installed with a “Mac App Store”. Ubuntu also comes installed with an “Ubuntu Software Center”. Both of these applications serve the same general functionality in very similar formats, but I’m going to take a look at what needs to be improved in the Ubuntu Software Center.

First off, lets take a look at both of these applications from a first impressions point of view. Its pretty obvious at a glance that the user interface of these applications are eerily similar. It’s also pretty obvious that one app has received a little more attention to detail and aesthetics.

First Glance

The Mac App Store features a rolling banner at the top which highlights new or popular items. This is something that Ubuntu has not adopted. Not that its necessary, but it’s certainly a nice touch.

Both applications feature a “What’s New” and “Top” section, but in Ubuntu the presentation is… well, lacking to say the least. You can probably see a different in the thumbnails above with the polished Mac App Store that seems to just pop and the Ubuntu Software Center that just seems dull and with little focus.

I seem to recall mention of Ubuntu trying to improve the quality of application icons and screenshots. This could go far for improving application presentation! As Ubuntu is increasingly becoming more and more popular, the need for a matured and polished software center is greater than ever.

Now lets look at what kind of information and selling points the Mac App Store offers when you select an item that you may be interested in installing.

Mac App Store – Application Profile Page

The Mac App Store shines with its prevalent display of the item’s icon, a well written brief description and most importantly a screenshot gallery. While a short description of the application is an obvious requirement, the screenshot gallery may be the single best-selling point for an application. These screenshots have the power to showoff not only how nice your application is, but more importantly what it can do! It seems that authors tend to pick a handful of well-chosen screenshots to give a thorough glance at the features and functionality available.

Some other nice details that the Mac App Store offers include information about the author and their website, the application’s version and release date, and of course a customer review section. The review section is just like any other review section, though it does provide a nice break down of the ratings. It’s easy to see the overall rating of an application as well as how many users rated it a one star, two star, three star, etc.

Now lets take a look at what we get from the Ubuntu Software Center.

Ubuntu Software Center – Application Profile Page

The Ubuntu Software Center has actually evolved a great deal over the past couple of years. Just like the Mac App Store, Ubuntu offers a prevalent application icon, a brief description and, when available, a screenshot. However, the simple presentation of these three important details is somewhat lacking.

As mentioned before, it’s not uncommon to find an application with a very poorly created icon. You may also, at times, run into the issue of a poorly written description or find an application with no screenshot available. Even when you find an application which has all the above, you’re only presented with one screenshot which opens in a new window and not simply featuring the larger view from within the software center itself.

Some improvements that I’d personally like to see would be an implementation similar to the gallery in the Mac App Store. I’m not saying I’d like for Ubuntu to clone the Mac App Store, but its clear why improving this feature would be very beneficial for the Ubuntu Software Center.

It would also be nice if the Ubuntu Software Center would pull screenshots of these applications (possibly from their own servers) that are taken in the Radiance or Ambiance theme. I’m sure it can be a little confusing for some when they see a screenshot with a non-default theme applied to it. This is a change that Ubuntu should consider for user familiarity and consistency.

Other important details that the Ubuntu Software Center offers include the application version, a “People Also Installed” section and user reviews. While the availability of the application version is certainly great, the complex versioning system that is so often used in Linux may make it useless for some. I understand the Chromium Web Browser version 18.0.1025.168~r134367-0ubuntu2, however, many people may find this less than ideal.

As for the user reviews, Ubuntu has done a nice job of making it easy to review and contribute to the success or demise of any given application. I’d still like to see a break down of the rating for each level like the Mac App Store does.

Now lets talk a little about some very poor user interface designing…

Ubuntu Software Center – Interface Design

What happens when you view a category or perform a search in the Ubuntu Software Center? Simple, you get a list. What kind of list you may ask? A very space inefficient list that leaves the user endlessly scrolling through results while appearing to be a half-assed implementation.

Mac’s approach to situations such as displaying categories or search results is to throw the results into a table-like layout. While this is a nice implementation, it’s not necessarily the best. There’s one thing that I know for sure though, and that’s the fact that Ubuntu’s current implementation just doesn’t cut it.

Other weaknesses in the design of the Ubuntu Software Center can be attributed to lack of visual divisions between applications in a list or important application details, poor color contrasts, inconsistent styling and a general feeling of the overall application’s color being desaturated.

As far as the poor color contrast, there are many areas throughout the software center that could benefit from adjusting the colors to focus the important content, make it stand out and shine, and make the less important details fade into the background. This technique helps to remove the feeling of having such a cluttered interface while retaining all the same information.

Conclusion

While Mac has always had the edge on other operating systems as far as offering a polished user interface, Ubuntu has come a long way and will continue to improve. Unfortunately, for the last few releases, Ubuntu has been overly focused on their Unity environment and this has left a lot less time for them to spend on improving other very important aspects of the operating system… such as the software center.

That being said, the Ubuntu Software Center certainly is a very usable tool and is much better than it has been in the past. One great thing about open source is the ability to take a bit of code, improve it and then release it as potentially a better alternative. That’s just what happened when Linux Deepin released the Deepin Software Center.

Lets just hope that the Ubuntu developers have taken note of this and will continue to strive for the best possible Linux experience.

Create a Bootable Windows 7 x64 Install Flash Drive from 32-bit Windows

Creating a bootable Windows 7 x64 flash drive from within a 32-bit install of Windows is not as straight forward as it may seem. I recently had to go through this process myself, so I’ll document the steps below.

Things you’ll need

  1. Windows 7 x64 disc image
  2. Windows 7 USB/DVD Download Tool
  3. 32-bit bootsect.exe

Create the installer

  1. Install the Windows 7 USB/DVD Download Tool.
  2. Extract the 32-bit bootsect.exe file to the directory that the Windows 7 USB/DVD Download Tool was installed to. This is usually something like “C:\Users\username\AppData\Local\Apps\Windows 7 USB DVD Download Tool“.
  3. Run the Windows 7 USB/DVD Download Tool and select your Windows 7 disc image. Follow the remaining steps in this tool and your image should be created successfully!

If you’ve followed these steps and your flash installer was created successfully then your next step is to, of course, install Windows 7! Don’t forget to change your boot options to load from USB!

This information is scattered on the web and slightly detailed on the Windows 7 USB/DVD Download Tool page, but I was not able to find a guide laid out as simplified as the one I’ve provided above. In most tutorials they suggest that you download the entire 32-bit iso in order to get the 32-bit bootsect.exe application, but I’ve made that step a lot less troublesome. Hopefully this has helped you!

Nvidia patches a bug I’ve waited 9 months for…

I’ve been following an Nvidia bug that’s been affecting me for a while now and am happy to say that its apparently been fixed! I say apparently, because I’ve not been around my Linux box for several days (due to the holidays) and haven’t had a chance to confirm for myself.

If you have an Nvidia card, especially the 7300le model like I have, and have had difficulties using Unity 3D with the proprietary drivers, then you may have experienced this bug: [nvidia, 7300, 7400] display freeze when using unity desktop

Nvidia has just released an update which resolves this issue and it can easily be installed right away!

Release highlights since 275.36:

  • Fixed a bug that would cause Firefox to abort on pages with Flash when layers acceleration was force-enabled on Linux and Solaris.
  • Fixed a bug that could cause display devices on a secondary GPU to get swapped between X screens when restarting the X server.
  • Fixed a regression that caused blank/white windows when exhausting video memory on GeForce 6 and 7 series GPUs while using composited desktops.
  • Fixed a bug that caused a crash when glDrawArrays was used with a non-VBO vertex attribute array to draw on a Xinerama screen other than screen 0 using an indirect GLX context.

The 275.43 NVIDIA Accelerated Linux Graphics Driver Set for Linux/x86 is available for download via FTP.

The 275.43 NVIDIA Accelerated Linux Graphics Driver Set for Linux/x86_64 is available for download via FTP.

 

Please see the README (x86 / x86_64) for more information about this release.

 

Please note: This NVIDIA Linux graphics driver release supports GeForce 6xxx and newer NVIDIA GPUs, GeForce4 and older GPUs are supported through the 96.43.xx and 71.86.xx NVIDIA legacy graphics drivers. GeForce FX GPUs are supported through the 173.14.xx NVIDIA legacy graphics drivers.

 

Please also note: If you encounter any problems with the 275.43 NVIDIA Linux graphics driver release, please start a new thread and include a detailed description of the problem, reproduction steps and generate/attach an nvidia-bug-report.log.gz file (please see http://www.nvnews.net/vbulletin/showthread.php?t=46678 for details).

If you’re seeing the same problem and would like to test the update, there are a few specific instructions that you may (or may not) need to follow, posted here.

What do you install in your Ubuntu?

I’ve been keeping lists for a few years of the applications that I install every time I do a fresh install of Ubuntu. I recently made a new list for Ubuntu 11.10

  • Cheese
  • Chromium Web Browser
  • CompizConfig Settings Manager
  • Dropbox
  • EasyTAG
  • Enable Commercial DVD Playback
  • FileZilla
  • Geany
  • Opera Web Browser
  • RapidSVN
  • Spotify
  • The GIMP
  • Ubuntu Restricted Extras
  • VLC
  • Wakoopa

The applications that I install haven’t changed a whole lot over the years, but it leaves me wondering what applications make the cut for others!

 

Submitting Anonymous Usage Statistics

Banshee Media Player Usage Statistics

Being a software developer myself, I tend to pay attention to application functionality and options a little more than the average end user. I’ve noticed that over the last few years when I encounter an option to ‘submit anonymous usage statistics’ I gladly and immediately enable it.

Knowing that you can gain valuable information about the way your end users are using your product, it makes sense for a software developer to include this option and frankly I’m baffled that its not available in most all applications.

I’d like to use this post for two reasons:

  1. To encourage you and others to consider enabling this option in order for developers to get the accurate information that they need to make their product even better!
  2. To maintain a list of these options in various applications that I stumble upon so others are aware.

As I gradually increase the number of applications, feel free to point out applications that I’ve missed and I’ll add them to the list!

Application List:

 

Adium

 

Banshee Media Player

 

Eclipse

 

Google Chrome

 

Google Drive

 

Google Music Manager

 

Opera

 

Ubuntu Software Sources

 

Google Music Manager

 

 

Using Synergy with Mac and Ubuntu

Ubuntu Linux Hostname from Terminal

This is just a quick guide for those of you who also use both Mac and Ubuntu (or really any flavor of Linux) side by side. If you’re not already familiar with Synergy, it’s a small application that connects your mouse and keyboard to one or more machines for a more continuous experience.

Mac and Linux use a graphical front-end for Synergy known as QuickSynergy. Here’s how to get it configured for use between Mac and Ubuntu…

Hostnames

You can find the hostnames to use simply by opening a Terminal window, or if you’re unsure still, simply type hostname and press enter. ;)

If you used the hostname command in Ubuntu, you probably noticed that the “.local” part is not printed out, but it is necessary when dealing with Mac OS X.

Connecting the Two

After selecting the system you’d like to share, configure the Use or Share tab as necessary similar to the examples below:

After configuring Synergy/QuickSynergy you’re all set to start making your life easier!

Unity Opera!

Unity Opera Tab Count

With Unity in the recent spot light and a little free time on my hands, I decided it was time to dabble with the Launcher API. What better combination that my two favorite pieces of software: Unity in Ubuntu and Opera!

With my Unity Opera script, you’ll be able to get extra functionality for Opera by simply downloading a script and adding it to your Startup Applications list. No technical modifications necessary!

The Launcher API provides four features at the moment: Count, Progress, Urgency, Quicklists.

At the moment I’m only able to implement functionality for three of these, with the exception being Progress. In its current implementation, Unity Opera has the following features:

Count

The total number of tabs you have open appears on the Launcher icon and is updated in real time as you open and close tabs.

One item to note here is that Opera’s Private tabs are not included in this tab count. Since information about these tabs and their contents are not stored anywhere on your computer, Unity Opera has no way of discovering them.

Progress

At this point in time, the progress functionality for this script is not available. Until I find a way to programmatically determine download progress in Opera, I will not be able to implement this.

If you have any information regarding a way to implement this feature then please let me know!

Urgency

When browsing the net, not every link you click on is from inside the web browser. Sometimes you click a link from an instant message, mail client, Gwibber, etc. This is where urgency comes into play.

Typically clicking these links automatically opens the tab in your browser, but it doesn’t always pull you’re browser into focus. When this happens, you may not know which browser the link opened in or if clicking it was even successful.

When Opera is not in focus and a new tab is opened, the Opera icon in the Launcher now enters urgency mode and wiggles onces. An urgency highlight is also applied to the icon and a small attention reminder in the upper left corner until you focus Opera again (this clears the urgency setting).

Quicklists

Previously I shared a tip on how to customize your Quicklists for Opera. That method meant that you had to manually open and edit the desktop file.

This is no longer the case, as these features are already built into Unity Opera.

On top of that, your Speed Dial items are also appended to the Quicklist, making your life that much easier! ;)

If you use Opera’s built in Mail client, also known as M2, then you will see an Opera for Mail, which is intended to open M2 directly. At the moment, this feature doesn’t work as intended, but hopefully in due time it will.

Download Unity Opera

Unity Opera is written in python and can easily be updated and maintained. I suggest you save and extract it to your Home directory and use it there, but you are free to place it anywhere you wish.

Download

Running Unity Opera

You can run Unity Opera in one of two ways:

1. The easiest way in my opinion is to simply add it to your Startup Applications.

To do this simply open your dash and search for ‘Startup Applications‘. Once there, click ‘Add‘ and fill in the blanks!

To run Unity Opera on startup, I place the script in my home folder. You can place it where ever you wish, but if you pick a place other than your home folder then you will need to provide a full path the script in your startup command.

An example of what I use is as follows:

python unity-opera.py

2. The other option is to open a terminal when you want to use this script and run the command above.

Options

This script has several options. For help and more information type:

python unity-opera.py –help

This script accepts two optional args:

1. Opera Channel: This is used for setting Unity Opera to run against regular Opera and the new Opera Next channel. By default, if you exclude this arg, Opera is set as the browser to run against. Examples of this command include:

python unity-opera.py opera

python unity-opera.py opera-next

2. Enable features: This is used to enable specific features. You can enable only basic quicklists [q], quicklists with Speed Dial entries [qs], tab count [c], urgency notification [u], and progress [p].

As mentioned before, progress is not functional at the moment, but I’ve built the script with this feature ready to include as soon as I find a way. ;)

This second argument requires the use of the first argument. Examples of this command include:

python unity-opera.py opera -qs

python unity-opera.py opera-next -qsu

Troubleshooting

If you experience trouble with this script, please try running it from a terminal to see if there are any errors output to the console. If so, copy and paste these in the comments below and I will take a look at them.