Category Archives: Fixes

Installing php-fpm and apache2

I’ve readed a lot of tutorials of using nginx and php-fpm.
I’m still using apache2 much more due the .htaccess easiness that allow with rewriting and password protect (despite using other modules like mod_svn, etc)

Even I haven’t found a 100% transparent solution like ngninx, here is what I’m using to work with php-fpm and apache2. Here are the steps in debian:

  • echo "deb stable all" >> /etc/apt/sources.list
  • apt-get update
  • apt-get install libapache2-mod-fastcgi apache2-mpm-worker php5-fpm php5-common php5-cli
  • do all the apt-get of all php5-* modules you want
  • Add the following to a new file: /etc/apache2/mods-enabled/fpm.load
    AddType application/x-httpd-fastphp5 .php .phtml
    Action application/x-httpd-fastphp5 /fast-cgi-fake-handler
  • in /etc/php5/fpm/pool.d/www.conf change:
    listen =


    ; listen =
     listen = /var/run/php-fpm.socket

    This will enable the unix socket which should be faster

  • /etc/init.d/php-fpm restart
  • /etc/init.d/apache2 restart


With this you will be able to use php-fpm through a /fast-cgi-fake-handler so for example in your /etc/apache2/sites-enabled/000-default your file will look like:

FastCGIExternalServer /var/www/fast-cgi-fake-handler -socket /var/run/php-fpm.socket
DocumentRoot /var/www

The system will rewrite /index.php path into: /fast-cgi-fake-handler/index.php which will be passed to the fastcgi

This have two problems:

  1. You need to set the FastCGIExternalServer like ${DOCUMENT_ROOT}/fast-cgi-fake-handler in all your virtual hosts to make it work
  2. Zend framework and other which use the consume all url’s pattern to pass through index.php will not work as will generate an endless loop, there is an easy solution, in your .htaccess use after RewriteEngine On:
    RewriteRule ^fast-cgi-fake-handler/ - [L,NC]

    this will skip processing all urls which contain “fast-cgi-fake-handler” at start; or of course use a RewriteCond to avoid this.


NFS client “Permission Denied” on Debian unstable

While I was trying to access to a master NFS server in lenny from a squeeze client, I was having “Permission denied” when I tried to write any file; as there are other NFS clients with the same configuration this didn’t seem to be a problem of NFS configuration but rather from new client version.

After some googling time, I found this bug:

If you want to know if your version is having this problem, you can check doing a “cat /proc/mounts” and should see the NFS mount with a “sec=null” and that is giving you the problem.

A suggestion from bug report is to downgrade, but that could not be an option in a fresh installed squeeze so the other workaround is easy:

  1. Unmount all nfs (important as I only unmount a exported filesystem from a server and won’t work until you unmount all)
  2. On /etc/fstab (or when mounting if you are doing manual) add the option sec=sys to all the mounts for that server; for example in fstab: /tmp/shared nfs rw,sec=sys 0 0

    or mounting:

    mount -t nfs  -o "rw,sec=sys" /tmp/shared

  3. Mount all nfs from that server

If you check the /proc/mounts you should see the sec=sys instead null and be able to write to remote server


Flex 4: Getting bitmap data on a spark clipped content

Recently I was working on a project where I need to get the bitmap data from a container which had a scroller. From Flex 3 I tried to simply get the content directly from container; but I noticed that I only got the exact image of the scroller (Viewport) instead the full content.

With some playing, I got to the same easy solution; to draw the entire content of the container is to simply disable the clipAndEnableScrolling property over the container I was going to fetch the bitmap data and after drawing, enable again; as internally it just adjust the view properties, you won’t notice the change.

Here is the snippet:

this.containerDraw.clipAndEnableScrolling = false;
this.containerDraw.clipAndEnableScrolling = true;

Where bmSave it’s a BitmapData, you can see an example here:


Mysqli small fix for allowing socket in Zend Framework

As this site is running on ICDSoft hosting, they allow to use MySQL 5 or MySQL 4, but they provide different sockets for each version.

In MySQLi extension, the following host string doesn’t works: localhost:/tmp/mysql5.sock (or localhost:/tmp/mysql.sock), this because they separate the socket from the server host string.

In Zend Framework in the MySQLi Adapter, they don’t use the socket optional parameter, so I made a small fix to allow this [Zend/Db/Adapter/Mysqli.php]:

if (isset($this->_config['port'])) {$port = (integer) $this->_config['port'];

} else {

$port = null;

}/* new block */

if (isset($this->_config['socket'])) {

$socket = $this->_config['socket'];

} else {

$socket = null;


/* end of new block */

// Suppress connection warnings here.

// Throw an exception instead.

@$this->_connection = new mysqli(






$socket //new


This allow you to use the socket name, this was for enabling my new showcase example: Google Maps and GeoIP Location, you can see the full code here:


Security Policies in Flash Player 9

I recently had a problem with Security Policies with flash player; I suggest you to read the official documentation specially if you want to know what to do in several versions of Flash Player.

WhatI learn is too simple about loading a crossdomain.xml from a server:

  1. If you load the crossdomain.xml from an http request. Example: Security.loadPolicyFile(''). The flash player sandbox will only allow to you swf to connect to ports over 1024
  2. If you want to load ports below this, you need to read the crossdomain from a port below 1024, for example: Security.loadPolicyFile('xmlsocket://')

Of course the most important about the last is that you can load from any port below 1024 and you’re granted to access any port on that server; you can use classes like Socket or XMLSocket for connecting to other ports; so you can have a server listening to information from Flash, but in another to serve the policies. You can do for example a small server in PHP5 for example: which shows you to use this great feature in PHP5.

Hope this help you.