How to Install Memcache on Linux / cPanel Server
How to Install PHP Memcache on Linux / cPanel Server
Slow websites are one of the main reasons why many websites lose the customers and sales. You must use some caching methods to reduce the loading time of the website. Memcache is a memory object caching system that makes your websites load faster, by fetching the cached data quickly from the memory.
1. How to Install Memcache on Easyapache 4 cPanel Servers
Do the below steps to Install memcache on easyapache 4 server. Do not run the below commands on an easyapache 3 server.
Run the command ‘/scripts/easyapache –version’ to check whether it is an easyapache 3 or easyapache 4 server. Easyapache 3 server will show the exact version when you run this command. On Easyapache EA4 servers you will see ‘EasyApache4 is in effect’.
A. Install memcache for PHP 5.4 on EA4 server :
1. Log into your cPanel server via SSH as root user.
2. Use pecl to install memcache for PHP version 5.4.
/opt/cpanel/ea-php54/root/usr/bin/pecl install memcache
3. Installer might ask whether to enable memcache session handler support. Enter ‘Yes’ and press enter key.
Enable memcache session handler support? [yes] : yes
Build process completed successfully
Installing ‘/opt/cpanel/ea-php54/root/usr/lib64/php/modules/memcache.so’
install ok: channel://pecl.php.net/memcache-2.2.7
php.ini “/opt/cpanel/ea-php54/root/etc/php.d/local.ini” does not exist
You should add “extension=memcache.so” to php.ini
4. Add “extension=memcache.so” in the PHP 5.4 configuration file
5. Check whether memcache is enabled for PHP 5.4
memcache
6. Create a phpinfo.php file under any website that is having PHP 5.4 version and check whether memcache is enabled.
Restart the web server if memcache is missing in phpinfo file.
B. Enable memcache for PHP 5.5 on Easyapache 4 server
Type the below pecl command to Install memcache for PHP 5.5
1. Command to install :
/opt/cpanel/ea-php55root/usr/bin/pecl install memcache
2. Add memcache.so extension in PHP 5.5 configuration file :
echo “extension=memcache.so” >> /opt/cpanel/ea-php55/root/etc/php.ini
3. Command to check whether memcache is Enabled :
/opt/cpanel/ea-php55/root/usr/bin/php -m | grep -i memcache
[root@server ~]# /opt/cpanel/ea-php55/root/usr/bin/php -m | grep -i memcache
memcache
C. Install memcache for PHP 5.6 on Easyapache 4 server
1. Install memcache in PHP 5.6 version :
/opt/cpanel/ea-php56/root/usr/bin/pecl install memcache
2. Append memcache.so in PHP 5.6 php.ini file :
3. Check whether memcache is enabled in PHP 5.6 :
/opt/cpanel/ea-php56/root/usr/bin/php -m | grep -i memcache
[root@server ~]# echo “extension=memcache.so” >> /opt/cpanel/ea-php56/root/etc/php.ini
[root@server ~]# /opt/cpanel/ea-php56/root/usr/bin/php -m | grep -i memcache
memcache
D. Install memcache for PHP 7 on Easyapache 4 server
Install memcache in PHP 7 :
Try the above command to install memcache in PHP 7. Follow the below steps if you face any errors.
Go to /usr/local/src directory :
Download the installation file from github repo :
unzip the downloaded file :
cd pecl-memcache-NON_BLOCKING_IO_php7
/opt/cpanel/ea-php70/root/usr/bin/phpize && ./configure –enable-memcache –with-php-config=/opt/cpanel/ea-php70/root/usr/bin/php-config && make
cp -a /usr/local/src/pecl-memcache-NON_BLOCKING_IO_php7/modules/memcache.so /opt/cpanel/ea-php70/root/usr/lib64/php/modules/
Add memcache.so to php.ini file, like shown below :
Now check whether memcache is enabled by running the below command :
Steps to uninstall / Remove Memcache
1. Log into your server via SSH
2. To Remove, run the command : /opt/cpanel/ea-php54/root/usr/bin/pecl uninstall memcache
Unable to remove “extension=memcache.so” from php.ini
uninstall ok: channel://pecl.php.net/memcache-2.2.7
3. Open the file “/opt/cpanel/ea-php54/root/etc/php.ini” in vi editor and remove the line “extension=memcache.so”.
4. Save the php.ini file and exit.
The above steps are for Installing / Removing memcache in PHP version 5.4. Do the below steps to uninstall for other PHP versions.
/opt/cpanel/ea-php56/root/usr/bin/pecl uninstall memcache
How to install PHP memcache on an EasyApache 3 EA3 server
The above steps are for installing PHP memcache on easyapache 4 EA4 server.
First type the below command to check whether it is an easyapache 3 or easyapache 4 server. Easyapache 3 servers will show the exact version and easyapache 4 servers will show “easyapache 4 is in effect”. Always check the easyapache version before installing PHP memcache.
Easy Apache v3.34.16
[cpanel]
66.0 (build 17)
[apache]
Server version: Apache/2.4.27 (Unix)
Server built: Sep 2 2017 13:28:48
Cpanel::Easy::Apache v3.34.16 rev9999
You will see the below output on an easyapache 4 server.
EasyApache3 is not available when EasyApache4 is in effect.
Do the below steps to install PHP memcache on easyapache 3 server.
1. Log into your Easyapache EA3 server as root user
2. Run the command “pecl install memcache” to install PHP memcache
[root@server ~]# pecl install memcache
3. Run the command “php -m | grep memcache” to check whether memcached module is enabled.
Build process completed successfully
Installing ‘/usr/local/lib/php/extensions/no-debug-non-zts-20131226/memcache.so’
install ok: channel://pecl.php.net/memcache-2.2.7
Extension memcache enabled in php.ini
memcache
Uninstall PHP memcache on Easyapache3 server
Run the command “pecl uninstall memcache” to uninstall memcache.
Extension memcache disabled in php.ini
uninstall ok: channel://pecl.php.net/memcache-2.2.7
Alternate way to install memcache
1. Log into your linux server via SSH as ‘root’ user
2. Download the latest version of PHP memcache from website “pecl.php.net”
URL to download : http://pecl.php.net/package/memcache
3. Go to /usr/local/src directory
4. Download PHP memcache tar.gz file using wget command
5. Extract the tar file
6. Run the below commands to install
phpize
./configure
make
make install
7. Add PHP memcache extension in the php.ini file by running the below command
8. Run the command “php -m | grep memcache” to make sure it is installed
memcache
How to Install PHP memcache through WHM
Try the below steps to install from WHM, if you are not familiar with installing packages from server backend.
1. Login to WHM using your ‘root’ login details
2. Search for “Module Installers” in WHM search bar
Home » Software » Module Installers
3. Click on “Module Installers” under “Software”
4. Under “Actions” click on “Manage” next to “PHP Pecl”
5. Search PHP “memcache” in the search field and click on “Go”
6. Click on “install” the memcache extension.
Click on “Show docs” under “Actions”, if you want to read the memcache docs.
Memcache Docs URL : http://pecl.php.net/package/memcache/docs
7. Create a phpinfo page to make sure memcache is enabled.
Steps to Install memcache through WHM on Easyapache 4 server
:
1. Login to WHM (Webhost manager)
2. Click on “Module Installers” under “Software”
3. Select the PHP version from the drop down and click on “Apply”, like shown in the below picture
4. Enter “memcache” in the search box and click on “Go”
5. Install memcache and do the same for other PHP versions in the dropdown. (Step 3)
Steps to Install Memcached on CentOS 6 and Redhat 6 (RHEL 6) servers
1. Login to Linux server as ‘root’ user
2. Install memcache daemon using yum
Command to Install Memcached : yum install memcached
3. Start the service after installation
/etc/init.d/memcached start
4. Enable Memcached service to start when the system boot up
Command : chkconfig memcached on
5. Open the file “/etc/sysconfig/memcached” using vi editor and increase the CACHESIZE value
PORT=”11211″
USER=”memcached”
MAXCONN=”1024″
CACHESIZE=”64″
OPTIONS=””
By default CACHESIZE will be 64, you must increase this value. You can also increase the maximum connections value and change the default port number 11211, if necessary.
6. Restart memcached service
Command to restart : service memcached restart
memcached is stopped
[root@server ~]# service memcached start
Starting memcached: [ OK ]
[root@server ~]# chkconfig memcached on
[root@server ~]# service memcached status
memcached (pid 16815) is running…
Install memcached on CentOS 7 / RHEL 7 (Redhat 7) servers
1. Log into server via SSH as ‘root’ user
2. Install Memcached using yum
Command to Install memcached on RHEL 7 and CentOS 7 server : yum install memcached
3. Increase the cache size in memcached after installation
Edit the file /etc/sysconfig/memcached using vi editor and increase CACHESIZE to 1Gb
Change CACHESIZE=”64″
To
CACHESIZE=”1024″
4. Save the file and exit
5. You must restart memcached service after increasing the Cache size
Command to restart memcached on CentOS 7 / RHEL 7 server : systemctl restart memcached
6. Enable Memcache daemon to start when server boot up
Command : systemctl enable memcached
7. Install PHP memcache extension using yum
command : yum install php-pecl-memcache
How to Install Memcached and PHP Memcached Extension on Ubuntu / Debian Server
1. Log into your Ubuntu/Debian Server
2. Run the below command to Install Memcached and PHP Memcached Extension on Ubuntu / Debian
Command : apt-get install memcached php5-memcached
3. Start the Memcached service
Command to start : service memcached start
4. You can change Port number, Cache Size etc in Memcached configuration file /etc/memcached.conf
5. Restart the web server
Command : service apache2 restart
6. Run the below command to check whether memcached service is running fine
netstat -tupln | grep memcached
OR
netstat -tupln | grep :11211
7. Create a phpinfo file to check whether memcache extension is enabled.