Have you ever thought what slows down your server? This may be due to a large number of request for a database in a single time.

Here’s PHP FPM Memcached’s role which is a distributed memory caching system. This can reduce database load and accelerates web applications.

At Bobcares, we often get requests from our customers set up PHP FPM Memcached as part of our Server Management Services.

Today, we’ll see how our Support Engineers set up PHP FPM with Memcached and fix the related errors.

What is PHP FPM Memcached?

PHP FPM Memcached can speed up the delivery of the website’s data by storing the most frequently used resources in the cache. Therefore, it amplifies the customer experience through a better response time of the websites.

In addition, Memcached minimizes the database loads by storing data objects in dynamic memory, resulting in faster Web applications. Also, Memcached stores data in key/value pairs in the form of large hash tables.

 

How we installed PHP FPM Memcached Module​

Here’re the steps how our Support Engineers install Memcached with PHP-FPM on Nginx.

1. Firstly, we run the following command to install Memcached.

apt install memcached

2. After installing Memcached, we enable and start the Memcached service

systemctl enable memcached.service

systemctl start memcached.service

3. Then we run the following commands to install PHP with Nginx and Memcached modules.

apt-get install php-fpm php-memcached php-cli

4. Next, we enable Nginx PHP site support in default site configuration file and enable the PHP block. To enable PHP block, we uncomment to enable the PHP section.

nano /etc/nginx/sites-available/default

6. At last, we restart Nginx Web server.

systemctl reload nginx.service

 

Moreover, to test whether the Memcached is properly installed, we use info.php file to test it. The output looks like,

Related errors and how we fixed it

From our experience in managing server, we’ve seen that customers facing problems after installing Memcached. Let’s take a closer look at how our Support Engineers fixed the problems.

 

1. Wrong IP address settings

Recently, one of the customers reported problems with PHP FPM Memcached on their Amazon EC2 instances pool. But Memcache was not connecting on one of the servers.

On checking, our Support engineers found that Memcached was running on the server.

root@ip-172-xx-xx-125:~ # sockstat -4l | grep mem
nobody memcached 26445 17 tcp4 *:11211 *:*
nobody memcached 26445 22 udp4 *:11211 *:*
nobody memcached 26445 23 udp4 *:11211 *:*
nobody memcached 26445 24 udp4 *:11211 *:*
nobody memcached 26445 25 udp4 *:11211 *:*

However, Memcached service was configured to listen on server address and this was creating problems here.

It is always recommended to use private IP connections between servers in the same datacenter. This will ensure a faster network connection and maximum service security.

Therefore, we set the Memcached service to listen on the private IP-addresses on EC2 instances instead of the public IP addresses. And, the problem was fixed.

 

PHP FPM service down

Similarly, another customer had an issue after installing Memcached. He got an error “Fatal error: Class ‘Memcached’ not found” while enabling Memcached on the server.

Then our Support Engineers took the following steps to solve the error.

1. Firstly, we logged into the server as root user.

2. Then, we checked the status of service php5-fpm.

service php5-fpm status

3. So, we found that the php5-fpm service was down.

4. At last, we restarted the php5-fpm service.

service php5-fpm restart

This is how we fixed the error.

 

[Having trouble while setting up PHP FPM Memcached? We’ll fix it for you.]

 

Conclusion

In short, Memcached increases the delivery speed of the website’s data by storing the most frequently used resources in the cache. Today, we saw how our Support Engineers setup PHP FPM Memcached and fixed related errors.



Source link

Author

Write A Comment