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

vipin93's avatar

environment variable in laravel4.2

Recently I deploy my app on Heroku by following tutorial https://mattstauffer.co/blog/installing-a-laravel-app-on-heroku but when I try to making table or anything locally it saying

 {"error":{"type":"ErrorException","message":"Undefined index: host","file":"C:\\lamp\\www\\heraku\\app\\config\\database.php","line":69}}

I try to check my environment same error

databse setting in database.php

'pgsql' => array(
            'driver'   => 'pgsql',
            'host'     => parse_url(getenv("DATABASE_URL"))["host"],
            'database' => substr(parse_url(getenv("DATABASE_URL"))["path"], 1),
            'username' => parse_url(getenv("DATABASE_URL"))["user"],
            'password' => parse_url(getenv("DATABASE_URL"))["pass"],
            'charset'  => 'utf8',
            'prefix'   => '',
            'schema'   => 'public',
        ),
0 likes
8 replies
onbjerg's avatar

Is the DATABASE_URL set when you run heroku config? If not, you probably need to run heroku pg:promote HEROKU_POSTGRESQL_RED replacing red with whatever color your database has according to Heroku.

vipin93's avatar

I did it , and when I migrate my table "heroku run php /app/artisan migrate" Ican but problem is that when I try to do anything locally It not allow same error

onbjerg's avatar

Yes. This is because you need to create a file named .env in your project root, specifying the environment variables, including DATABASE_URL

This could look something like

APP_DEBUG=true
DATABASE_URL=your database url
onbjerg's avatar

Post some dumps of your environment files (of course with your passwords and such hidden)

vipin93's avatar

APP_ENV=local APP_DEBUG=true APP_KEY=secret

DATABASE_URL=something

onbjerg's avatar

Are these seperated by a new line? Also, please hide your passwords =)

Please or to participate in this conversation.