Monthly Archives: May 2015

LDAP / memcache frustration on DirectAdmin

I have about 5 servers that I maintain to run websites. In addition to the base system that DirectAdmin installs I have a requirement for a few additional modules.

These are memcache and LDAP.

I use Debian x64 and DirectAdmin, to try and keep things the same. So if it works on one, you test it on one… it should work on the others right?

Every time I upgrade PHP I have issues getting these two modules compiled back in (add custom modules).

I upgraded one server to PHP 5.6.8, using CustomBuild 2.0 I enabled LDAP. So my custom/ap2/configure.php56 looks like this, to add LDAP:

./configure \
        --with-apxs2 \
        --with-config-file-scan-dir=/usr/local/lib/php.conf.d \
        --with-curl=/usr/local/lib \
        --with-gd \
        --enable-gd-native-ttf \
        --with-gettext \
        --with-jpeg-dir=/usr/local/lib \
        --with-freetype-dir=/usr/local/lib \
        --with-libxml-dir=/usr/local/lib \
        --with-kerberos \
        --with-openssl \
        --with-mcrypt \
        --with-mhash \
        --with-ldap \
        --with-mysql=mysqlnd \
        --with-mysql-sock=/tmp/mysql.sock \
        --with-mysqli=mysqlnd \
        --with-pcre-regex=/usr/local \
        --with-pdo-mysql=mysqlnd \
        --with-pear \
        --with-png-dir=/usr/local/lib \
        --with-xsl \
        --with-zlib \
        --with-zlib-dir=/usr/local/lib \
        --enable-zip \
        --with-iconv=/usr/local \
        --enable-bcmath \
        --enable-calendar \
        --enable-ftp \
        --enable-sockets \
        --enable-soap \
        --enable-mbstring \
        --with-icu-dir=/usr/local/icu \

Great, it works. LDAP is compiled in and everyone is happy.

I go and do the upgrade on the next server, no luck. The compiler for PHP says it can’t find the LDAP files. I check what ldap modules are installed on both machines with this:

dpkg-query -l '*ldap*'

Both machines show different results, the packages are mostly the same, but not exact. In fact the output of the dpkg-query is not the same, one shows an Architecture column and one does not. Hmmm… is one 64 bit and the other 32… checking on that… nope, both are 64 bit.

In the end on the machine with the issue where it says it can’t find the LDAP files I created a symlink to a ldap file I found.

ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/

That was enough that it could compile and things seem to be working, but super frustrating that there are so many differences on machines where I try and keep things the same.

To have DirectAdmin monitor the status of the memecached instance you can add it to /usr/local/directadmin/data/admin/services.status and DirectAdmin will start/restart if necessary.

The DA guys document it here:

PHP Memcache Sessions & Redundancy

I started using memcache to store sessions, rather than having PHP store them on disk. The server hard drives are SSD so I never noticed any performance issue sorting them on disk, but I did not like all those files filling up my /tmp space.

Once moved to memcache, then you have the issue of redundancy. If you have more than one server handling your traffic load, you need something to maintain a sticky session or the user would be logged out of your site (or session information lost) if they move between servers.

Doing some reading there seems to be a lot of bad information out there about exactly how to setup session redundancy across multiple memcache servers.

On a lot of sites I found this syntax to use:


I think that syntax is not correct, but it is that way on many sites. According to the documentation you would not encode the &. In addition all the values they are listing are the defaults. So odds are good those params are not valid like that, but it still works because the values are the default.

One of the better articles I found online was this one at DigitalOcean.

How To Share PHP Sessions on Multiple Memcached Servers on Ubuntu 14.04

His configuration is a bit different than mine, since the OS is different. A couple things to emphasize if you are trying to set this up.

In his example using three servers he says to place the following on each server:

session.save_path = 'tcp://,tcp://,tcp://'

The order here is important, I think a lot of people will want to change the order of the servers, placing the local server first. Don’t do that! In order for the redundancy to work correctly the session.save_path must be the same on all servers. Do not worry about the order, as PHP must contact each server to write the session data anyway.

Multiple Locale Website

This week I am experimenting with multiple languages in PHP based websites. The process is of course not so straight forward, so I am documenting some of what I am doing to get a server setup.

I am using GNU’s GETTEXT and Poedit, in order to get these things running you need to prep the server first. Gettext is well supported in PHP, which is why I am going that route.

On my debian server, I must first install gettext. I just installed the package.

apt-get install gettext

If you want to support a specific language, it must be a supported locale in the host OS as well.

In most linux distributions you can get a list of currently installed languages using:

locale -a

If you try and use gettext with a language that is not supported, it will not work.

On debian to install another supported language, it is fairly easy (I like easy) if you run:

dpkg-reconfigure locales

Then just select the locales you want to support and it takes care of the rest. Doing a locale -a again you should see your newly added languages.