Install PHP5 Memcached PECL extension and have it support igbinary

I was trying to figure out why my PHP setup would never have both igbinary to be used to serialize sessions in Memcached using current Memcached PECL extension.

Before: session handlers shows memcached
Before: igbinary support no?

After some research I found a procedure in an answer on StackOverflow.

But it didn’t solve my main requirement: Since I do automated deployment, I MUST be able to move packages around. Since all my VMs are using the same distribution and that I already have my own apt repo, I could just add one more deb file.

My objective was then now to package it for deployment. To do this, I discovered Jordan Sissel’s project called fpm which stands for “Freaking Package Manager” (sic)

My target deployment runs on Ubuntu 14.04 LTS and I want it to replace upstream php5-memcached package as a simple .deb file.

Build from PECL source

NOTE The following was run on an Ubuntu 14.04 VM with @rynop’s procedure.

  1. Setting the machine up to make a package.

    mkdir /tmp/php5-memcached
    cd /tmp/php5-memcached
    apt-get install -y php5-dev pkg-config php-pear
    
  2. Follow steps from the procedure. Those were taken from the Original procedure, just before issuing ./configure.

    pecl_memcached_ver="2.2.0"
    pecl download memcached-${pecl_memcached_ver}
    tar xzvf memcached-${pecl_memcached_ver}.tgz
    cd memcached-${pecl_memcached_ver}/
    phpize
    
  3. I realized that under Ubuntu 14.04 we also needed to disable Memcached SASL so I had to do it differently

    ./configure --enable-memcached-igbinary --disable-memcached-sasl
    

Make a .deb package

  1. Install jordansissel/fpm

    apt-get install -y ruby-dev gcc
    gem install fpm
    
  2. Check the package contents you want to replace and let’s replicate for our own purposes.

    dpkg --list | grep php5-memcached
    find /var/cache/apt -type f -name '*php5-memcached*'
    dpkg -c /var/cache/apt/archives/php5-memcached_2.1.0-6build1_amd64.deb
    
  3. I figured out in the output that I only needed a few folders, etc/php5/mods-available/ and usr/lib/php5/foo, so I created them manually.

    mkdir -p etc/php5/mods-available/
    // Adjust memcached.ini to suit your tastes, then prepare it for packaging
    cp memcached.ini etc/php5/mods-available/
    // Make sure the usr/lib/php5/foo path matches in 
    // the result of `dpkg -c` you issued
    mkdir -p usr/lib/php5/20121212/
    cp modules/memcached.so usr/lib/php5/20121212/
    
  4. Magic will happen

    fpm -s dir -t deb -n php5-memcached -v 2.2.0-wpd -m '<[email protected]>' --description 'PHP 5.5 PECL igbinary + memcached support' -d libmemcached10 etc/ usr/
    

    I could have used --replaces REPLACES in fpm options, but when I did this package, I didn’t know which syntax to use. Its an optional argument anyway.

  5. Test if the package works

    dpkg -i php5-memcached_2.2.0-wpd_amd64.deb
    [email protected]:/srv/webplatform/buggenie# dpkg -i /srv/webplatform/apt/php5-memcached_2.2.0-wpd_amd64.deb
    (Reading database ... 118781 files and directories currently installed.)
    Preparing to unpack .../php5-memcached_2.2.0-wpd_amd64.deb ...
    Unpacking php5-memcached (2.2.0-wpd) over (2.1.0-6build1) ...
    Setting up php5-memcached (2.2.0-wpd) ...
    

    Success!

  6. Look at the phpinfo

Ater: registered session handlers

Update your private apt repository (or create one)

  1. Then, in your own apt repository (if you do have one) here’s how I rebuild the index. Not that its not more complex than a folder with a bunch of deb files

    mkdir -p /srv/apt
    cp php5-memcached_2.2.0-wpd_amd64.deb /srv/apt
    cd  /srv/apt
    apt-get install -y dpkg-dev
    dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
    echo 'deb file:/srv/apt ./' > /etc/apt/sources.list.d/foo.list
    

Done!