Apachectl command does not work properly on mac - macos

I started learning Apache server with my macbook, and I typed apachectl on the Terminal.
Unfortunately I could only see the following message.
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Marshalls-MacBook-Air.local. Set the 'ServerName' directive globally to suppress this message
(13)Permission denied: AH00072: make_sock: could not bind to address [::]:80
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
What do you think is the matter, and how should I fix?

I typed apachectl
You need prefix apachectl with sudo, so:
sudo apachectl start
otherwise the command has no enough privileges to bind into port 80.
AH00558: httpd: Could not reliably determine the server's fully qualified domain name
You need to edit your httpd.conf Apache configuration file and uncomment ServerName line.
To locate the file, run: apachectl -t -D DUMP_INCLUDES first.

Related

Troubleshoot localhost / apache - connection refused error on MacOS

I am trying to debug localhost connection refused error. For context, I have a Flask App that I am trying to run locally. I launch the app using gunicorn and notice that it is running on port 8000.
Starting gunicorn 20.1.0
[2022-02-24 05:38:49 -0800] [21269] [INFO] Listening at: http://127.0.0.1:8000 (21269)
[2022-02-24 05:38:49 -0800] [21269] [INFO] Using worker: sync
[2022-02-24 05:38:49 -0800] [21271] [INFO] Booting worker with pid: 21271
I have tried several things including:
restart apache server - sudo apachectl restart
flush dns: sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache
Run httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MacBook-Air-2020.local. Set the 'ServerName' directive globally to suppress this message
(48)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
telnet 127.0.0.1
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
When I enter http://127.0.0.1/ in browser, I get
It works!
What else can I try? I am using gunicorn server to deploy / run the App locally.
This did the trick for me:
sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache

(OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. Windows apache

When trying to execute httpd.exe on my windows server, I get this error:
(OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : AH00072: make_sock: could not bind to address (myIpAddress):80
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs
This only happens when in the httpd.conf I set:
Listening (myIPAddress):80
but the I don't get this error when it's set to:
Listening 80
Confirm if some other process is already listening to Port 80.
netstat -aon | findstr :80
Since it is windows server there are chances to have IIS running by default.
You will have to stop the website binded with port 80 from IIS Manager and then run httpd.exe again.
(OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : AH00072: make_sock: could not bind to address [::]:443 (OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : AH00072: make_sock: could not bind to address 0.0.0.0: 443 AH00451: no listening sockets available, shutting down
I got this error.
I have installed VMWare software on my PC.
I start a CMD with administrative rights.
In that CMD I execute a powershell command
After powershell started in CMD I execute:
Get-Process vmwa* | kill
I got a message back
Confirm
Are you sure you want to perform the Stop-Process operation on the following
item: vmware-hostd(2164)?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
(default is "Y"):
Then I used A option and start xampp and Apache without problems.
p.s. I'm writing this if anyone has the same problem and have installed VMWare on their PC-s
Please check if port no : 80 is already occupy by Wampapache service or World Wide Web service.
netstat -aon | findstr :80
And stop the service which occupy port no 80 & then try to install the new Apache.
I only stopped Skype! this worked...no changes were required to do in Apache config file. Skype is somehow affecting the Apache on port 80
https://www.apachelounge.com/viewtopic.php?t=767
Thanks

XAMPP apache cannot connect to listening port

I am using xampp on windows 10 and trying to get apache to work. I have set it to listen to port 50563 in the httpd.conf and httpd-ssl.conf, however when I run httpd.exe I get this message:
(OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : AH00072: make_sock: could not bind to address [::]:50563
(OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : AH00072: make_sock: could not bind to address 0.0.0.0:50563
AH00451: no
listening sockets available, shutting down
AH00015: Unable to open
logs
I have tried running as administrator, I check netstat and that port is free. What should I do?
httpd.conf: https://pastebin.com/NUrWBfRB
httpd-ssl.conf https://pastebin.com/YLLfzEjP
Probably you are trying to listen on 50563 for both http and https? If this is the case you MUST use different ports, maybe use 50563 and 50564 for HTTP and HTTPS respectively.
In the case of multiple Listen directives, Apache will bind to port 80
the first time and then try to bind to port 80 a second time. This
yields a nice "Could not bind to port" error on start up. This
seems to happen with newbies and Debian based distros, where Debian
based distros have Listen 80 defined in ports.conf. Newbies don't
realize this and create another Listen 80 line in *.conf.
From: https://wiki.apache.org/httpd/CommonMisconfigurations

After upgrade to macOS Sierra Apache can't do start/stop/restart

After upgrade to macOS Sierra Apache can't do start/stop/restart.
Errors:
AH00557: httpd: apr_sockaddr_info_get() failed for MacBook-Pro-N.local
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
I tried reinstall apache24 using home-brew. But it didn't fix my problem.
Also I configured httpd.conf, uncommented ServerName localhost. But it didn't help anyway.
Please, help.
try adding
127.0.0.1 MacBook-Pro-N.local
to your /etc/hosts file
Another solution is to change ServerName to localhost.
So first you need to find the location of your httpd.conf Apache configuration file by:
apachectl -t -D DUMP_INCLUDES
then edit it and uncomment or change the line with ServerName (make sure it has the valid server name or it exists in your /etc/hosts file). E.g.
ServerName localhost

Killing an unknown self restarting server on port 80 Mac OSX

I have a server running on port 80, but I do not know what it is or where it came from. When I run
sudo lsof -i :80 | grep LISTEN
I get
httpd 80 root 5u IPv6 0x91f5a9de62859cfd 0t0 TCP *:http (LISTEN)
httpd 694 _www 5u IPv6 0x91f5a9de62859cfd 0t0 TCP *:http (LISTEN)
I have tried to enter get the process name using the PID, but all I ever get in return is "httpd" or "FOREGROUND".
When I kill the PID, the process simply restarts with a new PID. I assume I will have to stop it at launch.
How can I stop this server from running at startup?
If it helps any, I am trying to free up port 80 to use the apache server on MAMP.
This is just a guess, but it might be the built-in version of apache, being launched (& restarted) by launchd (OS X's daemon manager). It's disabled by default, but might've gotten enabled somehow. You can try disabling it with:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
If that doesn't do it (it'll say something like "Could not find specified service"), you can check to see if it's some other launch daemon item by looking for the PID of the master process (the one running as root, not _www):
sudo launchctl list | grep <masterPID>
That won't necessarily tell you exactly what's going on, but might point you in the right direction.
Like Gordon suggested, that's the built-in version of the Apache web server.
You can stop it with
sudo apachectl stop
btw, the configuration for this webserver can be found in the /etc/apache2/httpd.conf directory.
This happens to me a lot.
As #Gordon Davisson explains it is most likely the launchdeamon process conflicting with the service you have set up.
Definitely stop the apachetl server.
sudo apachetl -k stop
Try to find all the httpd process, they should be the last ones
sudo lsof -i :80 // without grep
Then get the first process (most likely in the 1000s) should also be the lowest one.
sudo kill <firstHttpdPID>
This should kill ALL the processes running that httpd instance and then you get simply start back up your server.
Must stop it first though or it will continue running again.
Mac OSX comes bundled with Apache, however it is deactivated. You might have activated it somehow. In my case, I have previously install XAMPP and configured something in the /etc/apache2/httpd.conf that leads my port localhost:80 to leads to html page with It Works!.
TLDR, the solution is to deactivate the Apache2 server.
Go to your terminal, and type this
sudo apachetl -k stop
In my case, it returns the following:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Shafies-MacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message
httpd (no pid file) not running
if you typed localhost on your browser, the port 80 is not active anymore and you will not see It Works! anymore.
For context, I have deleted XAMPP long time ago and not aware that my localhost:80 is still active. I am not able redirect dummy domain -- posts.com to my localhost port for my kubernetes YAML config files.
This is my ingress-srv.yaml file:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-srv
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
rules:
- host: posts.com
http:
paths:
- path: /?(.*)
backend:
serviceName: client-srv
servicePort: 3000
and I have tricked the operating system to redirect my posts.com to localhost:80 by adding below line in the hosts file located at /etc/hosts
127.0.0.1 posts.com
by SM

Resources