This article contains general information on how to install and configure Memcached server, required php extensions, and how to install and configure phpMemcachedAdmin to collect statistics and analyze memcached server performance.
Memcached is software that implements hash table based in-memory data caching service. Provides the ability to cache data in the RAM of most available servers with a high quality client library.
It’s also worth understanding the difference between Memcached Server and the Memcache php extension. If the functionality of the Memcache extension is sufficient for your project (since the functionality of the extension is limited, but it can provide speed and use fewer resources), then we recommend using thhed server will be performed using the example of the Debian 10 distribution with installation on different server sets – Apache and Nginx-PHP-FPM.hed server will be performed using the example of the Debian 10 distribution with installation on different server sets – Apache and Nginx-PHP-FPM.
First, you need to configure the web server for the domain and sites to work correctly.
The next step is to install the Memcached server directly.
First you need to update the repository:
apt-get update && apt-get upgrade
Next, you need to install Memcached and the php module to work correctly:
apt-get install memcached php-memcache
After installation, we can check if the service is running and whether it uses the local server to work:
netstat -tap | grep memcached
It is necessary to correct the configuration of the Memcached server before using it directly.
For Debian / Ubuntu, this is the /etc/memcached.conf file, for CentOS – / etc / sysconfig / memcached
You need to edit the following settings:
-m 1024 - max number of connections
-c 2048 - the size of memory that is allocated for memcached
-l 127.0.0.1 set the local interface
-U 0 - disable UDP to prevent most common attacks on the memcached server
As a result, the configuration file may look like this:
After making changes to the configuration, restart memcached:
service memcached restart
Next, you need to reboot the server that is currently running on the server:
service apache2 restart
service nginx restart
service php-fpm restart
To test the operation of the memcached server, you can use a simple php script that will add an entry to the cache and retrieve it from there.
Place the test file with the following code in the root of the site:
Next, go to the site by the name of the file in the browser and see the result of the work:
To install and configure phpMemcachedAdmin – software that provides a web interface for monitoring, collecting statistics and managing Memcached, we provide an option to create a subdirectory at the root of the site and configure authentication for access.
First, you need to create a folder in the site directory to upload the latest software version there:
mkdir phpMemcachedAdmin && cd phpMemcachedAdmin
wget https://github.com/elijaa/phpmemcachedadmin/archive/master.zip
Next, unpack the archive into the target folder and set up access rights for it:
unzip master.zip
mv phpmemcachedadmin-master/* .
find ./ -type f -exec chmod 0644 {} \;
find ./ -type d -exec chmod 0755 {} \;
Next, you need to create a .htaccess file to provide authorization:
Set a password:
htpasswd -c .htpasswd memcachedmanager
We can check the result by clicking on the folder name in the root of the site:
Additionally, you may need to change the rights to folders in the phpMemcachedAdmin directory and edit the correct path to the configuration file:
chmod -R 777 Temp/ Config/