Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Install memcache in Linux

Memcached is a high-performance, distributed, in-memory caching system that can be used to speed up web applications by temporarily storing data in memory. It reduces the number of times an application needs to read data from external sources like databases or APIs. In this tutorial, we'll walk through installing Memcached on a Linux system.

1. Update your system

Before installing Memcached, make sure your system is up to date. Run the following commands to update the package index and upgrade installed packages:

For Debian-based systems (e.g., Ubuntu, Debian):

sudo apt-get update
sudo apt-get upgrade

For RHEL-based systems (e.g., CentOS, Fedora):

sudo yum update

2. Install Memcached

To install Memcached, run the following command:

For Debian-based systems:

sudo apt-get install memcached

For RHEL-based systems:

sudo yum install memcached

3. Install libmemcached

To interact with Memcached from your application, you'll need the libmemcached library. Install it using the following command:

For Debian-based systems:

sudo apt-get install libmemcached-tools

For RHEL-based systems:

sudo yum install libmemcached

4. Configure Memcached

To configure Memcached, edit the /etc/memcached.conf file. You can adjust parameters like memory usage, port, IP address, and more. For example, to change the memory allocated for Memcached, edit the -m parameter:

-m 64

In this example, we've allocated 64MB of memory for Memcached.

5. Start and enable Memcached

After installing and configuring Memcached, start the service and enable it to start automatically at boot:

For Debian-based systems:

sudo systemctl start memcached
sudo systemctl enable memcached

For RHEL-based systems:

sudo systemctl start memcached
sudo systemctl enable memcached

6. Verify Memcached installation

To verify that Memcached is running, use the systemctl command:

sudo systemctl status memcached

You can also use the memcstat command to check the server statistics:

memcstat --servers=localhost

7. Install Memcached PHP extension (optional)

If you're using Memcached with PHP, you'll need to install the PHP extension for Memcached. Install it using the following commands:

For Debian-based systems:

sudo apt-get install php-memcached

For RHEL-based systems:

sudo yum install php-pecl-memcached

Finally, restart your web server (e.g., Apache or Nginx) for the changes to take effect.

That's it! You've successfully installed Memcached on your Linux system. You can now use it to improve the performance of your web applications by caching data in memory.

  1. Update Package Lists:

    sudo apt update
    
  2. Install Memcached:

    sudo apt install memcached
    
  3. Start and Enable Memcached:

    sudo systemctl start memcached
    sudo systemctl enable memcached
    

Step-by-step Memcached installation on CentOS:

  1. Update YUM Package Lists:

    sudo yum update
    
  2. Install Memcached:

    sudo yum install memcached
    
  3. Start and Enable Memcached:

    sudo systemctl start memcached
    sudo systemctl enable memcached
    

Memcached installation and configuration in Debian:

  1. Update Package Lists:

    sudo apt update
    
  2. Install Memcached:

    sudo apt install memcached
    
  3. Start and Enable Memcached:

    sudo systemctl start memcached
    sudo systemctl enable memcached
    

Installing and configuring Memcached on Red Hat:

  1. Update YUM Package Lists:

    sudo yum update
    
  2. Install Memcached:

    sudo yum install memcached
    
  3. Start and Enable Memcached:

    sudo systemctl start memcached
    sudo systemctl enable memcached
    

Linux Memcached server installation steps:

  1. Update Package Lists:

    # For Ubuntu/Debian
    sudo apt update
    
    # For CentOS/Red Hat
    sudo yum update
    
  2. Install Memcached:

    # For Ubuntu/Debian
    sudo apt install memcached
    
    # For CentOS/Red Hat
    sudo yum install memcached
    
  3. Start and Enable Memcached:

    sudo systemctl start memcached
    sudo systemctl enable memcached
    

Setting up Memcached on a Linux server:

  1. Install Memcached:

    # For Ubuntu/Debian
    sudo apt install memcached
    
    # For CentOS/Red Hat
    sudo yum install memcached
    
  2. Start and Enable Memcached:

    sudo systemctl start memcached
    sudo systemctl enable memcached