How to Install Memcached on Alma Linux 8
Memcached stands for “memory object caching systems”, is an open-source and high-performance distributed memory caching system used to speed up dynamic database-driven web applications. It caches data in memory that are generated from page load requests or API calls. Memcached is very useful for database query results caching, session caching, web page caching, API caching, and caching of objects such as images, files, and metadata. You can use Memcached in PHP-based applications including WordPress and Joomla to run smoothly without much latency.
In this post, we will guide you through the steps of installing Memcached on Alma Linux 8
Install Memcached on Alma Linux 8
By default, the Memcached package is included in the Alma Linux default repository. You can install it by running the following command:
dnf install memcached libmemcached -y
After installing Memcached, you can see the installed package information using the following command:
rpm -qi memcached
You will get the following output:
Now, start and enable the Memcached service using the following command:
systemctl enable memcached --now
To check the status of the Memcached use the following command:
systemctl status memcached
You should see the following output:
By default, Memcached listens on port 11211, you can check it using the following command:
ps -ef | grep memcached
You should see the following output:
Configure Memcached
Memcached main configuration file is located at /etc/sysconfig/memcached. You can configure it as shown below:
vi /etc/sysconfig/memcached
Change the following lines as per your requirements:
Save and close the file then restart the Memcached service to apply the changes:
systemctl restart memcached
Configure Firewalld
If you are using firewalld on your system, then you will need to allow ports 11211 and 80 through the firewalld. You can allow them by running the following command:
firewall-cmd --add-port=11211/tcp --zone=public --permanent firewall-cmd --add-port=80/tcp --zone=public --permanent
Next, reload the firewalld to apply the changes:
firewall-cmd --reload
You can now list all firewalld ports using the following command:
firewall-cmd --list-ports
Install PHP with Memcached Support
If you want to integrate Memcached with a PHP-based application, then you need to install the Memcached extension for PHP.
First, install the EPEL and Remi repo using the following command:
dnf install epel-release -y dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
Next, enable the PHP Remi repository using the following command:
dnf module enable php:remi-7.4 -y
Next, install the Memcached extension for PHP using the following command:
dnf install php-pecl-memcache php-pecl-memcached -y
Once all the packages are installed, you can proceed to the next step.
Verify Memcached for PHP<
Next, you will need to install the Nginx web server and create a sample PHP page to verify the Memcached. You can install Nginx and other PHP packages using the following command:
dnf install nginx php php-cli -y
Next, create an info.php page:
vi /var/www/html/info.php
Add the following lines:
<?php phpinfo(); ?>
Save and close the file then create a symbolic link of the PHP page to the Nginx default web root directory:
ln -s /var/www/html/info.php /usr/share/nginx/html/
Next, start and enable the Nginx service to apply the changes:
systemctl start nginx systemctl enable nginx
Now, open your web browser and access the URL http://your-server-ip/info.php. You should see Memcached on the following page:
Conclusion
Congratulations! you have successfully installed Memcached on Alma Linux 8. You can now use Memcached as a caching database to speed up your PHP-based website and applications.