Clean reinstall and fix of httpd service error on macos - macos

I'm still having some problems on using httpd (aka Apache2) after the update of my MacOs on BigSur.
I tried to make a clean reinstall of apache2 using the brew httpd services (like said in a lot of tutorials) but it still not working. I make a summary of the steps taked and I'll add some debug command.
To reinstall I done:
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd
After that I reboot and launched the command:
brew services start httpd
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)
But if I run the following command:
brew services list
Name Status User Plist
dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
fuseki stopped
httpd error matteo.ceradini /Users/matteo.ceradini/Library/LaunchAgents/homebrew.mxcl.httpd.plist
mongodb-community started matteo.ceradini /Users/matteo.ceradini/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
unbound stopped
As you can see the httpd is in an error status (in fact going to localhost:8080 I get an error) and I can't understand why.
Any suggestion how to fix this?
Thank you.

Something seems to not working, but still I can't find why.
I stopped all the services (either sudo brew and brew without sudo), and next running the commands:
sudo lsof -i :80
sudo lsof -i :8080
sudo lsof -i tcp:80
sudo lsof -i tcp:8080
the results is always nothing. But if I run:
sudo brew services start httpd
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)
The httpd will not start (even if in the terminal command it says yes):
sudo brew services list
httpd error root /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
And if I check the apachetl error I get always that the port 80 is occupied, even if there isn't processes on that port:
apachectl -e error
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
I urgently need to find a solution for this bug. It seems that in some httpd is corrupted, even if I uninstall and reinstall again
UPDATE:
I really don't know how I did it, but now it's working. I stopped all the brew httpd services and I restard apache using the command:
sudo apachectl -k start
and that worked for me

I just had exactly the same issue on Monterey. As digging in, it seems that the problem was a symbol not found ( _apr_bucket_alloc_aligned_floor ), expected in: /usr/lib/libaprutil-1.0.dylib.
Reinstalling apr-util fixed my case:
brew reinstall apr-util

FIRST ANSWER:
Sounds like the service started OK then later (or immediately) died, and reports an error. Using the command 'apachectl -e error' should provide details, but you'd wanna check the logs ('vi /usr/local/var/log/httpd/error_log', then shift-G [to goto end]).
SECOND (EXPLAINATION) ANSWER:
"
If you use (sudo) brew services ... to start httpd you have to use the proper (sudo) brew services list command to check the status:
If you start it as root then list it with root privs:
sudo brew services start httpd > sudo brew services list
or with user privs:
brew services start httpd > brew services list.
"

Judging by the result from sudo apachectl -e error, it cannot use port 8080 because another app is using it.
The first warning - can be ignored - or set the FQDN in httpd.conf. Usually this is in the '/usr/local/etc/httpd' folder. Edit with sudo vi /usr/local/etc/httpd/httpd.conf. (I like vi - use whatever you feel comfortable with - sudo open -e /usr/local/etc/httpd/httpd.conf is common).
The default config has the line #ServerName www.example.com:8080, remove that '#' and replace 'www.example.com:8080' with 'MBP-Matteo.local' - or whatever.
Type sudo lsof -i tcp:8080 to list all apps using port 8080, mostly only apps that LISTEN are important.
Next error: You must stop that other app which is using port 8080 (and prevent starting on boot) - or - set Apache to use a different port. (Note: If you choose a port lower than 1024, 'sudo' must be used to start the service.) Usually port 80 is devoted to Apache. The port to be used can be set by editing the config file, as above, then find the line 'Listen 8080', and replace 8080 with the desired port.
After the changes, try to start again with [sudo] 'brew services start httpd'. Then check with [sudo] 'brew services list'. Hopefully all works fine.

FIRST ANSWER: Sounds like the service started OK then later (or immediately) died, and reports an error. Using the command 'apachectl -e error' should provide details, but you'd wanna check the logs ('vi /usr/local/var/log/httpd/error_log', then shift-G [to goto end]).
The first command gives this result:
sudo apachectl -e error
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MBP-Matteo.local. Set the 'ServerName' directive globally to suppress this message
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:8080
no listening sockets available, shutting down
AH00015: Unable to open logs
And the file '/usr/local/var/log/httpd/error_log' is empty
SECOND (EXPLAINATION) ANSWER: " If you use (sudo) brew services ... to start httpd you have to use the proper (sudo) brew services list command to check the status:
The results doesn't change if I executed brew commands with both sudo or without (given that previously I was using without sudo)
Any suggestions?

my solution, stop httpd service, then check httpd.conf and check DocumentRoot "/opt/homebrew/var/www"
<Directory "/opt/homebrew/var/www"> when returning to the original state this route, restart the httpd service and it worked without problems.

A simple brew reinstall httpd fixed it for me. All .conf files remained intact after reinstall for anyone wondering.

Related

Error starting homebrew apache service from command line (mac) [duplicate]

I'm still having some problems on using httpd (aka Apache2) after the update of my MacOs on BigSur.
I tried to make a clean reinstall of apache2 using the brew httpd services (like said in a lot of tutorials) but it still not working. I make a summary of the steps taked and I'll add some debug command.
To reinstall I done:
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd
After that I reboot and launched the command:
brew services start httpd
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)
But if I run the following command:
brew services list
Name Status User Plist
dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
fuseki stopped
httpd error matteo.ceradini /Users/matteo.ceradini/Library/LaunchAgents/homebrew.mxcl.httpd.plist
mongodb-community started matteo.ceradini /Users/matteo.ceradini/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
unbound stopped
As you can see the httpd is in an error status (in fact going to localhost:8080 I get an error) and I can't understand why.
Any suggestion how to fix this?
Thank you.
Something seems to not working, but still I can't find why.
I stopped all the services (either sudo brew and brew without sudo), and next running the commands:
sudo lsof -i :80
sudo lsof -i :8080
sudo lsof -i tcp:80
sudo lsof -i tcp:8080
the results is always nothing. But if I run:
sudo brew services start httpd
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)
The httpd will not start (even if in the terminal command it says yes):
sudo brew services list
httpd error root /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
And if I check the apachetl error I get always that the port 80 is occupied, even if there isn't processes on that port:
apachectl -e error
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
I urgently need to find a solution for this bug. It seems that in some httpd is corrupted, even if I uninstall and reinstall again
UPDATE:
I really don't know how I did it, but now it's working. I stopped all the brew httpd services and I restard apache using the command:
sudo apachectl -k start
and that worked for me
I just had exactly the same issue on Monterey. As digging in, it seems that the problem was a symbol not found ( _apr_bucket_alloc_aligned_floor ), expected in: /usr/lib/libaprutil-1.0.dylib.
Reinstalling apr-util fixed my case:
brew reinstall apr-util
FIRST ANSWER:
Sounds like the service started OK then later (or immediately) died, and reports an error. Using the command 'apachectl -e error' should provide details, but you'd wanna check the logs ('vi /usr/local/var/log/httpd/error_log', then shift-G [to goto end]).
SECOND (EXPLAINATION) ANSWER:
"
If you use (sudo) brew services ... to start httpd you have to use the proper (sudo) brew services list command to check the status:
If you start it as root then list it with root privs:
sudo brew services start httpd > sudo brew services list
or with user privs:
brew services start httpd > brew services list.
"
Judging by the result from sudo apachectl -e error, it cannot use port 8080 because another app is using it.
The first warning - can be ignored - or set the FQDN in httpd.conf. Usually this is in the '/usr/local/etc/httpd' folder. Edit with sudo vi /usr/local/etc/httpd/httpd.conf. (I like vi - use whatever you feel comfortable with - sudo open -e /usr/local/etc/httpd/httpd.conf is common).
The default config has the line #ServerName www.example.com:8080, remove that '#' and replace 'www.example.com:8080' with 'MBP-Matteo.local' - or whatever.
Type sudo lsof -i tcp:8080 to list all apps using port 8080, mostly only apps that LISTEN are important.
Next error: You must stop that other app which is using port 8080 (and prevent starting on boot) - or - set Apache to use a different port. (Note: If you choose a port lower than 1024, 'sudo' must be used to start the service.) Usually port 80 is devoted to Apache. The port to be used can be set by editing the config file, as above, then find the line 'Listen 8080', and replace 8080 with the desired port.
After the changes, try to start again with [sudo] 'brew services start httpd'. Then check with [sudo] 'brew services list'. Hopefully all works fine.
FIRST ANSWER: Sounds like the service started OK then later (or immediately) died, and reports an error. Using the command 'apachectl -e error' should provide details, but you'd wanna check the logs ('vi /usr/local/var/log/httpd/error_log', then shift-G [to goto end]).
The first command gives this result:
sudo apachectl -e error
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MBP-Matteo.local. Set the 'ServerName' directive globally to suppress this message
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:8080
no listening sockets available, shutting down
AH00015: Unable to open logs
And the file '/usr/local/var/log/httpd/error_log' is empty
SECOND (EXPLAINATION) ANSWER: " If you use (sudo) brew services ... to start httpd you have to use the proper (sudo) brew services list command to check the status:
The results doesn't change if I executed brew commands with both sudo or without (given that previously I was using without sudo)
Any suggestions?
my solution, stop httpd service, then check httpd.conf and check DocumentRoot "/opt/homebrew/var/www"
<Directory "/opt/homebrew/var/www"> when returning to the original state this route, restart the httpd service and it worked without problems.
A simple brew reinstall httpd fixed it for me. All .conf files remained intact after reinstall for anyone wondering.

Cannot start jenkins-lts on mac using homebrew

I am trying to install/run jenkins on a mac machine using homebrew. This is what I did
brew install jenkins-lts
On running this command. I see that jenkins-lts is installed and I see this message
Note: When using launchctl the port will be 8080.
To have launchd start jenkins-lts now and restart at login:
brew services start jenkins-lts.
Or, if you don't want/need a background service you can just run:
jenkins-lts
If I run jenkins-lts, Jenkins starts at port 8080 successfully. I can reach it from the browser.
If I run brew services start jenkins-lts . I see the message
Successfully started jenkins-lts (label:homebrew.mxcl.jenkins-lts)
But I cannot reach the server on port 8080. I tried checking the status of the service
I tried checking the status of the service brew services list
Name Status User Plist
jenkins-lts unknown ec2-user /Users/ec2-user/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist
I see that status is unknown.
After a while I see that this service is not listed anymore in the brew services list command. If I try to start it again. I see this message
/Users/ec2-user/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist: service already loaded
Error: Failure while executing; /bin/launchctl bootstrap gui/501 /Users/ec2-user/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist exited
with 37
Where can I find the jenkins logs and how to get it working.
likely you have not configured you host setings
so after starting the service
use
http://127.0.0.1:8080/
not
http://localhost:8080/
This is my experience , brew services list showed up as :
Name Status User Plist
jenkins-lts error cskjk16 /usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.#CD6R ~
and the fix was:
1. brew services stop jenkins-lts
2. brew services start jenkins-lts
and now brew services list showed up as :
Name Status User Plist
jenkins-lts started cskjk16 /usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.#CD6R ~
My solution was to uninstall Jenkins using brew (brew uninstall jenkins-lts), followed by brew doctor, followed by brew clanup, and re-install jenkins (brew install jenkins-lts).
After, I was able to start Jenkins using brew services start jenkins-lts.
Your password will be available at $ cat /User/..../.jenkins/secrets/initialAdminPassword.
Use it to create the admin account and continue the configuration.
The issue here is that, macos was running as a dedicated host on AWS.
I was connected to this macos from my windows machine using putty and trying to run the command.
brew services start jenkins-lts
This does not work. I had to login to macos via some Remote Desktop client like VNC and then run the same command from the the terminal window of mac.
In some cases, there will be a pop up which you needs user input. Hence this did not work when I was connected via putty from my windows machine.
We had the same issues on MacBooks and this is what fixed it.
run this:
chmod u+w /usr/local/var/log
and then run this:
sudu chown -R $(whoami) /usr/local/var/log
then:
brew install jenkins-lts
and it worked

Why doesn't homebrew apache start at startup?

I’m trying to figure out why my apache doesn’t start at startup… (I would like for it to).
My OS: OSX Mojave
Impressions I’m under: that I’m running homebrew’s apache
Upon a fresh boot…
If I hit http://localhost in a browser I get
Unable to connect
Firefox can’t establish a connection to the server at localhost.
Fire up terminal…
$brew services list
returns
httpd started bigpimpin /Users/bigpimpin/Library/LaunchAgents/homebrew.mxcl.httpd.plist
php started bigpimpin /Users/bigpimpin/Library/LaunchAgents/homebrew.mxcl.php.plist
(That first line makes me think httpd is running and I should be able to hit localhost).
$which -a apachectl
returns
/usr/local/bin/apachectl
/usr/sbin/apachectl
then
$apachectl configtest
returns
Syntax OK
then
$sudo apachectl -V
returns (among other things)
-D SERVER_CONFIG_FILE="/usr/local/etc/httpd/httpd.conf"
(Isn’t this brew’s httpd.conf?)
There's a brew command (which I forget) that I already ran that is supposed to run httpd at startup.
Once I run
$sudo apachectl start
everything is jake. So it’s a low-priority question, but one I would like to solve and understand.
I had the same issue with Homebrew NGINX.
Running the brew services command with sudo solved the problem for me.
It appears that the Homebrew web-server packages require sudo to start | stop | restart.
Try running:
sudo brew services start apache2

Can't change document root for apache 2.4

I want to set up local web server using Apache and PHP on my Mac running Sierra. I followed this tutorial:
https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions
And I am stuck at changing the document root from httpd.config, for whatever reason this change does not take effect at all. If I type http://localhost it still says "It works", it still uses the original html file.
Another weird thing is that apparently I can't stop apache at all. I tried running
$ sudo apachectl stop
but I still can’t access http://localhost
if I run
$ brew services list
httpd24 is stopped. What gives? What am I doing wrong?
There is an instance of apache pre-installed with macOS. So you have now two versions of apache installed. If you check:
which apachectl
you will probably obtain:
/usr/sbin/apachectl
which is the official macOS version of apachectl. Stop it with:
sudo apachectl stop
Disable the auto-loading of the pre-installed apache with (as explained in the tutorial you mentioned):
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
To run the homebrew version do:
brew services run httpd24
to stop it:
brew services stop httpd24
to register it to launch at login:
brew services start httpd24

Postgres.app Could not start on port 5432

I'm using http://postgresapp.com. In the menubar it gives the error " Could not start on port 5432." Similarly if I try to start the server from the terminal, I get:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I also ran pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
and got the output server starting but still get the same errors when connecting to psql.
If you are running your server on a macOS machine and installed Postgres through Homebrew, you can stop the current instance like this:
brew services stop postgresql
Then click the Elephant in the native menu-bar at the top of the screen and it should successfully startup.
You can stop the process by finding the PID with
lsof -i :5432
and then killing it with
kill -9 <PID>
If you've installed Postgres via another method (for example, from www.postgresql.org) and it's starting automatically at startup, you can prevent that Postgres from starting via the following:
sudo launchctl unload /Library/LaunchDaemons/com.edb.launchd.postgresql-X.X.plist
sudo rm -f /Library/LaunchDaemons/com.edb.launchd.postgresql-X.X.plist
TIP: use tab to autocomplete after the com.edb.launchd part to figure out what version is loading.
Restart Postgres.app and you should be good to go.
(from http://forums.enterprisedb.com/posts/list/1831.page;jsessionid=70621DC48C99EDE663A6A594B05F1A02#6782)
I was just having this exact issue. When I ran which psql it was pointing at the Postgres client tools installed with Lion:
/usr/bin/psql
Using a hint from Frank Wiles I ran ps auxw | grep post to confirm that postgres was running and that it was running on the right port, that also showed me the postgres.app path:
/Applications/Postgres.app/Contents/MacOS/bin/postgres.
So I edited by .bash_profile to export that directory. On first effort I added it to the end of the path. When I ran echo $PATH I could see that usr/bin was the first thing in the path, and which psql still gave the /usr/bin path. At that point a friend guided me in the right direction:
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:${PATH}"
Start a new terminal window, then run which psql -- it should point to the postgres.app location and psql should fire up the postgres shell. Works fine now.
I have tried just about every solution to this problem that is out there. For me it always happens when my MacBook's battery dies, even if the computer is already sleeping. I was poking around in ~/Library/Application\ Support/Postgres/var-9.4 and I discovered another postmaster.pid file that I had not seen before. I deleted it, and now everything is back up and running! I am running the Postgres.app version, not the brew version.
Steps I took:
Make sure postgres.app is not running.
Run rm ~/Library/Application\ Support/Postgres/var-9.$X/postmaster.pid
If you don't have a var-9.$X directory, just run rm ~/Library/Application\ Support/Postgres/postmaster.pid
Restart postgres.app
Get back to developing cool stuff.
This command is a one-liner that instantly kills all PostgresSQL processes.
sudo kill -kill $(sudo lsof -t -i :5432)
This fixed all my problems on Mac OSX Mojave 10.14.1.
You my have another instance of postgres running, that is the only application interested in this port. You should use netstat and ps to determine this. Then stop the instance and uninstall it, you mayhave installed enterpiseDb for example, that is what I did.
I generally face this issue on my mac, and this fixes it for me always
rm /usr/local/var/postgres/postmaster.pid
brew services restart postgresql
Hope this is helpful
I had a similar problem where I could not connect to the Postgres.app even though the app itself said that it is running on port 5432.
I am not sure why, but even when I quit the app and checked that no postgres processes was running with ps -a. these files existed:
/tmp/.s.PGSQL.5432
and
/tmp/.s.PGSQL.5432.lock
My solution was to delete these files and then start the postgres.app again.
This is what worked for me:
$ sudo pkill -u postgres
Props to this resource:
https://github.com/PostgresApp/PostgresApp/issues/197#issuecomment-474534056
It can also happen that the PID is taken.
This ocurred to me when the Computer suffered an unexpected reboot.
If so, you must go to:
˜/Library/Application Support/Postgres/var-9.4
You can check that path in Postgres.app Preferences dialog.
And then, just remove the pid file
sudo rm postmaster.pid
And the server starts up right away.
When trying to open the Postgres app was getting that same error regarding post 5432 (on Mac OSX 10.10.5)
I did:
$ lsof -i | grep LISTEN
Saw which PID was running postgres at that port, did:
$ killall {pid} and then $ brew uninstall postgres
After that, restarted my Mac, and ran:
$ lsof -i | grep LISTEN again just to make sure. Saw no postgres running anywhere and was able to open the Postgres app without getting that warning.
Then I reinstalled postgres with $ brew install postgres
ANOTHER OPTION:
(I also tried this one time when the above approach didn't work and I could not kill any of the PID)
$ ps auxw | grep post
Saw a slew postgres processes, which I then sudo kill <PID>
Everything working fine now.
For those using mac, this code worked for me like charm.
sudo pkill -u postgres
At a guess, something else had taken port 5432 so the app chose to run on 5433 instead.
Why not just connect to Pg on port 5433, if that's where it's running? You have a /tmp/.s.PGSQL.5432 socket file, so you can connect with psql -p 5433 for UNIX domain socket connections. It'll also be listening on the same port with TCP/IP, so you can use psql -h localhost -p 5433 for TCP/IP and have your apps connect to port 5433 instead of 5432.
Change your .psqlrc to set the new port as default and you can forget it isn't on the default port.
I had similar problem when trying to use postgresql with rails. Updating my Gemfile to use new version of gem pg solve this problem for me. (gem pg version 0.16.0 works). In the Gemfile use:
gem 'pg', '0.16.0'
then run the following to update the gem
bundle install --without production
bundle update
bundle install
Mine failed to start up suddenly, and when I checked Console.app I saw:
com.heroku.postgres-service:
FATAL: could not create shared memory segment: Cannot allocate memory
DETAIL: Failed system call was shmget(key=5432001, size=3874816, 03600).
HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel's SHMALL parameter. You can either reduce the request size or reconfigure the kernel with larger SHMALL. To reduce the request size (currently 3874816 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
The PostgreSQL documentation contains more information about shared memory configuration.
It turns out Postgres wouldn't start up because I had Wireshark (and X11) running. It worked fine after I quit Wireshark.
Good luck!
I resolved this problem by
Identifying what was running on port 5432 by using "netstat" in the CL, which was postgreSQL not Postgres
I located the directory that contained postgreSQL, which was root/Library/PostgreSQL
I ensured an instants of the application wasn't running via Activity Monitor
Then I deleted the folder and rebooted! Everything was fine!
Somehow I totally forgot that this socket file will be hidden because of the dot. Make sure you use ls -A /tmp/.s.PGSQL.5432 if you are checking to see if the socket is actually there.
You most likely has a PostgreSQL installed, deleted it and installed it again. PostgreSQL typically used port 5432 but if not available, increases to the next available one, in this case 5433. So, you probably chose this port on your second install.
I think you should check file:
/etc/services
and adjust rows below for your expected port number:
postgresql 5432/udp # PostgreSQL Database
postgresql 5432/tcp # PostgreSQL Database
After this you should restart your computer (simplest way).
I had the same issues:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
In my case it was a corrupt host file on my mac. I was missing:
127.0.0.1 localhost
A quick easy way to check is to open terminal and type:
ping localhost
or:
scutil -r localhost
More info here
Hope it helps.
Netstat, ps aux, etc ... none showed 5432 in use. Checked /Library. Found PG9.6 old install still there. Did rm -rf and bang. Version 11 works fine.
I was losing my mind over this problem! i kept running
lsof -i | grep 5432
and nothing was showing up!
finally i ran it using sudo and a potgres client showed up.
so if anyone else has tried the lsof and went nowhere, try it with sudo.
sudo lsof -i | grep 5432
and then
sudo kill <the_pid_from_postgresql_found_from_lsof>
The same problem just happened to me. I had Postgres.app 9.2.4.1 running since a while. When I updated Mac OS X to 10.8.5, after the mandatory reboot it was not working anymore. I tried several things, including updating to 9.2.4.3 and neither after another reboot it was working.
I had to open the file /Users/$USER/Library/Application Support/Postgres/var/postgresql.conf and to:
uncomment line unix_socket_permissions = 0777
uncomment and adapt line unix_socket_directory = '/tmp'
After a restart, Postgres.app was running like a charm.
A file named "postmaster.pid" (in my $PGDATA directory) were preventing postgresql to start. It was a zombie file, placed there 10 days ago and when I brutally shut down the computer (pulling the plug, literally), no clean up process had the opportunity to remove that file.
beside all the helpful answers, you might also want to take a look at official page instructions :
postgressapp.com/documentation/remove.html
I had this same issue and mine was caused by some configuration issues I was having. Clearing the user configurations and reinstalling postgres in brew worked for me!
brew uninstall postgresql
rm -rf /usr/local/var/postgres
I ran the following:
psql --version then brew services stop postgresql#<VERSION>
finally, start your Postgres app on your Mac.

Resources