In this article, we will have explained the necessary steps to install and configure Memcached on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with
sudo privileges. All the commands in this tutorial should be run as a non-root user.
Memcached is a free and open-source high-performance memory caching system. It’s typically used to cache database data, API calls, or page rendering chunks in RAM to increase the application’s performance.
- Operating System with CentOS 7
- Server IPv4 Address with Superuser Privileges (Root Access)
- Gnome Terminal for Linux Desktop
- PuTTy SSH client for Windows or macOS
- Powershell for Windows 10/11
- Familiar with YUM/DNF Commands
Install Memcached on CentOS
Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.
sudo yum install epel-release sudo yum update
Step 2. Install Memcached.
Memcached packages are included in the default CentOS 7 repositories. Install Memcached using the following command:
sudo yum install memcached libmemcached
Once the installation is completed, start and enable the Memcached service:
sudo systemctl start memcached sudo systemctl enable memcached
Step 3. Configure Memcached.
The default Memcached configuration file is located in the
sudo nano /etc/sysconfig/memcached
Set or update parameters as follows, customizing them to your needs:
PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="64" OPTIONS="-l 127.0.0.1"
This is a brief description of the parameters:
**PORT**: The default port used by Memcached to run. **USER**: The user Memcached runs as. **MAXCONN**: The maximum number of allowed connections to Memcached. You can increase to any number based on your requirements. **CACHESIZE**: The cache size for memory. **OPTIONS**: Set IP address of server, so that Apache or Nginx web servers can connect to it.
Restart the Memcached service for the changes to take effect:
sudo systemctl restart memcached
Step 4. Install the Memcached PHP Extension.
You can install PHP extension to work with Memcached daemon with the command:
sudo yum install php-pecl-memcache
Now, restart Apache so that the changes take place:
sudo systemctl restart memcached sudo systemctl restart httpd
Congratulation, you have learned how to install and configure Memcached on CentOS 7. I hope this article was helpful to you. If you find it useful, don’t forget to share it with your friend and family. Also, if you have any questions, please feel free to ask in the comments section. We are always there to assist you.