memcached
Install Memcached, enable it at boot, and restrict it to localhost with UDP turned off
- Command:
/go/memcached - Category: Software
- Required option: None
- Output: Plain text from the package manager
- Last updated: 2026-11-20
On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also
Overview
/go/memcached installs Memcached, an in-memory cache that websites use to keep frequently needed data in RAM (for example sessions and database query results). The command:
- installs the
memcachedpackage withdnforapt - changes the service options so Memcached accepts connections only from this server (
127.0.0.1) and does not use UDP - enables the service at boot and starts it
Memcached has no login of its own, so it must never be reachable from the internet. Open UDP ports on public Memcached servers have been abused for large denial-of-service attacks. Restricting it to localhost and turning UDP off prevents this.
The command does not open any firewall port. It doesn't need to, because only programs on this server connect.
Quick start
/go/memcached
Then confirm that it listens only on localhost (see Examples).
Syntax
/go/memcached
| Form | Behavior |
|---|---|
/go/memcached |
Installs and secures Memcached, then enables and starts the service. |
Options
This command has no options. Arguments are only written to the log file.
Output
| Operating system | Message |
|---|---|
| AlmaLinux, Rocky, CentOS, Red Hat, Fedora | Installing MEMCACHED, followed by the dnf output |
| Debian, Ubuntu | Installing Memcached, followed by the apt output |
| Any other | Nothing. The command does nothing and prints no message. |
There is no success message. Every run is recorded in /var/log/go/memcached.log.
Examples
# Install and secure Memcached
/go/memcached
# Check that the service is running
systemctl status memcached
# Check what it listens on. Expect 127.0.0.1:11211 on TCP, and no UDP line.
ss -tulpn | grep 11211
# Apply the options if the check above shows the wrong addresses
sudo systemctl restart memcached
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The command prints nothing | The operating system name in /usr/local/goadmio/linux/os.db isn't one the script knows. |
The script supports AlmaLinux, Rocky, CentOS, Red Hat, Fedora, Debian, and Ubuntu. |
| Memcached listens on other addresses, or on UDP | The options line wasn't changed (see How the options are applied), or the service was already running with the old options. | Fix the options in the file your service reads, then run sudo systemctl restart memcached. |
sed: can't read ...: No such file or directory |
This version of the operating system keeps the Memcached options in another file. | Find the file with systemctl cat memcached, and set -l 127.0.0.1 -U 0 there. |
| Websites can't use Memcached | Their PHP version doesn't have the Memcached extension, or the site connects to the wrong address. | Install the extension with extension, and connect to 127.0.0.1 on port 11211. |
| Another server can't connect | This is intended. Memcached accepts local connections only. | Don't expose Memcached to the internet. Use a private network or an SSH tunnel instead. |
| Memcached doesn't start after a reboot | The service wasn't enabled, or it failed to start. | Run systemctl status memcached and systemctl enable --now memcached. |
Package errors from dnf or apt |
A repository or network problem. | Fix the package manager, then run the command again. |
Details
What it does
| Step | RHEL family | Debian and Ubuntu |
|---|---|---|
| 1. Install | dnf -y install memcached |
apt -y install memcached |
| 2. Set options | Edits /etc/sysconfig/memcached |
Edits /etc/default/memcached |
| 3. Enable | systemctl enable memcached |
systemctl enable memcached |
| 4. Start | systemctl start memcached |
systemctl start memcached |
How the options are applied
The command replaces a line that reads exactly OPTIONS="" with OPTIONS="-l 127.0.0.1 -U 0".
| Option | Effect |
|---|---|
-l 127.0.0.1 |
Listen only on the local loopback address. |
-U 0 |
Turn off the UDP port. |
The replacement has these limits:
- If the options line has any other content, it is left unchanged.
- If the file doesn't exist,
sedreports an error and nothing is changed. - On Debian and Ubuntu, the service may already be running by the time the file is edited, because installing the package can start it.
startdoes not restart a running service, so the new options apply only aftersudo systemctl restart memcached.
Always check the result with ss -tulpn | grep 11211.
Running it again
Running the command again is safe. The package is already installed, the options line no longer reads OPTIONS="" so it is left alone, and enabling and starting a running service changes nothing. An options line you edited yourself is never overwritten.
Memory
Memcached keeps its data in RAM, using the cache size from its configuration (usually 64 MB by default). Data in it is lost when the service restarts, so only store data that your application can rebuild.
See also
| Command | Description |
|---|---|
extension |
List, install, or remove a PHP extension across every installed PHP version |
mem |
Check the top ten memory-consuming commands or services |
memoryavg |
Check the weekly server memory average |
firewall |
Install and configure the server firewall (firewalld or UFW) with GoAdmio's default open ports, and start, stop, or reset it |
status |
Collect the status of every systemd service |
fpm |
Restart all installed PHP-FPM versions on your server |