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

chern123's avatar

Laravel 5 & Forge Environmental Variables (PDO Exception)

I'm getting extremely frustrated with Laravel 5 deployment... Things seem to work fine if I install and follow the instructions according to the Forge tutorial on here.

However, due to my particular needs of running wordpress alongside my laravel project, I wanted to split up the site like this:

Place the laravel app under /home/default/app/

Place the wordpress installation under the default directory, or /home/default/

Therefore I manually SSH'd into the server, and cloned my directory into /home/default/app/

And I then updated the Laravel Forge deployment script to this:

cd /home/forge/default/app/
git pull origin master
composer install --no-interaction --no-dev --prefer-dist
php artisan migrate --force

This is the error I am receiving when trying auto-deploy:

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

I set the environmental variables in Forge. My .env file is not uploaded to the repository... (included in .gitignore)

Assuming that it were, here is my .env file (which I strongly believe is not on my server):

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_HOST=localhost
DB_DATABASE=scheduleify
DB_USERNAME=root
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

My database.php entries for the MYSQL server:

    'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST'),
            'database'  => env('DB_DATABASE'),
            'username'  => env('DB_USERNAME'),
            'password'  => env('DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

The Environmental Variable names in Forge:

DB_HOST
DB_USERNAME
DB_PASSWORD
DB_DATABASE

EDIT: Additional Information

Running the getenv command:

Current application environment: production

However, trying to get the environmental variables via php artisan tinker through SSH (is my syntax right?) reveals:

>>> env('DB_HOST');
=> null

Is there any way to diagnose what's wrong? Is there something I missed? Should I un-install the repository in Forge?

0 likes
3 replies
chern123's avatar
chern123
OP
Best Answer
Level 3

UPDATE: I was able to resolve it by using commands other than cp for moving the files around.. very odd. Seems like it may have interfered with some of the functionality of Forge?

For anyone who may run into issues with this in the future.. mv command is your friend, not only for moving files, but creating new directories.

1 like
KevinKirchner's avatar

Ha. I forgot to put the DB_USERNAME and DB_PASSWORD Forge sent me when they provisioned my server into said Environment tab. There's no exception now and deploy is working smoothly!

Please or to participate in this conversation.