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

johngrotts's avatar

Cannot Deploy With Forge

I am very confused as to why I cannot deploy with forge. I forked the base laravel and it works fine, but my own project does not, so it is something in my code that is causing the problems.

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

That is the error I am getting. Having read through many other posts on this error it seems I have an issue with my .env file, which is not downloaded to git. When installing the repository, I click the Environment tab, click "Edit Environment" and paste in the .env file, with the changes made to the database parts. That did not work. I created a new database and put in those credentials, that did not work. I am at a loss here. Does anyone have any ideas on what I need to do, have an idea on what mistake I am making, or know where to find a tutorial to help me? I have been trying to setup a server for laravel for several weeks now, with no success, avoiding forge as I wanted to learn how to do it from the ground up. Now that I have given up on going fro the ground up and using forge, only to be met with failure again is very disheartening.

0 likes
28 replies
SaeedPrez's avatar

Go to Forge, then your site, the Environment tab, click Edit Environment.. you need to configure the DB_* environments, you got an email with database name, user, password, etc when Forge setup your server.

johngrotts's avatar

That did not work. I am copying over my entire .env file and changing 4 lines,

DB_CONNECTION=mysql  
DB_HOST=127.0.0.1 <-this one to my ip  
DB_PORT=3306  
DB_DATABASE=homestead <- this one to "forge"  
DB_USERNAME=homestead <-this one to the name I got in teh e-mail (also "forge")  
DB_PASSWORD=secret <- this one to password I got in the email  

Is this correct?

alenabdula's avatar

In your deploy script on Forge make sure you remove migrate line if you're not using a database.

johngrotts's avatar

I am using a database (mysql) for my project, so I need it.

alenabdula's avatar

@johngrotts Go to site details >> enviroment on Forge and edit your environment file, see if it reflects what's in your .env file.

SaeedPrez's avatar

@johngrotts

Let this one be 127.0.0.1

DB_HOST=127.0.0.1

Also, I don't think Forge automatically creates a database for you. You need to do that manually.

In Forge, you can go to your server page, then MySQL tab, there you can create a database (and add users if you want to).

2 likes
johngrotts's avatar

@alenabdula I have edited the .env file (well, created it from scratch, since the initial is never created) but since the repository is never successfully installed, I can't check it on the server.

johngrotts's avatar

I still cannot install the repository. I did 127.0.0.1 with the database username and password that forge sent me, I created a database with a username and password and tried that with 127.0.0.1, but again it won't install, creating the same error. Any other things that I am forgetting/do not know about?

SaeedPrez's avatar

Access denied for user 'forge'@'localhost' (using password: NO)

Well, if you're getting the same error, the error is saying you're not using a password. What does your config/database.php look like? Have you made changes in it?

Should look like this (default L5.3)..

        '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,
        ],
johngrotts's avatar

Yep, that all looks the same in the database.php file. I have made no changes to it.

SaeedPrez's avatar

What happens if you try create a new username/password and use that in the env? Paste the error message here.

johngrotts's avatar

Same error:

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

I created a new user, went to the environment tab and typed in all of the information in the db section, clicked save, went back to the repository part, typed in the repository and clicked install, and I get the same thing. I guess the env section does nothing?

SaeedPrez's avatar

That is what I wanted to figure out.. it seems your .env file is not loading. Show your whole env file (remove app key, usernames and password values)

johngrotts's avatar

APP_ENV=local APP_KEY= APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=forge or the name of the database I made DB_USERNAME=any one of the 3 names I have (1 given by forge and 2 I created DB_PASSWORD=one of two (one given by forge, one created by me that I Applied to both created users BROADCAST_DRIVER=log CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379

MAIL_DRIVER=smtp MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null PUSHER_KEY= PUSHER_SECRET= PUSHER_APP_ID=

I have changed or added nothing else, so if there is no notes, it is like that in teh env file

SaeedPrez's avatar

Hm.. Make sure you don't have any white spaces around any =

// Good
ENV_FOO=something
ENV_BAR="Hello World"

// Bad
ENV_FOO = something
ENV_BAR=Hello World

Also you might also want to set APP_ENV=production

After you change set APP_ENV to production, you can SSH into the server and run php artisan env to see if it gives you correct environment or not. It could also be caused by wrong permission but I don't see how since it's a Forge deployment.

You could also try..

php artisan cache:clear
php artisan config:clear
johngrotts's avatar

I checked the file over for extra spaces, there are none (thank you for having me check that though, that would have been annoyingly funny if it had been something that simple).

Changing to production still does nothing new (same error)

php artisan does not work since laravel never gets installed, so I can't do any of the cache or config stuff.

SaeedPrez's avatar

php artisan does not work since laravel never gets installed, so I can't do any of the cache or config stuff.

@johngrotts I don't understand how that is possible? All Forge does is pull the git repository, run composer install and run migrations. Can you explain more in detail what you mean by laravel never gets installed?

johngrotts's avatar

Whenever I try to install my laravel project, it errors out. If go to the IP address, it's just the initial php info page. If I go into the shell, there's no composer, no laravel, no artisan, no nothing. It fails on the install of the repository.

SaeedPrez's avatar

If and when Forge fails to deploy your repository, it will show the error messages. Paste the complete error message here.

johngrotts's avatar
Cloning into 'default'...
Loading composer repositories with package information
Installing dependencies from lock file
  - Installing jakub-onderka/php-console-color (0.1)
    Loading from cache

  - Installing vlucas/phpdotenv (v2.3.0)
    Loading from cache

  - Installing symfony/polyfill-mbstring (v1.2.0)
    Loading from cache

  - Installing symfony/var-dumper (v3.0.9)
    Loading from cache

  - Installing symfony/translation (v3.0.9)
    Loading from cache

  - Installing symfony/routing (v3.0.9)
    Loading from cache

  - Installing symfony/process (v3.0.9)
    Loading from cache

  - Installing symfony/polyfill-util (v1.2.0)
    Loading from cache

  - Installing symfony/polyfill-php56 (v1.2.0)
    Loading from cache

  - Installing symfony/http-foundation (v3.0.9)
    Loading from cache

  - Installing symfony/event-dispatcher (v3.1.3)
    Loading from cache

  - Installing psr/log (1.0.0)
    Loading from cache

  - Installing symfony/debug (v3.0.9)
    Loading from cache

  - Installing symfony/http-kernel (v3.0.9)
    Loading from cache

  - Installing symfony/finder (v3.0.9)
    Loading from cache

  - Installing symfony/console (v3.0.9)
    Loading from cache

  - Installing swiftmailer/swiftmailer (v5.4.3)
    Loading from cache

  - Installing nikic/php-parser (v2.1.0)
    Loading from cache

  - Installing jakub-onderka/php-console-highlighter (v0.3.2)
    Loading from cache

  - Installing dnoegel/php-xdg-base-dir (0.1)
    Loading from cache

  - Installing psy/psysh (v0.7.2)
    Loading from cache

  - Installing paragonie/random_compat (v1.4.1)
    Loading from cache

  - Installing nesbot/carbon (1.21.0)
    Loading from cache

  - Installing mtdowling/cron-expression (v1.1.0)
    Loading from cache

  - Installing monolog/monolog (1.21.0)
    Loading from cache

  - Installing league/flysystem (1.0.25)
    Loading from cache

  - Installing jeremeamia/superclosure (2.2.0)
    Loading from cache

  - Installing doctrine/inflector (v1.1.0)
    Loading from cache

  - Installing classpreloader/classpreloader (3.0.0)
    Loading from cache

  - Installing laravel/framework (5.2.41)
    Loading from cache

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

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

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

When I log into the system using a shell, I cannot use composer at all. composer.phar does not appear in any folder I have found, and trying to run "composer", "php composer", "php composer.phar" does not work at all (all three commands have have worked in other places at some time).

SaeedPrez's avatar

@johngrotts

  • Are you using Digital Ocean?
  • Did you create a VPS with a fresh install of Ubuntu 16.04 x64?
  • What steps did you go through provisioning the server with Forge?

I'm running out of ideas, maybe someone with more server experience (ping @bashy) knows how to fix this?

johngrotts's avatar

I am using digitalocean, I created the VPS server through Forge, here's the steps:

  1. Go to https://forge.laravel.com/servers
  2. Make sure my credentials are there.
  3. Change the server size to the small one
  4. Keep the database name "forge"
  5. Click "Create Server"
  6. Wait til it's made.

That's all I do to make a server.

Once the server is made:

  1. Click "Sites" then select the server
  2. Click "Environment" tab
  3. Paste in the .env file (since it is currently blank) and change the things previously mentioned in this thread
  4. Click the "Apps" tab
  5. type in the address of my repository (username/repositoryname)
  6. Click "Install Repository"
  7. Get frustrated by seeing the same error I always get.
SaeedPrez's avatar

Hm.. I don't know,..

If you want, you can send me your login info and I can try set everything up for you from scratch on DO/Forge?

bashy's avatar

If it's requiring the DB on composer install, you probably have something that needs it before it's set the environment?

adamwathan's avatar
Level 6

When you install the repository, try keeping Install Composer dependencies unchecked.

Then SSH into the server, cd into the project directory, and run /usr/local/bin/composer install --no-scripts to try and get the dependencies installed without running any of the post-scripts that might interact with the Laravel app.

Hopefully that gets you one step closer and into a state that's easier to troubleshoot smaller more isolated problems.

Once it's installed that way, you can update your .env settings and try some of the earlier suggestions like checking php artisan env.

4 likes
johngrotts's avatar

Hey! It installed. It currently does not work, but my laravel project is now on the server, along with composer!

I did what @adamwathan (thank you!) suggested and unchecked "Install Composer Dependancies" This allowed the install process to go through! I ssh'd into the server, went to the proper folder, ran the command and it seemed to install composer without any bugs.

The error I am getting now says "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forge.permissions' doesn't exist (SQL: select * from permissions) "

I created the database when I created the server (I just left "forge" as the name since that is what it suggests), but it does not work. I checked the .env file, it is reading everything correctly (I only changed 127.0.0.1 in DB_HOST to "localhost"). I tried creating a new mysql database with a user, changed the .env file's 3 things (database, username and password), "Deployed", but that did not fix the problem (even with a mysql and server restart, using those options in the "Restart Services" drop down). I cannot run "php artisan" in ssh due to this error (I think, they are both giving the same error). Any ideas from here? I figure I would ask as well as do some more research.

To everyone who has helped me so far, a very sincere thank you for taking time out to assist me. I do appreciate it.

luisten's avatar

I don't know if this will help at all but I had the exact same problem. In my case, it's because when I created the database via the Forge interface I named it and the new user as "my-database". Because of SQL syntax, this was changed to "my_database".

... it took me hours to notice that.

1 like

Please or to participate in this conversation.