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

zync09's avatar

Some help with Forge please, losing my mind

Hi all,

Just trying to get my app deployed for a test to a digital ocean droplet, first time deployment, read way too many tutorials and think I've gotten confused somewhere downt he track of it. I've bought Forge and a cheapo digital ocean server, just a $5 one. But I'm stuck beyond belief with trying too deploy my app there. I keep getting something like this when trying to deploy from my BitBucket repo. Bit bucket is linked fine too.

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize

                                                                               
  [Illuminate\Database\QueryException]                                         
  SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using pa  
  ssword: NO) (SQL: select * from `modules`)                                   
                                                                               

                                                                               
  [PDOException]                                                               
  SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using pa  
  ssword: NO)                                                                  
                                                                               

Script php artisan optimize handling the post-install-cmd event returned with error code 1

I don't know where that user is coming from, where do i setup the database user in a bitbucket pull? That and I can't even seem to SSH into my droplet after Forge has done its thing setting it up. I've setup my SSH public keys and it looks good. But no idea how to do anything after this. I thought forge was meant to make life easy? Please can anyone help?

0 likes
14 replies
jlrdw's avatar

Ok to try to help, I don't use forge, but have you watched the videos on it, could solve the problem.

zync09's avatar

I have but they are over 3 years old and Forge looks different now. Does anyone use it currently with bitbucket?

Or I don't mind trying it any other way long as I can get this app continuously deployed on commit.

zync09's avatar

Cheers for that mate, have tried that too. For some reason when installing composer dependencies is checked it breaks. When it's not it seems to grab that files OK, but there is still some huge issue with Forge. Either the username and passwords or something don't work out of the box or there are meant to go somewhere and I'm not sure where.

There is no instructions for this thing.

zync09's avatar

"Your application is making DB calls on every Artisan command. That is causing problems when trying to install your repository because we don't have time to get the .env file in place."

I got that back from Forge help and support but have no idea what that means or how to fix it. Can anyone shed some light on this? I just want to install my app. or can I cancel forge and just do it manually somehow? Any decent tutorials for that are up to date with 5.4?

isaackearl's avatar

@zync09 You have to set your environment variables on forge so that it uses the proper database credentials etc. In forge click on the site, then on the left you'll see "Environment". Then you can set your environment variables. This is the same thing as your .env file that you set in your local. You'll need to set DB_DATABASE, DB_USERNAME, DB_PASSWORD etc so it uses the forge username and password etc. You should have recieved that password when you provisioned the server on forge (it emails to you).

Let me know if you get stuck.

if you never setup a .env file, then take a look at the .env.example file in your local development folder.

Ultimately the commands get run off the values in your config/database.php file... however this file tries to grab values of of the environment variables you set.

zync09's avatar

Hi @isaackearl,

Cheers for that mate. But Have done that already too. I just did a Self Help > Reset the deployment site.

--FYI Not the real password--

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=forge
DB_PASSWORD=B7R6CoJXStWLX

Added the above settings in the Forge environment variables.

I've linked bitbucket in Forge so I have the option to select it, selected it.

Type in my repo and have install composer dependancies check and click go.

But then I keep getting this error:

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize

                                                                               
  [Illuminate\Database\QueryException]                                         
  SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using pa  
  ssword: NO) (SQL: select * from `modules`)                                   
                                                                               

                                                                               
  [PDOException]                                                               
  SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using pa  
  ssword: NO)                                                                  
                                                                               

Script php artisan optimize handling the post-install-cmd event returned with error code 1

I also notice when I check back in the environment variable, even if I click off the modal window and even after pressing save. the settings will disappear. Seems like Forge is just pretty buggy or I'm doing something completely wrong and theres not a scrap of instructions on the Forge site to help.

isaackearl's avatar

@zync09 so it seems like it is pulling in your repo just fine from bitbucket based on the fact that it is trying to install it etc... It just isn't picking up your password :(.

Have you looked at your database.php file to make sure that DB_PASSWORD isn't hardcoded for the database type you are using. Had a friend who had set that up accidentally and so it wasn't reading the DB_PASSWORD from his .env file.

Have you been able to ssh in yet? If I were you I might ssh go to the directory for your site and see if you can tinker with it to get it to work. That would get you the clue you need to fix the deployment.

Are you on windows or mac/linux ? If you are on mac/linux then do this:

cat ~/.ssh/id_rsa.pub

then copy the entire thing into the SSH tab on for for that server. then you should be able to connect to it simply by doing this:

ssh [email protected] // whatever your ip address is

Once you are in there, then i would go to the folder and try and do a composer install and try and connect to the database using the command line mysql tool etc, and figure out what is going on.

mdecooman's avatar

Hi @zync09

The usual workflow is.

//On Forge
- Link your Git account (you did)
- Make sure you can SSH into your server with your ssh priv/pub key (you did)
- Create a User/DB for your app
- Optional: Access it from a tool like SQL Pro with the forge credentials you received and do whatever you want.
- Create your app
- Edit the .env file, paste a template and modify accordingly (with the DB credentials you just created)
- Link it to your repository (make sure you commit your composer.lock, recommended)

If not working: can you publish without checking the box of installing composer dependencies. Edit the .env file in production. SSH in and run a composer install yourself and see what error you may have? It may give you some hints

1 like
zync09's avatar

Hi @isaackearl . Did your suggestion and looks like forge doesn't put in the password into the database.php file in the config directory.

And @mdecooman Did what you suggested too and edited my .env file. also managed to connect to the database with navigate so that's definitely working. I can't seem to run a php artisan command though. Even after doing a composer install. Kept getting. I couldn't even run migrate

> php artisan optimize


  [Illuminate\Database\QueryException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forge.modules' doesn't exist (SQL: select * from `modules`)



  [PDOException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forge.modules' doesn't exist


Script php artisan optimize handling the post-install-cmd event returned with error code 1
forge@colorful-canopy:~/bebrilliant.mustardstaging.com.au$ php artisan migrate


  [Illuminate\Database\QueryException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forge.modules' doesn't exist (SQL: select * from `modules`)



  [PDOException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forge.modules' doesn't exist

So I just copied the tables from my local machine to the server with navicat and that seemed to work. Why would it do this though? Seems like a lot of extra work when forge is meant to make things simplier?

The only tech support I got back from forge was:

Your application is making DB calls on every Artisan command. That is causing problems when trying to install your repository because we don't have time to get the .env file in place.

Where would it be making the calls though?

isaackearl's avatar

not sure @zync09, maybe try re-provisioning the server?

I have several sites deployed with forge now and I've never had any issue like that.

From your error message, it seems like the command is trying to access a database called forge. Is that what it is called in your database.php config file/.env file etc ? In other words are you pointing at the correct database?

Sorry at this point I can't think of much else to try. You could try to reprovision and see if you can ssh into the new server and manually deploy just to find out if all the environment stuff is setup right like php/mysql etc. Might give you some clues as to what is going on.

1 like
zync09's avatar

OK found the problem. It kept erroring out on Modules and I had no idea where the call was coming from. Apparently I had some counts that I needed in my app on every screen and that's why forge was complaining. Moved these to their own function now and site deployed with no issues.

Thanks for your help all, got there in the end.

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
      View::share('module_count', \App\Module::all()->count());
      View::share('topic_count', \App\Topic::all()->count());
      View::share('exercise_count', \App\Exercise::all()->count());
      View::share('user_count', \App\User::all()->count());
    }
}

Please or to participate in this conversation.