Install and Configure PrestaShop With Memcached

Posted on June 15th, 2020

Memcached is an open-source, free memory object caching system that helps to reduce access and execution time to the database for an extensive web application. The Memcached frequently caches the accessed data, such as the results of database calls, API calls, and more to speed up the dynamic database-driven web apps. In this knowledgebase, you learn how to install Memcached and then configure PrestaShop with Memcached on your Ubuntu server.

In this tutorial, we are going to Install and Configure PrestaShop With Memcached on Ubuntu. The process to configure PrestaShop with Memcached on your Ubuntu server are:

  1. Install Memcached on the Server
  2. Configure the Memcached Setup
  3. Verify the Installation
  4. Install Memcached PHP Module
  5. Configure PrestaShop with Memcached

In this tutorial, We will see each one of the step in detail. So, Let’s get started with the first step.

Install Memcached on Ubuntu

To install Memcached on your Ubuntu server, follow the below process.

1) Log in to the server as an ssh user with sudo privilege.

2) First, update the apt package cache by using the following command.

$ sudo apt-get update

3) Install the Memcached server by executing the following command.

$ sudo apt-get install memcached

Once installed, we have to configure Memcached according to our requirements. So, Let’s do it.

Configure the Memcached Set Up

You can configure the Memcached by using the following settings in the configuration file of Memcache.

$ sudo vim /etc/memcached.conf

If you want to configure your Memcached server to run as a service, then you can use the ‘-d’ option. The -d runs the Memcached in daemon mode.

You can use the ‘-m’ option to define the maximum number of memory that the Memcached daemon can use. The default value of the same is 64 MB.

It is also possible to define the port number to which the Memcached daemon listens to using the ‘-p’ option. The default port number to which Memcached daemon listens to is 11211.

You can use the ‘-I’ option to set the IP address to which the Memcached listens. If you want Memcached to listen to all the IPs configured on the system, then set the value of ‘-I’ to 0.0.0.0.

After making the changes in the configuration file, restart the Memcached service by using the following command.

$ sudo service memcached restart

Now, Let’s verify the Memcached installation.

Verify the Installation of Memcached

To verify if the installed Memcached is running correctly on your server, then run the following command. The following command shows the current statistics of the Memcached server.

$ sudo echo “stats settings” | nc localhost 11211

The above-given echo command displays the set of Memcached values. In the following report, you can see an example output for the command.

STAT maxbytes 134217728

STAT maxconns 1024

STAT tcpport 11211

STAT udpport 11211

STAT inter 127.0.0.1

STAT verbosity 0

STAT oldest 0

STAT evictions on

STAT domain_socket NULL

STAT umask 700

STAT growth_factor 1.25

STAT chunk_size 48

STAT num_threads 4

STAT num_threads_per_udp 4

STAT stat_key_prefix :

STAT detail_enabled no

STAT reqs_per_event 20

STAT cas_enabled yes

STAT tcp_backlog 1024

STAT binding_protocol auto-negotiate

STAT auth_enabled_sasl no

STAT item_size_max 1048576

STAT maxconns_fast no

STAT hashpower_init 0

STAT slab_reassign no

STAT slab_automove 0

STAT lru_crawler no

STAT lru_crawler_sleep 100

STAT lru_crawler_tocrawl 0

STAT tail_repair_time 0

STAT flush_enabled yes

STAT hash_algorithm jenkins

STAT lru_maintainer_thread no

STAT hot_lru_pct 32

STAT warm_lru_pct 32

STAT expirezero_does_not_evict no

END

Now, We have to install the PHP Module for Memcached. It allows our PHP based website to interact with Memcached.

Install Memcached PHP Module

After confirming the set up of Memcached, you need to install the latest PHP on your Memcached server. If PHP is already available on your Ubuntu server, you can skip it till step 3 and follow the other steps. To install the latest PHP version from the ‘ppa:ondrej/php’ PPA on your Ubuntu server, execute the following commands.

First, add the ‘ppa:ondrej/php’ PPA on your Ubuntu server using the following command.

$ sudo add-apt-repository ppa:ondrej/php

Then, update the apt package cache by using the following command.

$ sudo apt-get update

Execute the below command to install the latest PHP version.

$ sudo apt-get install -y php php-pear php-dev libapache2-mod-php

Then, install the PHP Memcached module on your Ubuntu system. Run the following command to set the required configuration.

$ sudo apt-get install -y php-memcached

After the installation, run the following command to restart the Apache service.

$ sudo service apache2 restart

Then, check if the Memcache PHP extension is available and working correctly on your server. Create a file and name it as ‘info.php’.

$ sudo nano info.php

Then, add the following code inside the info.php file.

<?php
phpinfo();
?>

Now, access the info.php from the web interface and then, search for Memcached. The search for Memcached should show an output similar to one shown in the following screenshot in the web interface.

Install PrestaShop

Configure PrestaShop With Memcached

Now, the Memcached is running on the server. After that, follow the steps below to configure PrestaShop with Memcached.

  1. Log in to your PrestaShop as an administrator user.
  2. Click the ‘Advanced Parameters’ from the left-side menu bar.
  3. Then, navigate to Performance.
  4. In the Performance page, scroll down to the ‘CACHING’ section and then set the status of ‘Use Cache’ to Yes option.
  5. Select the ‘Memcached via PHP::Memcached’ option from the list of the Caching system.
  6. Click the ‘+Add Server’ button and then set the IP Address and Port in the text boxes.
  7. Then, click the ‘Test Server’ button to check if the filled details are proper. If you see green color, then the details filled is correct, but if it is having any problem, then it shows a red color.
  8. If everything is proper, click the ‘Add server’ button to add the configurations.
  9. Finally, click the ‘Save’ button to configure PrestaShop with Memcached.

Install PrestaShop

 

Conclusion

Memcached is an open-source, free memory object caching system that helps to reduce access and execution time to the database for a broad web application. The Memcached frequently caches the accessed data, such as the results of database calls, API calls, and more to speed up the dynamic database-driven web apps. We hope that this knowledge base was helpful to you. Please comment below for any questions or queries. If you are an InterServer customer, please reach out to our support team for further help.

Leave a Reply