The server is running fine -- or at least it seems to -- but there's always the following error:

apache2/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)

It happens with Apache 2.2.22-9 on Debian Wheezy.

# apache2ctl configtest

/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
Syntax OK

# service apache2 reload

[....] Reloading web server config: apache2/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
. ok

# service apache2 restart

[....] Restarting web server: apache2/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
... waiting /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
. ok

# service apache2 status

Apache2 is running (pid 32045).

  • 1
    Have a look at what you have in /etc/security/limits.conf and /etc/security/limits.d. It seems that you have APACHE_ULIMIT_MAX_FILES (see it in /usr/sbin/apache2ctl) variable set to something larger than the limit in that files.
    – HUB
    Commented Aug 6, 2012 at 9:44

3 Answers 3


This might help:- http://ubuntuforums.org/showthread.php?p=11950245#post11950245

sudo service apache2 restart # no errors
service apache2 restart      # errors
  • 1
    Thanks, I already saw that but it doesn't help. Using sudo or not doesn't change anything, I have the same error. Commented Aug 26, 2012 at 15:00
  • 1
    Worked for me! Totally forgot sudo. Commented Nov 15, 2012 at 16:19
  • 2
    +1 magic sudo always does the trick
    – bicycle
    Commented Sep 11, 2013 at 0:06
  • 1
    even worst, I have docker setup where this is appering, works on my home computer, but not on the server .. in the container with no difference between them... makes no sense to me
    – superhero
    Commented Aug 24, 2015 at 17:47
  • Same here superhero. Also, restart doesn't work with or without sudo for me. I have to use stop then start without sudo to make it work.
    – Shardj
    Commented Feb 26, 2020 at 15:03

The problem stems from /usr/sbin/apache2ctl (on Debian). Check it out:

~$ grep ULIMIT /usr/sbin/apache2ctl
if [ "x$ULIMIT_MAX_FILES" != "x" ] ; then

Here it is setting the number of open files allowed to 8192. Or trying to and failing, in your case.

So to avoid getting an error when apache2ctl does that, adjust your system's settings in the /etc/security/limits.conf file by adding these two lines:

*               soft    nofile          8192
*               hard    nofile          8192

I didn't increase it to more than necessary (8192) because I don't know what else it will impact. However this gets rid of the warning.

Not sure if you will need to reboot your system after that, because there is a dynamic element to the ulimits which I am not familiar with. However you can test easily enough to find out what your current ulimit num of files is:

ulimit -n

You might want to read where I found it: stackoverflow - setting ulimit

  • How would I do the reverse and reduce the Apache limit?
    – eri0o
    Commented Nov 2, 2015 at 13:05
  • Seeing that the script I posted in the answer is direct out of the apache2ctl script which is installed by apache, then you will have to go to that script file and change it, assuming you have the access right and assuming you're willing to repeat the action with every Apache upgrade.
    – Adam
    Commented Nov 2, 2015 at 15:23
  • The actual answer on the question. +1 Commented Apr 9, 2020 at 13:39

1.Check and modify the value of ulimit in your host machine. Add the values in the file /etc/profile then make it take effect.

ulimit -u 10240
ulimit -n 8192     #This configuration is what we most needed
ulimit -d unlimited
ulimit -m unlimited
ulimit -s unlimited
ulimit -t unlimited
ulimit -v unlimited

source /etc/profile

or you can:

sudo sh -c 'printf "\nulimit -HSn 999999\n" >> /etc/sysconfig/docker'

2.Restart docker service and make the configuration to be effective.

sudo service docker restart

3.Test the ulimit in the container.

ulimit -n

This is my test result!

Tips:Maybe you can also try the command as below(prerequisite: ulimit in the host machine should be larger than 8192 ),but I am failed.

docker run --privileged -it -p xxxx:80 --ulimit data=8192 linode/lamp /bin/bash
  • 1
    $ ulimit -n 8192 gives me -bash: ulimit: open files: cannot modify limit: Operation not permitted
    – Shardj
    Commented Feb 26, 2020 at 15:25

You must log in to answer this question.

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