This section provides instructions to install memcached on Ubuntu.
Adobe recommends using memcached version 3.0.5 or later.
Because PHP has no native support for memcache, you must install an extension for PHP to use it. There are two PHP extensions available and it is important to decode which to use:
memcache
(no d)—an older but popular extension that is not maintained regularly.
The memcache
extension currently does not work with PHP 7. See PHP documentation for memcache.
The exact name is php5-memcache
for Ubuntu.
memcached
(with a d
)—a newer and maintained extension that is compatible with PHP 7. See PHP documentation for memcached.
The exact name is php5-memcached
for Ubuntu.
To install and configure memcached on Ubuntu:
As a user with root
privileges, enter the following command:
apt-get -y update
apt-get -y install php5-memcached memcached
Change the memcached configuration setting for CACHESIZE
and -l
:
Open /etc/memcached.conf
in a text editor.
Locate the -m
parameter.
Change its value to at least 1GB
Locate the -l
parameter.
Change its value to 127.0.0.1
or localhost
Save your changes to memcached.conf
and exit the text editor.
Restart memcached.
service memcached restart
Restart your web server.
For Apache, service apache2 restart
Continue with the next section.
Adobe recommends testing memcached to make sure it works before you install Commerce. Doing so takes only a few minutes and can simplify troubleshooting later.
To verify that memcached is recognized by the web server:
Create a phpinfo.php
file in the web server’s docroot:
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
Go to that page in your web browser. For example:
http://192.0.2.1/phpinfo.php
Make sure memcached displays as follows:
Verify you are using memcached version 3.0.5 or later.
If memcached does not display, restart the web server and refresh the browser page. If it still does not display, verify you installed the php-pecl-memcached
extension.
This test uses a PHP script to verify that memcached can store and retrieve cache data.
For more information about this test, see How To Install and Use Memcache on Ubuntu tutorial.
Create cache-test.php
in the web server’s docroot with the following contents:
$meminstance = new Memcached();
$meminstance->addServer("<memcached hostname or ip>", <memcached port>);
$result = $meminstance->get("test");
if ($result) {
echo $result;
} else {
echo "No matching key found. Refresh the browser to add it!";
$meminstance->set("test", "Successfully retrieved the data!") or die("Could not save anything to memcached...");
}
Where <memcached hostname or ip>
is either localhost
, 127.0.0.1
, or the memcache hostname or IP address. The <memcached port>
is the listen port; by default, 11211
.
Go to that page in a web browser. For example
http://192.0.2.1/cache-test.php
The first time you go to the page, the following displays: No matching key found. Refresh the browser to add it!
Refresh the browser. The message changes to Successfully retrieved the data!
Finally, you can view the memcache keys using Telnet:
telnet localhost <memcache port>
At the prompt, enter
stats items
The result is similar to the following:
STAT items:2:number 1
STAT items:2:age 106
STAT items:2:evicted 0
STAT items:2:evicted_nonzero 0
STAT items:2:evicted_time 0
STAT items:2:outofmemory 0
STAT items:2:tailrepairs 0
STAT items:2:reclaimed 0
STAT items:2:expired_unfetched 0
STAT items:2:evicted_unfetched 0
Flush memcached storage and quit Telnet:
flush_all
quit