The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Installing memcache and memcached with EasyApache4

Discussion in 'EasyApache' started by cPGeoffS, Aug 25, 2016.

Tags:
  1. cPGeoffS

    cPGeoffS Technical Analyst
    Staff Member

    Joined:
    Dec 11, 2012
    Messages:
    11
    Likes Received:
    3
    Trophy Points:
    3
    cPanel Access Level:
    Root Administrator
    We've recently seen some users have issues with installing the Memcache and Memcached extensions for PHP. Below is a step-by-step guide for getting these installed in a cPanel & EasyApache 4 environment. These directions are specific to PHP 5.6 but should be able to be used with the other versions of PHP offered in EasyApache 4 (simply change out the ea-php56 for the version of PHP you're using, e.g., ea-php55).

    It's important to note this guide only goes over install libmemcached which is necessary to build the PECL Memcached package, the PECL Memcached extension and the PECL Memcache extension. This guide does not cover installing the Memcached daemon. Your hosting provider or systems administrator may be able to assist with the installation of that.

    Before we dive into the installation, let's first make sure we understand what each of these three items are.

    libmemcached is an open source C/C++ client library and tools for the memcached server (memcached - a distributed memory object caching system). It has been designed to be light on memory usage, thread safe, and provide full access to server side methods.

    The PECL memcached package is an extension that uses the libmemcached library to provide API for communicating with memcached servers.

    The PECL memcache package is an extension allows you to work with memcached through handy OO and procedural interfaces.

    Alright, let's get this all installed!

    The first part of the process involves downloading and compiling the libmemcached source code.

    Code:
    wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
    tar -xvzf libmemcached-1.0.18.tar.gz
    cd libmemcached-1.0.18
    ./configure
    make && make install
    Next we'll download the PECL Memcached extension:

    Code:
    /opt/cpanel/ea-php56/root/usr/bin/pecl download memcached
    tar -xvf memcached-2.2.0.tgz
    cd memcached-2.2.0
    /opt/cpanel/ea-php56/root/usr/bin/phpize
    ./configure --with-php-config=/opt/cpanel/ea-php56/root/usr/bin/php-config
    make && make install
    Once the extension has been installed, we need to add it to the proper php.ini configuration file. Since we're installing for PHP 5.6 we need to use this command:

    Code:
    echo 'extension=memcached.so' >> /opt/cpanel/ea-php56/root/etc/php.d/memcached.ini
    Installing memcache can be done with using pecl:

    Code:
    /opt/cpanel/ea-php56/root/usr/bin/pecl install memcache
    
    Build process completed successfully
    Installing '/opt/cpanel/ea-php56/root/usr/lib64/php/modules/memcache.so'
    install ok: channel://pecl.php.net/memcache-2.2.7
    configuration option "php_ini" is not set to php.ini location
    You should add "extension=memcache.so" to php.ini
    
    echo 'extension=memcache.so' >> /opt/cpanel/ea-php56/root/etc/php.d/memcache.ini
    You can confirm both the memcache and memcached extensions are installed and activated using this command:

    Code:
    sandbox [~]# php -m |grep mem
    memcache
    memcached
    Further Resources

    - libMemcached
    - Memcached
    - PECL Memcache Extension
    - PECL Memcached package
    - Installing PECL Memcache on a CentOS 7 server
     
    #1 cPGeoffS, Aug 25, 2016
    Last edited by a moderator: Aug 30, 2016
  2. Anthony Parsons

    Anthony Parsons Active Member

    Joined:
    Aug 4, 2016
    Messages:
    25
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Australia
    cPanel Access Level:
    Root Administrator
    I made it this far, then get an error:
    /configure --with-php-config=/opt/cpanel/ea-php70/root/usr/bin/php-config

    Which says, -bash: /configure: No such file or directory
     
  3. cPMelaniel

    cPMelaniel Technical Analyst Supervisor
    Staff Member

    Joined:
    Jun 25, 2013
    Messages:
    9
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Houston,Tx
    cPanel Access Level:
    Root Administrator
    I've updated the post with the correct command.

    It should be :

    ./configure --with-php-config=/opt/cpanel/ea-php56/root/usr/bin/php-config
     
    Anthony Parsons likes this.
  4. Anthony Parsons

    Anthony Parsons Active Member

    Joined:
    Aug 4, 2016
    Messages:
    25
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Australia
    cPanel Access Level:
    Root Administrator
    I get this error at the end of configure: configure: error: no, sasl.h is not available. Run configure with --disable-memcached-sasl to disable this check

    Which stops the next step with an error: make: *** No targets specified and no makefile found. Stop.
     
  5. Anthony Parsons

    Anthony Parsons Active Member

    Joined:
    Aug 4, 2016
    Messages:
    25
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Australia
    cPanel Access Level:
    Root Administrator
    For those who go nuts with memcached on centos 7, with php7, see liquidweb.com/kb/how-to-install-memcached-on-centos-7/ which worked for me. Sorry... Googled, found this, tried it, and it worked.

    Then, with PHP7 to get pecl-memcache connected and integrated, I found:

    1. wget https://github.com/websupport-sk/pecl-memcache/archive/NON_BLOCKING_IO_php7.zip
    2. unzip NON_BLOCKING_IO_php7.zip
    3. cd pecl-memcache-NON_BLOCKING_IO_php7
    4. /opt/cpanel/ea-php70/root/usr/bin/phpize && ./configure --enable-memcache --with-php-config=/opt/cpanel/ea-php70/root/usr/bin/php-config && make
    5. cp modules/memcache.so /opt/cpanel/ea-php70/root/usr/lib64/php/modules/
    6. echo 'extension=memcache.so' >/opt/cpanel/ea-php70/root/etc/php.d/memcached.ini
    7. service httpd restart

    stackoverflow.com/questions/37550910/memcache-extension-with-php-7-on-centos-fails-to-install
     
    #5 Anthony Parsons, Aug 30, 2016
    Last edited by a moderator: Oct 31, 2016
  6. cPMarkF

    cPMarkF Member
    Staff Member

    Joined:
    Feb 4, 2013
    Messages:
    11
    Likes Received:
    3
    Trophy Points:
    3
    cPanel Access Level:
    Root Administrator
    Regarding sasl support and missing sasl/sasl.h, you need to install the devel libraries for sasl:

    # yum install cyrus-sasl-devel

    You need to do this prior to building libmemcached. If you've already built libmemcached, it's okay to go back into the libmemcached source directory, and run the configure, make, and make install again to rebuild the module with sasl support.

    Thanks for the write-up for PHP 7.0.
     
  7. Anthony Parsons

    Anthony Parsons Active Member

    Joined:
    Aug 4, 2016
    Messages:
    25
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Australia
    cPanel Access Level:
    Root Administrator
    Yer... figured that one out after some searching, LOL. Thanks for posting that though, as I did forget to add it here.
     
  8. cPMarkF

    cPMarkF Member
    Staff Member

    Joined:
    Feb 4, 2013
    Messages:
    11
    Likes Received:
    3
    Trophy Points:
    3
    cPanel Access Level:
    Root Administrator
    Let's have more fun. Need igbinary support in memcached? If you've done all the steps above, you need to remove the source directory of memcached-2.2.0 and untar the tarball again to get a fresh directory.

    Download and install igbinary from PECL:

    Code:
    wget https://pecl.php.net/get/igbinary-1.2.1.tgz
    tar -vxzf igbinary-1.2.1.tgz
    cd igbinary-1.2.1
    /opt/cpanel/ea-php56/root/usr/bin/phpize
    ./configure --with-php-config=/opt/cpanel/ea-php56/root/usr/bin/php-config
    make && make install
    

    Create your igbinary.ini

    Code:
    echo 'extension=igbinary.so' >> /opt/cpanel/ea-php56/root/etc/php.d/igbinary.ini
    

    Go into your newly re-extracted memached-2.2.0 directory and rebuild memcached, enabling igbinary support (note: if you've already built memcached using the previous steps outlined above in this thread, you do not need to create or echo the module into the memcached.ini again)

    Code:
    cd memcached-2.2.0
    /opt/cpanel/ea-php56/root/usr/bin/phpize
    ./configure --with-php-config=/opt/cpanel/ea-php56/root/usr/bin/php-config --enable-memcached-igbinary
    

    During the config.status output, you should see these lines:

    Code:
    checking whether to enable memcached igbinary serializer support... yes
    checking for memcached igbinary support... enabled
    

    If not, make sure you followed the steps above to install igbinary. If so, then:

    Code:
    make && make install
    

    Afterwards, you should see igbinary support not only in PHP, but also for memcached:

    Code:
    [17:21:38 sg root@server ~/memcached-2.2.0]cPs# php -i | grep igbinary
    /opt/cpanel/ea-php56/root/etc/php.d/igbinary.ini,
    igbinary
    igbinary support => enabled
    igbinary version => 1.2.1
    igbinary APC serializer ABI => 0
    igbinary session support => yes
    igbinary.compact_strings => On => On
    igbinary support => yes
    memcached.serializer => igbinary => igbinary
    Registered serializer handlers => php_serialize php php_binary igbinary wddx
    
    Hope this helps!
     
    #8 cPMarkF, Sep 9, 2016
    Last edited: Sep 9, 2016
    cPanelMichael likes this.
  9. Neso

    Neso Member

    Joined:
    Feb 11, 2009
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Installing memcached over yum install memcahed OK on my VPS (Centos 7.2, EA4 with PHP 5.6) and all work OK, but yum install old version of memcached 1.4.15 and latest one is 1.4.30 with meany fix and improvements

    I installed manually latest version, but how do I start it ?

    When I run service memcached start I get this error:

    Failed to start memcached.service: Unit memcached.service failed to load: No such file or directory.
     
    #9 Neso, Sep 26, 2016
    Last edited: Sep 26, 2016
  10. dalem

    dalem Well-Known Member
    PartnerNOC

    Joined:
    Oct 24, 2003
    Messages:
    2,577
    Likes Received:
    40
    Trophy Points:
    48
    Location:
    SLC
    cPanel Access Level:
    DataCenter Provider
  11. Patrik Johnsson

    Patrik Johnsson Registered

    Joined:
    Dec 4, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello, thanks for this guide.

    I'm doing this on PHP 7.1 and get the following error:

    In file included from /usr/local/src/memcached-2.2.0/php_memcached.c:26:0:

    /usr/local/src/memcached-2.2.0/php_memcached_private.h:44:40: fatal error: ext/standard/php_smart_str.h: No such file or directory

    #include <ext/standard/php_smart_str.h>​

    This after make && make install

    Any help would be greatly appreciated.
     
  12. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,666
    Likes Received:
    646
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  13. Patrik Johnsson

    Patrik Johnsson Registered

    Joined:
    Dec 4, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi, yes, that works for memcache, but I'm seeing this on memcached

    In file included from /memcached-2.2.0/php_memcached.c:26:0:

    /memcached-2.2.0/php_memcached_private.h:44:40: fatal error: ext/standard/php_smart_str.h: No such file or directory

    #include <ext/standard/php_smart_str.h>

    ^

    compilation terminated.

     
Loading...

Share This Page