• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Install Memcached For WordPress On A VPS

Bhagwad Park

Published on: December 20, 2021

Categories: WordPress 0

If you’re running WordPress on a VPS – managed or unmanaged – your web hosting provider won’t include memcached as part of the installation. A managed VPS takes care of OS updates, setting up the control panel, e-mail, etc., but only goes so far. Unlike shared hosting, where your web host might have a checkmark in the PHP extensions interface where you can enable or disable various modules, with a VPS, you’ll have to install memcached for WordPress manually.

It’s not very hard to install memcached on a VPS, but you’ll have to take into consideration things like PHP versions for integration into WordPress.

Two Components to Memcached

For your PHP script in WordPress to be able to access the memcached system, two components must be installed:

  1. The memcached server component
  2. The memcached PHP component

The first is the memcached service that should be installed on your VPS. It creates and enables the daemon that runs in the background. The second is what allows your PHP scripts to access memcached and use its features. So let’s see how to install them one by one.

Step 1: Installing the memcached Service on a VPS

For the following commands, I’m assuming a CentOS distribution. The commands will be different for Ubuntu, which uses apt-get instead of yum. So make the changes as necessary! Note that all these commands will require at least sudo privileges. In general, I don’t recommend that you log in as root, so create a user with sudo privileges, and dive in!

First, we update the existing repositories:

yum update

Then we install memcached and the libmemcached library:

yum install memcached libmemcached

Once this is done, you’ve installed the first component of memcached on your VPS!

Step 2: Secure memcached by Restricting Access to the Local Machine

You don’t want anyone outside your VPS to access memcached and potentially cause a DDoS attack. So we change the configuration file to only allow requests from the local machine to access it. The configuration file is located at:

/etc/sysconfig/memcached

Open it and paste the following code in the OPTIONS line like this:

OPTIONS=”-l 127.0.0.1 -U 0″

This also blocks the UDP protocol that has been used previously for DDoS attacks.

Start and enable the memcached daemon like this:

systemctl restart memcached
systemctl enable memcached

And you’re done!

Step 3: Install the PHP Component of Memcached

It can get tricky here. I happen to have multiple versions of PHP on my machine, and it was hard for me to figure out how to install the right version of memcached.

To do this, search for the right module for your PHP version. In my case, my site runs on PHP 7.4. So I first do this:

yum search memcached | grep php74

This brings up the following package in the list:

Get the Right Package for Memcached
Get the Right Package for Memcached

As you can see, the correct name for the memcached package I want is:

php74-php-pecl-memcached

So now I install this using the command:

yum install php74-php-pecl-memcached

Let the installation proceed. When it’s done, restart apache and PHP. The process of restarting PHP will be different depending on what kind of PHP set up you have. My installation uses PHP-FPM, so I restart it like this:

systemctl reload php-fpm

Your way might be different. So make sure you read the documentation to see how to do it!

Using memcached on WordPress

To fully utilize memcached, you should have applications that call it. One great example is the caching plugin W3 Total Cache, which you can configure to use memcached. If you have the LiteSpeed web server, then you shouldn’t use a 3rd party caching plugin. But if your server is Apache, then caching is a must! Memcached will speed up the process of caching, so make sure you use it as much as possible!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

How To Back Up Your WordPress Site (And Why You Should Do It Today)

In this post, we’ll take a closer look at why backups matter. We’ll also show you different ways to back up your WordPress website.

How to Eliminate Render-Blocking Resources in WordPress (& Why You Should)

Many things can slow down your site, including render-blocking resources. These are CSS and JavaScript files that delay the loading of content on your site. As a result, visitors will have to wait longer to interact with your page, which could lead to frustration and instant exits.  So, what can you do to eliminate render-blocking […]

What Is Self-Hosted WordPress?

In this post, we’ll differentiate self-hosted WordPress from WordPress.com, and discuss the benefits of the former.

Joomla vs. WordPress: Which One Is Better?

In this post, we’ll consider five differences between Joomla and WordPress and how you might go forward with setting up a WordPress website.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA