Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Fix the "Too Many Open Files" Error

This guide explains this Linux error and shows how to raise the limit. It needs root access, so it fits a VPS or dedicated server.

How-To Guides2 min read11 steps

What does it mean?

On Linux, almost everything is a file: real files, network connections and logs. Each running program may only keep a certain number of them open at once. This is the open files limit. If a busy program such as a web server or database hits the limit, it shows "Too many open files". It is like a juggler who can only hold so many balls.

Warning: back up any config file before you change it.

Steps

  1. Log in to your server with SSH.
  2. Check the current limit for your user:
ulimit -n

A common default is 1024. That is low for a busy site.

  1. See how many files a program has open. Replace PID with its process number:
ls /proc/PID/fd | wc -l

This counts the open files for that program.

  1. Raise the limit for a session, to test:
ulimit -n 65535

This lasts only until you log out.

  1. Make it permanent. Back up and open the limits file:
cp /etc/security/limits.conf /etc/security/limits.conf.bak
nano /etc/security/limits.conf
  1. Add these lines at the bottom:
* soft nofile 65535
* hard nofile 65535

Soft is the working limit. Hard is the highest value a user can set. The star means all users.

  1. Save the file and log out, then log in again.
  2. Check with ulimit -n.

For services started by systemd

Services like Nginx or MySQL ignore limits.conf. Set the limit in the service instead:

  1. Run systemctl edit nginx (use your service name).
  2. Add:
[Service]
LimitNOFILE=65535
  1. Save, then restart the service:
systemctl daemon-reload
systemctl restart nginx

Check the system-wide limit

cat /proc/sys/fs/file-max

This number is the most files the whole server can open.

Tip: If the number of open files keeps climbing, a program may have a bug that never closes files. Raising the limit only delays the problem.

Quick recap

  • Each program can hold a limited number of open files.
  • Check with ulimit -n.
  • Raise it in limits.conf, or in the systemd service.
  • Restart the program and test.