2

I need to increase max number of allowed opened files for Nginx 1.10 and PHP-FPM 7 on Ubuntu 16.04. According to some tutorials i changed the max number of opened files per user in /etc/security/limits.conf

*    soft nofile 64000
*    hard nofile 68000

I also changed the max number of opened files for entire system in /etc/sysctl.conf

fs.file-max = 200500

After reloading my virtual machine i checked soft and hard limits for the user i login to the system with

igor@ubuntu:~$ ulimit -Sn
64000
igor@ubuntu:~$ ulimit -Hn
68000

As you see, the limits applied to users. My problem is that i can't change the limits for Nginx and PHP

igor@ubuntu:~$ sudo ps aux|grep nginx
root      1124  0.0  0.0  45988   980 ?        Ss   01:04   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data  1125  0.0  0.2  46164  2372 ?        S    01:04   0:00 nginx: worker process
igor      2754  0.0  0.0   5108   848 pts/6    S+   01:14   0:00 grep --color=auto nginx
igor@ubuntu:~$ cat /proc/1124/limits
Limit                     Soft Limit           Hard Limit           Units     

.....
Max open files            1024                 4096                 files     
.....  

And the same thing for php

igor@ubuntu:~$ sudo ps aux|grep php
root      1097  0.0  2.1 118388 22496 ?        Ss   01:04   0:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data  1140  0.0  0.5 118388  5532 ?        S    01:04   0:00 php-fpm: pool www
www-data  1141  0.0  0.5 118388  5532 ?        S    01:04   0:00 php-fpm: pool www
igor      2795  0.0  0.0   5108   852 pts/6    S+   01:20   0:00 grep --color=auto php
igor@ubuntu:~$ cat /proc/1097/limits
Limit                     Soft Limit           Hard Limit           Units     
.....
Max open files            1024                 4096                 files     
.....

How can i change the limits for PHP and NGINX?

1 Answer 1

2

You need to add that configuration to the systemd unit file. Best would be to make this via a drop-in file.

mkdir /etc/systemd/system/nginx.service.d
echo "[Service]
LimitNOFILE=10000" > /etc/systemd/system/nginx.service.d/local.conf
systemctl daemon-reload
systemctl restart nginx

Then repeat that for the php7.0-fpm.service unit file.

You also can set defaults in /etc/systemd/system.conf, but it is recommended to use the drop-in files.

1
  • What's the equivalent way for Ubuntu 14.04 (systemctl is not supported) Feb 4, 2019 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .