我目前正在使用 Sail 开发 Laravel 项目。一切都在本地完美运行,包括运行 artisan migrate 命令。但是,当我尝试使用反向代理在我的 Fedora 服务器上部署项目时,在运行迁移时遇到了问题。
当我在服务器上运行迁移命令(./vendor/bin/sail artisan migrate)时,收到以下错误:
SQLSTATE\[HY000\] \[1045\] Access denied for user 'sail'@'192.168.160.3' (using password: YES) (Connection: mysql, SQL: select \* from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
756▕ // If an exception occurs when attempting to run a query, we'll format the error
757▕ // message to include the bindings with SQL, which will make this exception a
758▕ // lot more helpful to the developer instead of just the database's errors.
759▕ catch (Exception $e) {
➜ 760▕ throw new QueryException(
761▕ $this-\>getName(), $query, $this-\>prepareBindings($bindings), $e
762▕ );
763▕ }
764▕ }
为了更好地了解可能导致此问题的原因并获得解决此问题的帮助,我将详细介绍在出现此问题之前我所执行的任务的完整过程。我希望通过提供这些信息,我可以获得意见和建议,以最终克服这个障碍并继续开发我的 Laravel 项目。
我有点迷失,不知道该怎么做才能解决这个问题。如果有人有任何想法或建议,我将很高兴听到他们的声音。我需要解决这个问题,以便我可以继续从事这个项目。
预先感谢您的帮助。
我的.env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:ZeM4sQDei27icN6cC1GJMpIAekJAv/yLBp+6c7vjTkc=
APP_DEBUG=true
APP_URL=http://localhost
APP_PORT=80
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
#DB_HOST=host.docker.internal. i try to
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=sail
DB_PASSWORD=password
我的docker-compose.yml
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.2
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.2/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sail-mysql:
driver: local