Unable to connect to localhost after MAMP installation

Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
I am using homebrew to set up Apache and PHP on MacOS Monterey since Apple no longer supports PHP. I have successfully installed homebrew and have been following the instructions at How to Setup MAMP (MacOS, Apache, MySQL, PHP) Local Server on macOS 12 Monterey M1 Mac (2021). I have also checked the homebrew console output which tells me that whereas tech-cookbook refers to /opt/homebrew/etc/httpd/ this should be replaced by /usr/local/opt/httpd/

The installation seems to have worked OK:

% brew services restart httpd
Stopping `httpd`... (might take a while)
==> Successfully stopped `httpd` (label: homebrew.mxcl.httpd)
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)
% brew services restart php
Stopping `php`... (might take a while)
==> Successfully stopped `php` (label: homebrew.mxcl.php)
==> Successfully started `php` (label: homebrew.mxcl.php)

But when I try to access localhost via browser I get

Unable to connect
An error occurred during a connection to localhost.

I have checked the content of httpd.conf many times. Can anyone suggest how to find out what's wrong?

Thank you.
- Malcolm
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,762
Reaction score
2,100
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Does 'brew services list' show HTTPD as a running service?
 
OP
M
Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
Looks like it:

% brew services list
Name Status User File
httpd started malcolmi ~/Library/LaunchAgents/homebrew.mxcl.httpd.plist
php started malcolmi ~/Library/LaunchAgents/homebrew.mxcl.php.plist

Regards
- Malcolm
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,762
Reaction score
2,100
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
OK and you've see the correct DocumentRoot option in your configuration file? If you have nothing of value in the folder you're pointing to, you should at least see a folder listing indicating that the web server is up.
 
OP
M
Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
/usr/local/etc/httpd/httpd.conf has the following (amongst others):

ServerName localhost

<Directory />
AllowOverride none
Require all denied
</Directory>

#DocumentRoot "/usr/local/var/www"
#<Directory "/usr/local/var/www">
DocumentRoot "/Users/malcolmi/Sites/"
<Directory "/Users/malcolmi/Sites/">

I have also tried ServerName localhost:80 and localhost:8080 to no avail.

Neither Safari nor Firefox can connect to localhost.
 
OP
M
Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
I have also checked Activity Monitor. There are 6 httpd processes. I have quitted one of them and they all disappear. Then I type

% brew services restart httpd

and all six reappear in the list. So it seems that the brew services command is successful in kicking off the daemon. However browsers are still unable to connect - Safari says:

Safari can't open the page "localhost" because Safari can't connect to the server "localhost".
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,762
Reaction score
2,100
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Ok, you should reset back the beginning and get things work natively first and then make changes.

So do the following "brew uninstall httpd" and uninstall the server completely. Then install it again and don't make any changes. Then start up the service with "brew services start httpd" and visit http://localhost:8080 and it should say "It works!"

If that isn't the case, then something more basic is wrong and you shouldn't proceed.

I made similar changes and things worked, while doing that I noted that you made a mistake in your change, a very subtle one.

When you copied the DocumentRoot and Directory settings, you added an extra "/" at the end, remove that like the default values that were there and things should work.
 
OP
M
Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
I've tried uninstalling and reinstalling. The console output gave me

malcolmi@Malcolms-iMac ~ % brew services start httpd
Service `httpd` already started, use `brew services restart httpd` to restart.
malcolmi@Malcolms-iMac ~ % brew services restart httpd
Stopping `httpd`... (might take a while)
==> Successfully stopped `httpd` (label: homebrew.mxcl.httpd)
Error: Formula `httpd` is not installed.

I tried another uninstall with the intention of additionally deleting all files in usr/local/opt/httpd as well but now I get:

malcolmi@Malcolms-iMac ~ % brew uninstall httpd
Error: No such keg: /usr/local/Cellar/httpd

Am I digging myself into an ever deepening hole here? How best to start from scratch?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,762
Reaction score
2,100
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Do a "brew list" and see if HTTPD is listed. If not, then it's properly uninstalled.

You should then delete the files it leaves behind with a "rm -rf /usr/local/etc/httpd"

Now, do the install again, and "brew services start httpd" to start it up and visit the site.

Oh, and stop following that other site since it's just messing you up.. 😃

Once you can visit localhost and get the boilerplate result, then go through the process of moving DocumentRoot and so on paying close attention to how the entries look right now and continue your journey.
 
OP
M
Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
Sadly, it's behaving just as before - Safari can't connect to the server "localhost". I have reinstalled and started httpd and the console hasn't flagged any errors during installation or startup. As you suggested I haven't made any changes to httpd.conf. The brew list includes httpd and Activity Monitor shows 6 httpd processes.

However the error.log says:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Malcolms-iMac.local. Set the 'ServerName' directive globally to suppress this message
[Tue Feb 07 16:47:58.683493 2023] [mpm_prefork:notice] [pid 56143] AH00163: Apache/2.4.55 (Unix) configured -- resuming normal operations
[Tue Feb 07 16:47:58.684473 2023] [core:notice] [pid 56143] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd -D FOREGROUND'

The ServerName directive is commented out in the (unedited) httpd.conf - could this be the problem? If so, what should I set it to?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,762
Reaction score
2,100
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
I have a similar, but subtly different message in my error.log

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

In your case, it's using the name Malcolms-iMacs.local, so try using that in the browser as opposed to localhost and see what happens.
 
OP
M
Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
No, that doesn't work either! I have also tried apachectl configtest - Syntax OK. I have checked /etc/hosts and that seems OK. I've tried connecting to 127.0.0.1.

I'm in the process of searching the web more widely for answers. If I find anything that works I'll report back here.

Thank you for your help and patience, by the way.

- Malcolm
 
OP
M
Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
I have just tried connecting to localhost:8080 and ... SUCCESS! that returns Apple's default Sites/index.html - I can't access my own local website files though - must be a permissions thing. And php doesn't seem to be working even though I've restarted it. Progress anyway.
 
OP
M
Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
I seem to be almost there but ... If I visit localhost:8080 the browser returns Sites/index.html and that's great but if I try to visit my websites under Sites/ I get

Forbidden
You don't have permission to access [my websites] on this server.

This seems to be a well-known problem going back many years and there are published fixes for MacOS built-in Apache (like creating a ~myusername.conf) but I can't find anything for the Homebrew httpd. installation, can anyone help?
 
OP
M
Joined
Jan 2, 2009
Messages
55
Reaction score
3
Points
8
I seem to have succeeded at last in getting the Homebrew installed XAMPP webserver to work. It seems that the url needs to be different from the value I was using previously with Apple's built-in Apache.
(1) The localhost port number is required in the url - i.e. localhost:8080
(2) url should be
localhost:8080/Sites_subdirectory/index.php
instead of
localhost:8080/~myusername/Sites_subdirectory/index.php
I hope this helps anyone else hitting the same problem.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top