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

jayscottelliott's avatar

Forge Deployment failing on >php artisan optimize

I am setting up forge for the first time. My initial pull from bitbucket seemed to work. However now when i hit deploy i get the following error

> php artisan optimize
Generating optimized class loader
Compiling common classes

                                                                                                                                                        
 [Illuminate\Database\QueryException]                                                                                                                      
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from                    information_schema.tables where table_schema = energya and table_name = migrations)  
                                                                                                                                                        

                                                
[PDOException]                                    
SQLSTATE[HY000] [2002] No such file or directory  

When i SSH in and look there are no tables in the database. So I am assuming the migrations have not worked. Have looked online but have not found any solution.

0 likes
17 replies
SaeedPrez's avatar

Did you setup your database before the first deployment? Also make sure your .env is setup correctly, with APP_ENV=production

jayscottelliott's avatar

Following the guide i thought this would be setup when i deploy. I have setup the .env file.

I have also tried creating a new DB and user and adding these details into the .env file but i get the same error.

Tried manually doing php artisan migrate and also get the same error.

SaeedPrez's avatar

Hm, if you're using localhost in your .env file, try replace it with 127.0.0.01

DB_HOST=127.0.0.1
1 like
ejdelmonico's avatar

You need to run php artisan config:clear after changing the config files because the config is cached. Then, you can run php artisan migrate.

jayscottelliott's avatar

Just tried php artisan config:clear

I still get the same error.

php artisan migrate
[Illuminate\Database\QueryException]                                         

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from inform ation_schema.tables where table_schema = energya and table_name = migration s)

It seems to be able to connect as it is throwing No such file or directory not a connection error.

ejdelmonico's avatar

Make syre your forge user for the DB values are correct in .env. I use localhost on all of my forge servers. Sometimes, after changing the config and clearing cache, I have had issues continue until I redeployed the project. Then, I was able to migrate.

SaeedPrez's avatar

See if this helps..

Edit config/database.php and add the last line as example shown below..

        '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' => true,
            'engine' => null,
            'unix_socket' => '/tmp/mysql.sock', // <<-- add this line
        ],
jayscottelliott's avatar

Just tried adding this-

'unix_socket' => '/tmp/mysql.sock', // <<-- add this line

Still the same error. I also tried to create another database on the server and use the details for that. Also tried importing the database from my local machine to see if having existing tables would make a different.

Still just get the same error.

SaeedPrez's avatar

@jayscottelliott with the /tmp/mysql.sock in place try run php artisan config:clear and composer dump-autload and then try to migrate again..

If it doesn't work, log in to Forge, at the bottom right there is a Help > Contact us button. I'm running out of ideas :(

jayscottelliott's avatar

Thanks for you help. I have lodged with forge support. Will post the solution if I get it fixed.

EE's avatar

I know the post is old but possible issue is your AppServiceProvider.

2 likes
EE's avatar

@itsali @develalfy in my case I was running query on my service provider like below. It was giving me error without using try catch . So with wrapping my query with try catch I solved my issue.

        try {
            if (Schema::hasTable('settings')) {
                $settings = Setting::pluck('value', 'key')->toArray();
                if (isset($settings['media_lock'])) {
                    if ($settings['media_lock'] == 'false') {
                        //do something
                    }else{
                         //do other things
                    }
                }
            }
        } catch (\Illuminate\Database\QueryException $e) {
            app('log')->error($e->getMessage());
        }

paulbarker's avatar

The same issue here, I had this going on:

public function boot()
    {
        Schema::defaultStringLength(191);

        Gallery::deleting(function ($gallery) {
            \Storage::delete('galleries/' . $gallery->id);
        });

        View::share('recentArticles', $this->getRecentArticles());
    }

My AppServiceProvider was trying to grab articles from a database that hadn't been set up yet, and in the Forge pipeline, .env is generated after a successful first build. I wonder if there's a better way to do a first build on Forge...

Firemaps's avatar

I've just linked my GitHub to a shared private repo on Forge, getting the same error.

ejdelmonico's avatar

@firemaps If you are the repo owner, then permissions should be correct. Go into the profile settings of Forge and refresh your github token. Sometimes, that will fix the issue. If you are not the listed owner of the repo, then have the owner give you full permissions on that repo.

1 like

Please or to participate in this conversation.