简体   繁体   中英

How to install php-memcache in xampp ubuntu?

I have installed xampp for linux from https://www.apachefriends.org/index.html in my Ubuntu 22.04 OS

After successfully installed, my project is running fine but when I install the php-memchached in my system with the below command but it is not showing in my phpinfo() page.

Command:

sudo apt-get install -y php-memcached

Also I tried with the code to check my Memcached Successfully installed or not. But I got the error message that Class 'Memcached' not found

Code:

$memcached = new Memcached();
$memcached->addServer("127.0.0.1", 8080);
$response = $memcached->get("sample_key");

if($response==true) {
    echo $response;
} else {
    echo "Cache is empty";
    $memcached->set("sample_key", "Sample data from cache") ;
}

Error Output in Yii console:

Class 'Memcached' not found

Please let me know how to install the php-memcached in Xappp for my ubuntu system?

php-memcached extension uses the libmemcached library to provide an API for communicating with memcached servers.

So, This extension requires libmemcached client library .

The steps in outline:

sudo apt-get update
sudo apt-get install -y memcached
sudo apt-get install -y php-memcached
sudo systemctl restart memcached
sudo /opt/lampp/lampp restart

Don't forget to check extension=memcached.so in the php.ini, and path to extension dir...as shingo points out in his commentary

References for more details:

https://www.php.net/manual/en/book.memcached.php

https://www.alibabacloud.com/blog/how-to-set-up-memcached-with-php-on-ubuntu-18-04_595628

Steps for installing php-memcached in ubuntu

first, go to the /opt/lampp/bin/ then run the below command

> sudo pecl install Memcached

OR

> /opt/lampp/bin/pecl install memcached

Once installed then open php.ini(my ini path /opt/lampp/etc/php.ini ) and add the below line in that file

extension=memcached.so

Finally, restart XAMPP

> sudo /opt/lampp/lampp restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM