新Mac(High Sierra)无法访问localhost、本地站点及phpMyAdmin求助
Hey there, let's work through this issue step by step—you've already covered a lot of the key basics, so let's focus on the remaining likely culprits:
Verify Apache is running and check for errors
First, make sure Apache is actually up and running. Run these commands in Terminal:sudo apachectl start sudo apachectl statusIf it reports it's running but you still can't access localhost, check the error logs for clues:
tail -f /var/log/apache2/error_logLook for lines about missing modules, permission issues, or configuration syntax errors.
Confirm PHP module is loaded in Apache
Even if yourhttpd.confmatches your old Mac, the PHP module path might differ on your new system (especially if you're using Homebrew PHP vs. the deprecated system PHP).- Check if the
LoadModuleline for PHP is uncommented inhttpd.confand points to an existing file. For example, a Homebrew PHP 8.x line would look like:LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so - Verify the module is loaded with:
apachectl -M | grep php
If you don't see
php_module (shared), the module isn't loading—double-check the path or reinstall PHP if needed.- Check if the
Validate virtual host configuration
Even ifhttpd-vhosts.confis identical, ensure:- The line including this file in
httpd.confisn't commented out:Include /private/etc/apache2/extra/httpd-vhosts.conf - The
DocumentRootpaths in your virtual hosts match the actual file locations on your new Mac (e.g., if your username changed, paths like/Users/yourname/Siteswill need updating). - Check Apache's virtual host status to confirm your sites are recognized:
apachectl -S
- The line including this file in
Check for port conflicts
macOS sometimes uses port 80 for system services like AirPlay Receiver. Verify if port 80 is occupied:sudo lsof -i :80If another process is using it, either stop that service (via System Settings > Sharing) or change Apache's listen port in
httpd.conffromListen 80toListen 8080, then accesslocalhost:8080.Troubleshoot phpMyAdmin specifically
Since MySQL works via Workbench, the issue is likely in phpMyAdmin's connection settings:- Open your phpMyAdmin
config.inc.phpfile (usually in/usr/local/share/phpmyadminor your Sites folder) and confirm:$cfg['Servers'][$i]['host'] = '127.0.0.1'; // Try 127.0.0.1 instead of localhost if socket connections fail $cfg['Servers'][$i]['socket'] = '/tmp/mysql.sock'; // Match your MySQL socket path—get it with `mysql_config --socket` - Ensure Apache has access to the phpMyAdmin directory. Check for an Alias and Directory block in
httpd.confor a dedicatedphpmyadmin.conf:Alias /phpmyadmin "/usr/local/share/phpmyadmin" <Directory "/usr/local/share/phpmyadmin"> AllowOverride All Require all granted </Directory>
- Open your phpMyAdmin
Test a basic PHP page
Create a file namedinfo.phpin your default Apache document root (usually/Library/WebServer/Documentsor your user Sites folder) with this content:<?php phpinfo(); ?>Try accessing
localhost/info.php(orlocalhost:8080/info.phpif you changed ports). If this loads, the problem is isolated to your virtual hosts or phpMyAdmin; if not, Apache/PHP isn't configured correctly.Rule out browser caching
Try accessing your sites in a private/incognito window to eliminate cached redirects or outdated content.
内容的提问来源于stack exchange,提问作者DBerg




