#!/bin/bash
# Memcached (service & related PHP modules) installation on cPanel/WHM servers
#
# by Fotis Evangelou (Engintron)
#
# Updated: May 2018
#
# USAGE:
# Upload this file at the root (/) folder of your cPanel/WHM server (on CentOS 7)
# and make it executable with: $ chmod +x /memcached_installer_for_cpanel.sh
#
# Then execute it with:
# $ /memcached_installer_for_cpanel.sh
#
# To define a different cache pool size (e.g. 512M), execute with:
# $ /memcached_installer_for_cpanel.sh 512M
#
# Enjoy!
CACHE_SIZE="256M"
if [[ $1 ]]; then
CACHE_SIZE=$1
fi
clear
echo " ****************************************************"
echo " * Installing Memcached *"
echo " ****************************************************"
# Let's update the system first
yum clean all
yum -y update
yum -y upgrade
# Install memcached & start it
yum -y install memcached memcached-devel ea4-experimental
service memcached start
chkconfig memcached on
# Adjust its cache size to 512M & restart
if [ -e "/etc/sysconfig/memcached" ]; then
sed -i 's/CACHESIZE=.*/CACHESIZE="'${CACHE_SIZE}'"/' /etc/sysconfig/memcached
fi
service memcached restart
# Install related PHP modules for PHP versions 5.6 to 7.2
yum -y install ea-php56-php-memcached ea-php70-php-memcached ea-php71-php-memcached ea-php72-php-memcached
# Finish things up by restarting web services
service memcached restart
# Restart Apache & PHP-FPM
if [ "$(pstree | grep 'httpd')" ]; then
echo "Restarting Apache..."
/scripts/restartsrv apache_php_fpm
/scripts/restartsrv_httpd
echo ""
fi
# Restart Nginx (if it's installed via Engintron)
if [ "$(pstree | grep 'nginx')" ]; then
echo "Restarting Nginx..."
service nginx restart
echo ""
fi
# Print out useful info
memcached -h
php -i | grep -i memcache
echo " ****************************************************"
echo " * Memcached installation complete *"
echo " ****************************************************"