You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

新Mac(High Sierra)无法访问localhost、本地站点及phpMyAdmin求助

Troubleshooting Localhost, Local Sites & phpMyAdmin Access on New Mac

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 status
    

    If it reports it's running but you still can't access localhost, check the error logs for clues:

    tail -f /var/log/apache2/error_log
    

    Look for lines about missing modules, permission issues, or configuration syntax errors.

  • Confirm PHP module is loaded in Apache
    Even if your httpd.conf matches 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 LoadModule line for PHP is uncommented in httpd.conf and 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.

  • Validate virtual host configuration
    Even if httpd-vhosts.conf is identical, ensure:

    • The line including this file in httpd.conf isn't commented out:
      Include /private/etc/apache2/extra/httpd-vhosts.conf
      
    • The DocumentRoot paths in your virtual hosts match the actual file locations on your new Mac (e.g., if your username changed, paths like /Users/yourname/Sites will need updating).
    • Check Apache's virtual host status to confirm your sites are recognized:
      apachectl -S
      
  • Check for port conflicts
    macOS sometimes uses port 80 for system services like AirPlay Receiver. Verify if port 80 is occupied:

    sudo lsof -i :80
    

    If another process is using it, either stop that service (via System Settings > Sharing) or change Apache's listen port in httpd.conf from Listen 80 to Listen 8080, then access localhost:8080.

  • Troubleshoot phpMyAdmin specifically
    Since MySQL works via Workbench, the issue is likely in phpMyAdmin's connection settings:

    • Open your phpMyAdmin config.inc.php file (usually in /usr/local/share/phpmyadmin or 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.conf or a dedicated phpmyadmin.conf:
      Alias /phpmyadmin "/usr/local/share/phpmyadmin"
      <Directory "/usr/local/share/phpmyadmin">
          AllowOverride All
          Require all granted
      </Directory>
      
  • Test a basic PHP page
    Create a file named info.php in your default Apache document root (usually /Library/WebServer/Documents or your user Sites folder) with this content:

    <?php phpinfo(); ?>
    

    Try accessing localhost/info.php (or localhost:8080/info.php if 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

火山引擎 最新活动