Install PHP5 Memcached PECL extension and have it support igbinary

Canonical
Tags

Igbinary is a drop in replacement for the standard PHP serializer. Instead of the time and space consuming textual representation used by PHP’s serialize, igbinary stores PHP data structures in a compact binary form.

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.

OpenStack Cloud-Init dialog
OpenStack Cloud-Init dialog

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.
  1. Follow steps from the procedure. Those were taken from the Original procedure, just before issuing ./configure.
  1. 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. Ideally this should be done on a machine or VM image you're OK building things on and you can re-use.
apt-get install -y ruby-dev gcc

# Install fpm gem globally.
gem install fpm
  1. 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
  1. 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/
  1. Magic will happen
fpm -s dir \
    -t deb \
    -n php5-memcached \
    -v 2.2.0-wpd \
    -m '<your@email.org>' \
    --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.

  1. Test if the package works
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!

  1. Look at the phpinfo
OpenStack Cloud-Init dialog

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. If you only have a handful of packages, it can simply be 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

If you want something more scalable than a directory with a bunch of .deb and a Package.gz that you rsync around, there are other procedures available online.

Done!