How to install Xapian 1.2.5 PHP bindings on Ubuntu Lucid Lynx

Starting from version 1.2.x, Xapian repository on Ubuntu does not contain php5-xapian package :( apparently due to the license incompatability between GPL and PHP license(great…)
Issue is discussed somewhat at length here.

But in the meantime, folks suggesting to build PHP bindings for Xapian manually on Ubuntu and Debian. Here is a quick command trail that shows how to install Xapian 1.2.5 PHP bindings on Ubuntu Lucid(10.04), also tested on Ubuntu 10.10 and 11.04:

1. Edit /etc/apt/sources.list and add the following lines to it:

deb http://ppa.launchpad.net/xapian-backports/xapian-1.2/ubuntu lucid main
deb-src http://ppa.launchpad.net/xapian-backports/xapian-1.2/ubuntu lucid main

2. Get some required packages:

sudo apt-get update
sudo apt-get build-dep xapian-bindings
sudo apt-get install php5-dev php5-cli
sudo apt-get install devscripts

3. Fetch sources and build:

apt-get source xapian-bindings
cd xapian-bindings-1.2.5
rm debian/control
env PHP_VERSIONS=5 debian/rules maint
debuild -e PHP_VERSIONS=5 -us -uc

This will generate .deb file in the folder, one level up.

4. Finally, install php5-xapian extenstion:

cd ..
sudo dpkg -i php5-xapian*.deb

5. Verify that you got it running:

php -i | grep Xapian

Information about this process is taken from here and here.

Getting around open_basedir restriction on Plesk

Almost every time I do a deploy on Plesk-based hosting server, I hit the same roadblock:

PHP Warning:  realpath() [<a href='function.realpath'>function.realpath</a>]: open_basedir restriction in effect.

Since I tend to keep my app-code outside of webroot, this restriction is somewhat a problem. Well, luckily, the fix is simple enough.

1. Add file vhost.conf to /var/www/vhosts/YOURDOMAIN/conf folder with the following:

<Directory /var/www/vhosts/YOURDOMAIN/httpdocs/>
<IfModule sapi_apache2.c>
php_admin_value open_basedir none
</IfModule>
<IfModule mod_php5.c>
php_admin_value open_basedir none
</IfModule>
</Directory>

2. Reload server configuration, either via Plesk admin or through CLI:

/usr/local/psa/admin/sbin/websrvmng -u --vhost-name=yourdomain

WordPress shortcode for ShareThis buttons

I like using ShareThis for social sharing button, but one thing that was certainly missing for the default ShareThis WordPress plugin were shortcodes. Luckily WordPress makes it really easy adding them :) So to get shortcode for ShareThis integration just add the following few lines to the end of the functions.php in your theme folder:

/**
* Creates sharethis shortcode
*/
if (function_exists('st_makeEntries')) :
add_shortcode('sharethis', 'st_makeEntries');
endif;

Once that’s done you can use [sharethis] shortcode anywhere on the page/post to get sharing buttons rendered there. Short and sweet :)

How to setup local PHP debugging with PHPStorm and Xdebug

I am checking out a new IDE on the block – PHPStorm… well, new for me anyway :)

For Java and Python, Eclipse is all I need, but when coding in PHP, I am not a big IDE guy, for me, Vi is still the weapon of choice. But when it comes to debugging complex apps(yeah you can write those in PHP too :) , Vi doesn’t quite cut it. There are plugins for it to provide debugging capabilities(or rather Vimified interface to Xdebug), but half of the time it doesn’t work and the other half of the time it’s not what I am looking for. So far, I’ve been a user of Komodo IDE, I still have the old version 4 up and running here and do most of my debugging in it. It’s nice on one side, but somewhat cumbersome on the other.

Anyway, one major thing that always kept me from trying new IDEs is debugger setup. I tend to spend 10 minutes trying to setup debugging in new IDE, get frustrated, say fuck it, and get back to Komodo. This short blog post is to capture how I setup debugging in PHPStorm using Xdebug.
There is a video about this as to how to get a remote debugging working, but not much info about how to get a local one for folks who is on Linux(Ubuntu in my case).
So there we go:

Xdebug Setup

Step 0. Get phpize. If you’re on Ubuntu it’s as simple as running sudo apt-get install php5-dev
Step 1. Get Xdebug, it’s pure awesomeness. Just go here: http://xdebug.org/find-binary.php and follow the instructions. Note: you can also try installing it from pecl or Ubuntu repository, but I had problems with these methods before.
Step 2. I recommend not to follow the last step of Xdebug install instructions where it says to add zend_extension line to the php.ini file. Cleaner way of enabling Xdebug and then configuring it is to add a file xdebug.ini to /etc/php5/conf.d/ folder with the following contents:

;xdebug configuration
zend_extension = /usr/lib/php5/20090626/xdebug.so
xdebug.remote_host = 127.0.0.1
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.remote_mode = req

This xdebug.ini will be picked up by both CLI and Apache and makes it easier to control without messing with the central config file.
Once apache is restarted and xdebug succesfully loaded, time to look at phpStorm’s side.

Step 3. Get Xdebug helper extension for Chrome or similar for Firefox is very handy. Get one so you can enable/disable debugging sessions from the browser. Make sure you set it up such that is loads up on your local domain. For example, if your project runs on myproject.local, your setup will prob look like this:

PHPStorm Debugging Setup

This is a bit less straightforward, but here I go anyway. Here are my assumptions:
My project is running localy at http://myproject.local
It’s stored locally in /home/user/Projects/myproject/public ,which is also a DocumentRoot for myproject.local Vhost config in Apache. There are ‘library’ and ‘application’ folders outside of DocRoot however.

Step 1. In PHPStorm, setup path to web browser(File->Settings->Web Browsers). It actually detected all paths correctly except for Chrome, which I had to set manually(in my case it was in /usr/bin/google-chrome)

Step 2. Setup run configuration – Run->Edit Configurations. That screen is kinda odd, but here is how I got it going.
* Create new configuration, with type PHP on Server

* Create new server(click on the button next to “Server” dropdown). I picked server type “Local” and set webroot to “http://myproject.local“. On the “Mappings” tab I set local path to /home/user/Projects/myproject/public
* Save that server and select it in the Run Configurations
Ultimately my config looked as following:

This looks like it. Now opening up a file inside that project and ‘running’ it will actually bring up a new Chrome window with a page and put PHPStorm in listening mode on port 9000 for Xdebug connections. You’ll need to activate ‘Xdebug helper’ in that window, after that all interactions with the server will be intercepted by Xdebug and PHPStorm.

XDebug doesn’t show local variables in Komodo, NetBeans or Eclipse PDT

Lovely surprise that came sometime after upgrading Lucid Lynx(and thus to PHP 5.3.2) – Xdebug doesn’t show local variables. Fortunately that’s a known issue that is fixed in Xdebug 2.1.0RC, but since it’s not released, it is not yet in Ubuntu’s repository. This should be pretty easy to fix though :) let’s try this:

sudo apt-get install php5-dev php-pear

That’ll get us ready for manual xdebug building. Then we need to get the sources. Gotta tell you, Xdebug guys are pretty awesome – they put together this nice little tool that helps you find and build the right version:¬†http://xdebug.org/find-binary.php

It requires output of phpinfo() or in ‘php -i’ command and based on that gives you set by step instructions.

For standard Lucid Lynx install it boils down to the following commands:

wget http://xdebug.org/files/xdebug-2.1.0RC1.tgz
tar -xvzf xdebug-2.1.0RC1.tgz
cd xdebug-2.1.0RC1
phpize
./configure
make
sudo cp modules/xdebug.so /usr/lib/php5/20090626
sudo /etc/init.d/apache2 restart

Before restarting the server though(last command) you may want to double check the the following line exists in either /etc/php5/apache2/php.ini or in /etc/php5/apache2/conf.d/xdebug.ini

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

Choosing Credit Card Fraud Detection Service: MaxMind® vs. FraudLabs™

Credit Card fraud detection service may seem like an unnecessary thing, but if you’re running(or building) an ecommerce site that may potentially have a lot of transactions it’s something that you may want to look into as a measure of minimizing your chargebacks and your processing fees as well.

There are bunch of companies that provide credit card fraud detection service, two of them I came across while searching for such service for our latest project. MaxMind and FraudLabs

Continue reading

Setting up complex data types in WSDL

Putting SOAP service on PHP platform is a piece of cake. There are few nice articles out there that will pretty much guide you through the whole setup(which is in fact just putting together WSDL and server-side functions to handle a request), so after half an hour of messing around you can have your own SOAP thingie going. One draw back there – the article would get you as far as sending simple types(like strings and floats) back and force between client and server. Now, this isn’t very helpful if you’re trying to build something more object oriented.

The basic problem that I hit setting up SOAP server for a data-sharing application(pretty much content repository for a network of websites) – how to set up a custom complex data type without going through that whole WSDL spec?

Continue reading