Bitnami Memcached Installer

NOTE: Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under "Start -> Bitnami APPNAME Stack -> Application console" (Windows). Learn more.
NOTE: When running the commands shown on this page, replace the installdir placeholder with the full installation directory for your Bitnami stack.

Description

Memcached is an high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

First steps with the Bitnami Memcached Stack

Welcome to your new Bitnami application! Here are a few questions (and answers!) you might need when first starting with your application.

What are the system requirements?

Before you download and install your application, check that your system meets these requirements.

How do I install the Bitnami Memcached Stack?

Windows, OS X and Linux installer
  • Download the executable file for the Bitnami Memcached Stack from the Bitnami website.

  • Run the downloaded file:

    • On Linux, give the installer executable permissions and run the installation file in the console.
    • On other platforms, double-click the installer and follow the instructions shown.

Check the FAQ instructions on how to download and install a Bitnami Stack for more details.

The application will be installed to the following default directories:

Operating System Directory
Windows C:\Bitnami\APPNAME-VERSION
Mac OS X /Applications/APPNAME-VERSION
Linux /opt/APPNAME-VERSION (running as root user)
OS X VM
  • Download the OS X VM file for the Bitnami Memcached Stack from the Bitnami website.
  • Begin the installation process by double-clicking the image file and dragging the WordPress OS X VM icon to the Applications folder.
  • Launch the VM by double-clicking the icon in the Applications folder.

What credentials do I need?

You need application credentials, consisting of a username and password. These credentials allow you to log in to your new Bitnami application.

What is the administrator username set for me to log in to the application for the first time?

  • For Windows, Linux and OS X installers, the username was configured by you when you first installed the application.
  • For OS X VMs, the username can be obtained by clicking the Bitnami badge at the bottom right corner of the application welcome page.

What is the administrator password?

  • For Windows, Linux and OS X installers, the password was configured by you when you first installed the application.
  • For OS X VMs, the password can be obtained by clicking the Bitnami badge at the bottom right corner of the application welcome page.

How to start or stop the services?

Linux

Bitnami native installers include a graphical tool to manage services. This tool is named manager-linux-x64.run on Linux and is located in the installation directory. To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the "Server Events" tab.

Management tool

The native installer also includes a command-line script to start, stop and restart applications, named ctlscript.sh. This script can be found in the installation directory and accepts the options start, stop, restart, and status. To use it, log in to the server console and execute it following the examples below:

  • Call it without any service names to start all services:

      $ sudo installdir/ctlscript.sh start
    
  • Use it to restart a specific service only by passing the service name as argument - for example, mysql, postgresql or apache:

      $ sudo installdir/ctlscript.sh restart mysql
      $ sudo installdir/ctlscript.sh restart postgresql
      $ sudo installdir/ctlscript.sh restart apache
    
  • Obtain current status of all services:

      $ installdir/ctlscript.sh status
    

The list of available services varies depending on the required components for each application.

Mac OS X

Bitnami native installers include a graphical tool to manage services. This tool is named manager-osx on Mac OS X and is located in the installation directory. To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the "Server Events" tab.

Management tool

The native installer also includes a command-line script to start, stop and restart applications, named ctlscript.sh. This script can be found in the installation directory and accepts the options start, stop, restart, and status. To use it, log in to the server console and execute it following the examples below:

  • Call it without any service names to start all services:

    $ sudo installdir/ctlscript.sh start
    
  • Use it to restart a specific service only by passing the service name as argument - for example, mysql or apache:

     $ sudo installdir/ctlscript.sh restart mysql
     $ sudo installdir/ctlscript.sh restart apache
    
  • Obtain current status of all services:

     $ installdir/ctlscript.sh status
    

The list of available services varies depending on the required components for each application.

NOTE: If you are using the stack manager for Mac OS X-VM, please check the following blog post to learn how to manage services from its graphical tool.

Windows

Bitnami native installers include a graphical tool to manage services. This tool is named manager-windows.exe on Windows and is located in the installation directory. To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the "Server Events" tab.

Management tool

The Windows native installer creates shortcuts to start and stop services created in the Start Menu, under "Programs -> Bitnami APPNAME Stack -> Bitnami Service". Servers can also be managed from the Windows "Services" control panel. Services are named using the format APPNAMESERVICENAME, where APPNAME is a placeholder for the application name and SERVICENAME is a placeholder for the service name. For example, the native installer for the Bitnami WordPress Stack installs services named wordpressApache and wordpressMySQL.

These services will be automatically started during boot. To modify this behaviour, refer to the section on disabling services on Windows.

How to connect to Memcached from a different machine?

IMPORTANT: Bitnami Native Installers do not modify the firewall configuration of your computer, therefore the Memcached ports could be open which is a significant security risk. You are strongly advised to close the Memcached ports (refer to the FAQ for more information on this).

How can I run a command in the Bitnami Memcached Stack?

Load the Bitnami Console and then run the command as usual.

How to start memcached using another port?

The default port for accessing memcached is 11211 and is automatically configured as an allowed port for remote connections. You can change it using these commands:

$ cd installdir/memcached/scripts/
$ sudo sed -i 's/11211/11212/g' ctl.sh

In this example, 11211 is your original Memcached port and 11212 (example) is the new port to use. Once done, restart the memcached server for the change to take effect.

$ sudo installdir/ctlscript.sh restart

How to add another user or modify a user password?

By default, a user is automatically created during the installation process. To obtain the username and password, refer to the server dashboard. Check our FAQ for more information.

To add another user, execute the following command:

$ sudo installdir/common/sbin/saslpasswd2 -a memcached -c USERNAME

Enter a password (twice) for the new user and the new user account will be created.

How to list created users with SASL?

To list users created with SASL, execute the following command:

$ sudo installdir/common/sbin/sasldblistusers2

This will display a list of created users. It will only list users if there is a sasldb2 file.

NOTE: The password will appear as userPassword, but this is only a placeholder string and not the current password for the user.

How to start memcached without SASL authentication?

By default, memcached is configured to run with SASL authentication. This is highly recommended to secure your memcached installation.

To disable this authentication:

$ cd installdir/memcached/scripts/
$ sudo sed -i 's/memcached -d -S/memcached -d/g' ctl.sh

Once done, restart the memcached server for the change to take effect.

$ sudo installdir/ctlscript.sh restart

NOTE: If you see the following error it might be because you are using a Memcached client that does not support SASL authentication. You can either disable authentication as explained in this section or use a different Memcached client like the one used in the how to test Memcached with a client section

PHP Notice:  memcache_get(): Server 127.0.0.1 (tcp 11211, udp 0) failed with: Read failed (socket was unexpectedly closed) (0) in /home/bitnami/example.php on line 10
array(0) {
}

How to enable SASL authentication on memcached?

By default, memcached is configured to run with SASL authentication. This is highly recommended to secure your memcached installation.

If you have previously disabled this authentication and now want to re-enable it:

$ cd installdir/memcached/scripts/
$ sudo sed -i 's/memcached -d/memcached -d -S/g' ctl.sh

Then, create a user:

$ sudo installdir/common/sbin/saslpasswd2 -a memcached -c USERNAME
$ sudo chown memcached:memcached installdir/common/etc/sasldb2

Restart the memcached server for the change to take effect.

$ sudo installdir/ctlscript.sh restart

How to test Memcached with a client?

You can test your Memcached installation with a client like php-memcached-sasl, a simple Memcached client written in PHP.

NOTE: The Bitnami Memcached Stack does not include PHP. To use the example script below, you must have PHP installed on your machine. You can install PHP in your machine (refer to PHP Official Documentation for more information regarding how to install it), or you can launch a new server with PHP using the Bitnami LAMP Stack.

Download the php-memcached-sasl client from this link and begin by extracting the contents of the downloaded archive. The archive includes a simple script named example.php.

$ curl -o php-memcache-sasl-master.zip 'https://codeload.github.com/hull-graveyard/php-memcache-sasl/zip/master'
$ unzip php-memcache-sasl-master.zip
$ cd php-memcache-sasl-master
$ nano example.php

The script begins by including the necessary PHP class and instantiating an object of the class:

include('MemcacheSASL.php');
$m = new MemcacheSASL;

Configure the client object by defining the Memcached server host and port, and SASL configuration. Replace these values with actual values for your server:

$m->addServer('host', 'port');
$m->setSaslAuthData('user', 'password');

SASL credentials: You must use the same credentials you have entered when you first installed the application.

NOTE: If your Memcached server doesn't use SASL authentication, simply omit the call to setSaslAuthData().

You can now use the object's add() and get() methods to add or remove values from the cache. In this example, the add() method stores the value '12345' using the key 'test'. The key can then be used with the get() method to retrieve the original value whenever needed.

var_dump($m->add('test', '12345'));
$var = $m->get('test');

Here's the complete code for the modified example.php script:

<?php
include('MemcacheSASL.php');
$m = new MemcacheSASL;
$m->addServer('host', 'port'); // replace these values
$m->setSaslAuthData('user', 'password');  // replace these values
var_dump($m->add('test', '12345'));
$var = $m->get('test');
print "$var";
?>

Save the file and run it:

$ php example.php

The script will connect to your Memcached server, save the value to the key 'test', then retrieve and display it.

How to create a full backup of Memcached?

The Bitnami Memcached Stack is self-contained and the simplest option for performing a backup is to copy or compress the Bitnami stack installation directory. To do so in a safe manner, you will need to stop all servers, so this method may not be appropriate if you have people accessing the application continuously.

NOTE: If you want to create only a database backup, refer to these instructions for MySQL and PostgreSQL.

Backup on Linux and Mac OS X

Follow these steps:

  • Change to the directory in which you wish to save your backup.

     $ cd /your/directory
    
  • Stop all servers.

     $ sudo installdir/ctlscript.sh stop
    
  • Create a compressed file with the stack contents.

     $ sudo tar -pczvf application-backup.tar.gz installdir
    
  • Start all servers.

     $ sudo installdir/ctlscript.sh start
    
  • Download or transfer the application-backup.tar.gz file to a safe location.

You should now download or transfer the application-backup.tar.gz file to a safe location.

Backup on Windows

Follow these steps:

  • Stop all servers using the shortcuts in the Start Menu or the graphical manager tool.

  • Create a compressed file with the stack contents. You can use a graphical tool like 7-Zip or WinZip or just right-click the folder, click "Send to", and select the "Compressed (zipped) folder" option.

  • Download or transfer the compressed file to a safe location.

  • Start all servers using the shortcuts in the Start Menu or the graphical manager tool.

Restore on Linux and Mac OS X

Follow these steps:

  • Change to the directory containing your backup:

    $ cd /your/directory
    
  • Stop all servers.

    $ sudo installdir/ctlscript.sh stop
    
  • Move the current stack to a different location:

    $ sudo mv installdir /tmp/bitnami-backup
    
  • Uncompress the backup file to the original directory:

    $ sudo tar -pxzvf application-backup.tar.gz -C /
    
  • Start all servers.

    $ sudo installdir/ctlscript.sh start
    
IMPORTANT: When restoring, remember to maintain the original permissions for the files and folders. For example, if you originally installed the stack as the root user on Linux, make sure that the restored files are owned by root as well.

Restore on Windows

  • Change to the directory containing your backup:

       $ cd /your/directory
    
  • Stop all servers using the shortcuts in the Start Menu or the graphical manager tool.

  • Uninstall the previous services by executing the following command:

        $ serviceinstall.bat
    
  • Create a safe folder named Backups in the desktop and move the current stack to it. Remember to replace PATH with the right location of your folder:

        $ move installdir \PATH\Backups
    
  • Uncompress the backup file using a tool like 7-Zip or Winzip or just double-click the .zip file to uncompress it, and move it to the original directory.
  • Install services by running the following commands from an elevated command prompt:

      $ cd installdir
      $ serviceinstall.bat INSTALL
    
  • Start all servers using the shortcuts in the Start Menu or the graphical manager tool.
nativeInstaller

Bitnami Documentation