Memcached is a distributed memory object caching system which stored data in memory on key-value basis. It is very useful for optimizing dynamic websites and enabled speed by caching objects in memory. Read more about memcache.
This article will help you to install Memcached on Fedora Linux systems.
Install Memcached on Fedora
Memcached is available under default Fedora repositories. You can install it by running the following command on your Fedora Linux system.
sudo dnf install memcached -y
Now start the Memcached service using the following commands.
sudo systemctl enable memcached.service
sudo systemctl start memcached.service
Edit the Memcached default configuration file in your favorite text editor.
sudo vim /etc/sysconfig/memcached
and update the settings as per your system requirements. Here CACHESIZE is the max memory limit in Mb, which Memcached can use.
PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="64" OPTIONS=""
The above configuration shows that Memcached can use up to 64 Mb memory on the system.
After doing any changes, restart the Memcached server to apply changes.
sudo systemctl restart memcached.service
View Memcached Stats
You can view the service status using the systemctl command
sudo systemctl status memcached.service
You can also view the statics of the running Memcached service using “stats settings” command. Below is the example to send this command to the Memcached server and see the results.
echo "stats settings" | nc localhost 11211
STAT maxbytes 67108864 STAT maxconns 1024 STAT tcpport 11211 STAT udpport 11211 STAT inter 127.0.0.1 STAT verbosity 0 STAT oldest 0 STAT evictions on STAT domain_socket NULL STAT umask 700 STAT growth_factor 1.25 STAT chunk_size 48 STAT num_threads 4 STAT num_threads_per_udp 4 STAT stat_key_prefix : STAT detail_enabled no STAT reqs_per_event 20 STAT cas_enabled yes STAT tcp_backlog 1024 STAT binding_protocol auto-negotiate STAT auth_enabled_sasl no STAT item_size_max 1048576 STAT maxconns_fast no STAT hashpower_init 0 STAT slab_reassign no STAT slab_automove 0 END
Install Memcache PHP Extension
You need to enable Memcache/Memcached PHP extension on your server to connect PHP with the Memcached service. There are basically two Memcache PHP modules available to install. One is named Memcache and the other Memcached. So install the module as per your uses.
sudo dnf install php-pecl-memcache
sudo dnf install php-pecl-memcached
After installation restarts the Apache service.
sudo systemctl restart httpd.service
Now check if memcache php extension is enabled and working properly. Create a phpinfo.php file using following code
Now access http://server-ip-addr/phpinfo.php on the web browser and search for Memcache, You will see the results below.