30

I can stop it using

/etc/init.d/apache2 stop

But when I want to start it again using:

/etc/init.d/apache2 start

I get this error:

Starting web server apache2                                                  /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
(13)Permission denied: make_sock: could not bind to address [::]:80
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
                                                                         [fail]
Artisan
  • 599
  • 2
  • 6
  • 13

4 Answers4

66

Some words about the errors you get which hopefully will save you from similar situations in future.

In Linux ports from 0 to 1024 are reserved for system use. This means that in order to use one, you must have the authority to change - access basic system settings. The root user has such privileges and can actually use a port from the range 0 - 1024.

In your problem as you can see, the system through Apache2 response indicates the root of the problem ([...]could not bind to address blah blah 80):

(13)Permission denied: make_sock: could not bind to address [::]:80
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80

When the Apache2 http daemon starts, it tries to bind the 80 port as it is the default port for use in HTTP see, which is a port within the system assigned ports and as such it can only be accessed by root.

You executed the start command as a typical user without root privileges and led to failure to do so.

In simple words:

You:

Hi Apache2. I am Kongthap and I am telling you to start (/etc/init.d/apache2 start)

Apache2:

OK. I am starting (Starting web server apache2)

System, please give me port 80 to use and listen for connections.

System:

OK. One moment to check...

Ahh... Sorry Apache2 but I cannot let you run at 80 port, it is for personal use.

And you do not have the correct privileges to bind it. (Operation not permitted)

Apache2:

Ohh, Kongthap I failed to start, the System did not let me do it ((13)Permission denied:[...])

Conclusion

There are mainly two solutions to this problem:

  1. Run the Apache2 HTTP daemon with root privileges using sudo:

    sudo service apache2 start
    

    or:

    sudo /etc/init.d/apache2 start
    
  2. Change the default port from 80 to something greater than 1024, say 2000, 2500, 9000, etc. A typical port to run when in such situation is 8080

    sudo vi /etc/apache2/ports.conf
    

    look for or if not there add:

    Listen 8080
    

    or any other port of your choice such as port > 1024 and the selected port is not used by another process.

Stef K
  • 4,836
  • 5
    Really excellent explanation!!! – Artisan Aug 28 '13 at 09:52
  • Great explanation, understood well! – Timothy Sep 06 '14 at 12:05
  • Great explanation. Why is using service the preferred method? – Holloway Oct 15 '14 at 20:34
  • They are Upstart directives, check this question and answers http://askubuntu.com/q/19320/12218 and for more detailed view check the upstart cookbook http://upstart.ubuntu.com/cookbook/. Keep in mind these refer to the services (daemon) handling (when and how to start-stop) this question and my answer also tackles the permission problems. – Stef K Oct 15 '14 at 23:49
  • 1
    Needless wordiness. Answer does not address the problem. – reggie Oct 27 '15 at 16:00
  • @reggie that may be your opinion but the answer does solve the op's problem, in addition explains in extremely simple terms how one can avoid such situations. So if your problem is not solved by the answer, either your problem is not the same as the op's or you did not understand the explanation - solution provided here. – Stef K Oct 31 '15 at 22:28
  • 1
    sudo service apache2 start does NOT run the service as root, it starts the service as root. By default systemd services run as root anyway - all sudo does is let you start/stop them. If your apache service is configured to run as apache it matters not that you start it with root. – Marc Mar 29 '22 at 12:58
7

Following are the commands to start/stop/restart apache server:

  • To start:

    sudo /etc/init.d/apache2 start
    
  • To stop:

    sudo /etc/init.d/apache2 stop
    
  • To restart:

    sudo /etc/init.d/apache2 restart
    
Saurav Kumar
  • 14,916
  • After restart the computer, it seems ok with all commands you suggested but I got this message during restarting... Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName – Artisan Aug 28 '13 at 06:50
  • 1
    @Kongthap: that's not an error. I'm sure the web is full of explanation for that message. – Andrea Corbellini Aug 28 '13 at 07:09
  • Yes, @AndreaCorbellini is correct. It is not an error, it says because your ip does not have any Fully Qualified Domain Name for example mail.google.com. – Saurav Kumar Aug 28 '13 at 11:22
5

Check the selinux port context by issuing command

semanage port -l | grep http

If it's present in the http_port_t list then it's OK, otherwise add your port by

semanage port -a -t http_port_t -p tcp 80

or something that you want to assign.

wjandrea
  • 14,236
  • 4
  • 48
  • 98
zahid iqbal
  • 51
  • 1
  • 1
  • This was helpful, will add that issuing semanage port -a -t http_port_t -p tcp 8081 may fail if the port is already defined. What then helped me get past that was issuing a subsequent command semanage port -m -t http_port_t -p tcp 8081 – TryTryAgain Jan 14 '20 at 21:20
1

This is an selinux error, or at least it was in my case. Either change the boolean, disable selinux, or set it for permissive with setenforce 0.

The boolean change would require you to run getenforce -a | grep http, and look for the "allow http connect network". Copy it and replace "on" where the list says "-- off"

wjandrea
  • 14,236
  • 4
  • 48
  • 98
tru
  • 11
  • 1
  • Ubuntu use AppArmor not SELinux, so your answer is irrelevant to ubuntu. – sgx1 Jan 17 '14 at 03:25
  • As a centos user who got this problem and this is the first stackoverflow question to come up I appreciate the help this fixed my issue – Cacoon Apr 16 '18 at 05:20