Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

IsaacBen's avatar

Getting access denied on new deployment via forge

My projects works fine on my local machine. I have no idea what might be wrong. I have a clients table, but not sure where this query is coming from. Just to be clear, the deployment fails.

                                       
  [Illuminate\Database\QueryException]                                                                                                                                            
  SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: select * from `clients` where `clients`.`deleted_at` is null order by `name` asc)  
                                                                                                                                                                                  

   [PDOException]                                                                          
  SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)
0 likes
12 replies
JoshMountain's avatar

The error suggests that Laravel can't access your database (and also that it is trying to access it without a password). I'm guessing you don't have your .env configured properly in the database section.

IsaacBen's avatar

@JoshMountain When I do composer install from the command line I get this

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forge.clients' doesn't exist (SQL: select * from `clients` where `clients`.`deleted_at` is null order by `name` asc)  

Why is sql running on composer install?

Shouldn't the ENV file come after installing the repository?

I also have the ENV file configured correctly.

JoshMountain's avatar

Hmm that definitely isn't normal, the .env should be generated automatically yes. Try restarting the server through Forge, maybe the .env never loaded properly into the environment.

IsaacBen's avatar

@JoshMountain Just in case I rolled back migration in my local machine and now I get the same errors.

Base table or view not found: 1146 Table 'crm.clients' doesn't exist

These errors are useless as they don't direct me to the line of issue. I do have that table.

IsaacBen's avatar

Wow, I found the error. It was because of my globals in the App service provider.

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $clients    = Client::orderBy('name', 'asc')->get();
        $statuses   = Status::orderBy('status', 'asc')->get();
        $priorities = Priority::orderBy('priority', 'asc')->get();
        $locations  = Location::all();
        View::share([
            'clients'    => $clients,
            'statuses'   => $statuses,
            'priorities' => $priorities,
            'locations'  => $locations
        ]);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

Is this normal?

JoshMountain's avatar

Whether it is normal would depend on the application you pulled in I suppose, Forge doesn't touch your AppServiceProvider at all.

Laravel is complaining about your View::share because those tables don't seem to exist (or at least not in a databased called crm).

IsaacBen's avatar

@JoshMountain Yes, but it actually ran that code before tables were migrated, This is why I got the error that table didn't exists.

JoshMountain's avatar

This might be something migration related then. If you delete all the tables in your local machine database and run php artisan migrate on an empty database do all the migrations run successfully?

IsaacBen's avatar

@JoshMountain No. They don't run unless I comment out the code in the AppServiceProvider. Maybe this is a natural behavior, but I didn't see it mentioned in the docs.

JoshMountain's avatar
Level 8

Ah okay now I understand! The issue is because these service providers are loaded on boot, so they load when an artisan command runs. In that sense yes this is normal. You can use $this->app->runningInConsole() to determine if Laravel is running in the console, during migrations and the like, (thanks @martinbean - Link to his original post) and skip your view composers.

Please or to participate in this conversation.