You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel/Homestead环境下PhpMyAdmin访问及migrate命令报错求助

Hey there, let’s break down these two issues you’re facing with Homestead—they’re definitely connected, so fixing one will likely knock out the other too!

1. Fixing the phpMyAdmin Subpath 404 Issue

First, let’s clarify why this is happening: Homestead sets up phpMyAdmin as a standalone site by default, mapped to phpmyadmin.test—not as a subdirectory of your Laravel project. That’s why mylaravelproject.test/phpmyadmin throws a 404; there’s no Nginx configuration or Laravel route handling that path.

You’ve got two solid options:

  • Option 1 (Easiest, use the default setup): Stick with accessing phpMyAdmin via http://phpmyadmin.test. This is the intended workflow—just double-check your local hosts file has an entry for phpmyadmin.test pointing to Homestead’s default IP (192.168.10.10).
  • Option 2 (Add subpath access if you prefer):
    1. SSH into your Homestead VM: homestead ssh
    2. Open your project’s Nginx config (usually at /etc/nginx/sites-available/mylaravelproject.test)
    3. Add this location block inside the server block (adjust the PHP version to match your Homestead setup):
      location /phpmyadmin {
          alias /usr/share/phpmyadmin;
          index index.php index.html index.htm;
          location ~ ^/phpmyadmin/(.+\.php)$ {
              alias /usr/share/phpmyadmin/$1;
              fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
              fastcgi_index index.php;
              include fastcgi_params;
              fastcgi_param SCRIPT_FILENAME $request_filename;
          }
      }
      
    4. Test the Nginx config for errors: sudo nginx -t
    5. Reload Nginx to apply changes: sudo systemctl reload nginx

2. Fixing the Migrate Connection Refusal Error

This error almost always comes from a mismatch between your local Laravel .env config and the Homestead VM’s database setup. Here’s how to fix it:

  • Step 1: Update your .env file
    Open your project’s .env and make sure these values match Homestead’s defaults (adjust if you set custom DB credentials in Homestead.yaml):
    DB_CONNECTION=mysql
    DB_HOST=192.168.10.10 # Critical: use the VM's IP, NOT localhost
    DB_PORT=3306
    DB_DATABASE=homestead # Or your custom database name
    DB_USERNAME=homestead
    DB_PASSWORD=secret
    
  • Step 2: Verify the database exists in the VM
    SSH into Homestead, log into MySQL, and check if your target database is there:
    mysql -u homestead -psecret
    SHOW DATABASES;
    
    If it’s missing, create it with CREATE DATABASE your_database_name;
  • Step 3: Run migrate correctly
    You have two reliable ways to run migrations:
    1. Local machine: With the .env fixed, just run php artisan migrate locally—Homestead forwards the VM’s MySQL port to your host by default.
    2. Inside the VM: SSH into Homestead, navigate to your project folder (cd /home/vagrant/code/mylaravelproject), then run php artisan migrate. This avoids any network routing hiccups.

Why These Issues Are Linked

Both problems boil down to understanding how Homestead isolates services:

  • phpmyadmin.test works because it points directly to the VM, so it connects to the VM’s MySQL instance.
  • The subpath 404 happens because Nginx doesn’t know to route mylaravelproject.test/phpmyadmin to the phpMyAdmin directory.
  • The migrate error occurs if your .env uses DB_HOST=localhost—your local machine tries to connect to its own MySQL (which isn’t running the Homestead database), hence the refusal. Fixing the .env to use the VM’s IP aligns your migrate command with the same database phpMyAdmin uses.

内容的提问来源于stack exchange,提问作者Brad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:37:27