Memcached on Void Linux

Void does not provide runit service for Memcached, so we have to write our own.

  1. Install memcached:

    # xbps-install memcached
  2. Create separate user and group for memcached daemon:

    # useradd --system _memcached
  3. Create service directory:

    # mkdir /etc/sv/memcached
  4. Create the /etc/sv/memcached/run file, adjust it to your needs:

    #!/bin/sh
    exec 2>&1
    exec chpst -u _memcached:_memcached memcached -m 32 -l 127.0.0.1 -p 11211 2>&1
  5. Make it executable.

    # chmod +x /etc/sv/memcached/run
  6. Enable service if needed:

    # ln -s /etc/sv/memcached /var/service/

Optional: PHP Module

If you, like me, want to use memcached from PHP, you'll also have to compile the PECL Memcached module, since Void also doesn't provide it in repos.

First of all, install required dependencies. For the sake of example I'll assume we're working with php version 8.1.

# xbps-install gcc autoconfig make pkg-config zlib-devel libmemcached-devel php8.1-devel

Download latest version of memcached module sources:

# cd /usr/src
# wget "https://pecl.php.net/get/memcached-3.2.0.tgz"

Unpack and compile:

# tar xvf memcached-3.2.0.tgz
# cd memcached-3.2.0
# phpize8.1
# ./configure --with-php-config=/usr/bin/php-config8.1
# make -j$(nproc)

Install the extension:

# make install

Enable it by addding the following line to /etc/php8.1/php.ini:

extension=memcached

Check that it's loaded:

# php -m | grep memcached

In the end, don't forget to restart php-fpm or similar services if needed.

If you have any comments, contact me by email.