Setting up memcached via unix sockets in BitrixVM
Posted: Thu Feb 20, 2025 3:44 am
Almost all Bitrix projects (both websites and corporate portals) are recommended to be installed on VPS or dedicated servers and necessarily in the BitrixVM web environment .
As Bitrix themselves write on their website, BitrixVM is specially configured for fast execution of 1C-Bitrix software products: it is deployed in minutes and is immediately ready for work.
However, by default, the virtual machine and Bitrix itself have a setting for caching data in the file system. In modern realities with SSD drives (especially NVMe), the file cache will work quite quickly, but still much slower than from RAM.
Another problem is that if caching is configured incorrectly, you can fill up the entire file system with cache files: then you will either run out of disk space or free inodes of the file system. After that, your site will stop opening with the MySQL error "Got error 122 from storage engine" (we will talk about this in another article).
To configure cache storage in the server's RAM, the virtual machine mexico mobile database provides the ability to install memcached and connect it as a cache keeper for Bitrix. To install and configure memcached for best performance, you need to:
Installing memcached
The easiest way to install it is through the toolbar that comes with the virtual machine:
By default, memcached is installed on the local machine and allows connections via TCP sockets (via port 11211 by default). This is not the most productive method, so it is better to switch memcached to work via a unix socket.
Setting up work via unix socket
The memcached daemon settings in CentOS 7.5 are located in the /etc/sysconfig/memcached file. Its default contents are as follows:
PORT="0" allows you to disable TCP socket listening.
USER="bitrix" specifies the owner of the socket file that we are going to create. No one except the owner will be able to read or write anything to the socket.
CACHESIZE="64" we left as is, but in this parameter you can specify the amount of memory (in megabytes) that you want to allocate for the cache.
OPTIONS are the main settings for creating a socket file, there are two of them:
-s /tmp/memcached.sock specifies the path and name of the future socket file
-a 0600 defines access rights to the file
After making changes, you need to restart memcached with the command:
systemctl restart memcached
The last thing you need to do to make Bitrix write cache to memcached instead of files is to make changes to the file /bitrix/.settings.php by adding the key there.
As Bitrix themselves write on their website, BitrixVM is specially configured for fast execution of 1C-Bitrix software products: it is deployed in minutes and is immediately ready for work.
However, by default, the virtual machine and Bitrix itself have a setting for caching data in the file system. In modern realities with SSD drives (especially NVMe), the file cache will work quite quickly, but still much slower than from RAM.
Another problem is that if caching is configured incorrectly, you can fill up the entire file system with cache files: then you will either run out of disk space or free inodes of the file system. After that, your site will stop opening with the MySQL error "Got error 122 from storage engine" (we will talk about this in another article).
To configure cache storage in the server's RAM, the virtual machine mexico mobile database provides the ability to install memcached and connect it as a cache keeper for Bitrix. To install and configure memcached for best performance, you need to:
Installing memcached
The easiest way to install it is through the toolbar that comes with the virtual machine:
By default, memcached is installed on the local machine and allows connections via TCP sockets (via port 11211 by default). This is not the most productive method, so it is better to switch memcached to work via a unix socket.
Setting up work via unix socket
The memcached daemon settings in CentOS 7.5 are located in the /etc/sysconfig/memcached file. Its default contents are as follows:
PORT="0" allows you to disable TCP socket listening.
USER="bitrix" specifies the owner of the socket file that we are going to create. No one except the owner will be able to read or write anything to the socket.
CACHESIZE="64" we left as is, but in this parameter you can specify the amount of memory (in megabytes) that you want to allocate for the cache.
OPTIONS are the main settings for creating a socket file, there are two of them:
-s /tmp/memcached.sock specifies the path and name of the future socket file
-a 0600 defines access rights to the file
After making changes, you need to restart memcached with the command:
systemctl restart memcached
The last thing you need to do to make Bitrix write cache to memcached instead of files is to make changes to the file /bitrix/.settings.php by adding the key there.