Report this

What is the reason for this report?

How do I enable memcached when upgrading from PHP 5.5 to 5.6?

Posted on June 3, 2019

I’ve been using the memcached module with no problems on my site with PHP 5.5 and Ubuntu 14. I’m trying to update my site to PHP 5.6, but when I disable PHP 5.5 and enable PHP 5.6, the memcached module is no longer loaded when I restart Apache according to the phpinfo. How do I tell PHP 5.6 to load the memcached module?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

First you need to make sure that you have the php-memcache module installed for PHP 5.6, then you need to make sure that the memcache.so extension is specified in your PHP 5.6 php.ini file.

Hope that this helps.

Heya,

When upgrading PHP versions, it’s common to encounter issues with extensions that were working fine in older versions. This usually happens because the extension may not be compiled for the new version of PHP, or the configuration pointing to the extension is not set up for the new version. Here’s how you can ensure the memcached module is loaded for PHP 5.6, and I’ll also explain how to do it for PHP 8.1, as requested.

For PHP 5.6

Step 1: Install the PHP 5.6 Memcached Module

First, ensure that the memcached module is installed for PHP 5.6. You might need to install it if it was only installed for PHP 5.5:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6-memcached

Step 2: Check if the Module is Enabled

You can check if the module is enabled by looking at the list of modules:

bashCopy code

php5.6 -m | grep memcached

Step 3: Ensure Configuration Files Are Correct

Ensure that the configuration for memcached is set up correctly in PHP 5.6’s mods-available directory:

  • Look for a file named memcached.ini or similar in /etc/php/5.6/mods-available/.
  • The file should contain a line like: extension=memcached.so.

If the file exists and is configured correctly, make sure it’s symlinked in the conf.d directory for PHP 5.6:

sudo ln -s /etc/php/5.6/mods-available/memcached.ini /etc/php/5.6/apache2/conf.d/20-memcached.ini
sudo ln -s /etc/php/5.6/mods-available/memcached.ini /etc/php/5.6/cli/conf.d/20-memcached.ini

Step 4: Restart Apache

Restart Apache to apply the changes:

sudo service apache2 restart

For PHP 8.1

Step 1: Install the PHP 8.1 Memcached Module

With PHP 8.1, the process is similar but tailored for the newer version:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php8.1-memcached

Step 2: Check if the Module is Enabled

Verify that the module is enabled for PHP 8.1:

php8.1 -m | grep memcached

Step 3: Ensure Configuration Files Are Correct

Check the mods-available directory for the memcached configuration:

  • Look for memcached.ini in /etc/php/8.1/mods-available/.
  • It should include: extension=memcached.so.

Ensure the configuration file is linked to both the CLI and Apache2 configurations:

sudo ln -s /etc/php/8.1/mods-available/memcached.ini /etc/php/8.1/apache2/conf.d/20-memcached.ini
sudo ln -s /etc/php/8.1/mods-available/memcached.ini /etc/php/8.1/cli/conf.d/20-memcached.ini

Step 4: Restart Apache

Finally, restart Apache to make sure all settings take effect:

sudo service apache2 restart

General Advice

  • Check for Errors: Look at Apache’s error log (/var/log/apache2/error.log) for any messages related to PHP or memcached.
  • PHP Info: After restarting Apache, create a PHP info file to check if the memcached extension is loaded:
<?php phpinfo(); ?>

View this file in a browser to see if the memcached section appears, confirming the module is loaded correctly.

By following these steps, you should be able to get the memcached module working with both PHP 5.6 and PHP 8.1 on your Ubuntu system.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.