【问题标题】:Laravel won't reload .env file on MAMPLaravel 不会在 MAMP 上重新加载 .env 文件
【发布时间】:2016-06-08 03:51:00
【问题描述】:

我最近从使用内置的 Apache2 和 Mac 上的 PHP 安装切换到最新版本的 MAMP (3.5) 并将我的所有项目移到 htdocs 文件夹中。在我更新到新的 MySQL 信息后,除了我的 Laravel 项目外,一切正常。尝试访问使用 MySQL 的任何内容时,我收到此错误

PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'cumc'@'localhost' (using password: YES)

新的 .env 文件在数据库信息中如下所示。

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cumc
DB_USERNAME=root
DB_PASSWORD=root

因此,由于错误,似乎某些内容正在被缓存,但我已经运行了所有我能找到的缓存:清除命令,重新启动 MAMP,我的 Mac,并尝试了我能想到的一切。即使用新的详细信息更改app/database.php,并更改.env 的名称使其无法加载,它仍然会显示错误。

这是config/database.php 文件

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | PDO Fetch Style
    |--------------------------------------------------------------------------
    |
    | By default, database results will be returned as instances of the PHP
    | stdClass object; however, you may desire to retrieve records in an
    | array format for simplicity. Here you can tweak the fetch style.
    |
    */

    'fetch' => PDO::FETCH_CLASS,

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'cluster' => false,

        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],

    ],

];

【问题讨论】:

  • 尝试在 Config->database.php 以及 .env 文件中更改详细信息,然后使用此命令 php artisan serve
  • @PardeepPathania 是我能够让它工作的唯一方法是使用php artisan serve?因为我希望 MAMP 允许我直接运行它而不必这样做。
  • 1) 做一件事尝试创建虚拟主机。它可能会解决您的问题
  • @PardeepPathania 如何在 MAMP 中进行设置。我没有使用专业版。

标签: php mysql apache laravel mamp


【解决方案1】:

运行php artisan config:clear,它会清除缓存的配置。

【讨论】:

  • 我已经运行了 3 次,然后重新启动了 MAMP 服务器,它仍然给出同样的错误。
  • 我添加了它。它应该与全新安装相同。
  • 尝试运行php artisan cache:clear。另外,删除bootstrap/cache 中的所有文件并运行composer dumpauto
  • 我运行了命令,删除了文件,然后重新启动了服务器,它仍然使用相同的凭据。现在将其存储在哪里是没有意义的。我应该尝试使用我的作曲家文件重新安装 larval 吗?
  • @hightekjonathan,尝试在 Laravel 项目文件夹中使用全文搜索,搜索cumc,也许你会发现一些有趣的东西。
【解决方案2】:

2021 年与 Mamp Pro 的行为相同。 实际上,配置存储在会话中。 如果会话保存在文件中,则通过删除 storage/framework/sessions/ 的内容来解决它。 如果保存在数据库中(例如 mysql ),只需清空正确的表。 等等:)

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 2017-06-25
    • 2016-10-17
    • 2016-02-12
    • 1970-01-01
    • 2015-11-12
    • 2017-03-13
    • 1970-01-01
    • 2015-11-28
    相关资源
    最近更新 更多