Skip to content
This repository has been archived by the owner on Mar 11, 2018. It is now read-only.

Run using PHP internal server and remote DB? #102

Open
OKNoah opened this issue Jun 12, 2015 · 1 comment
Open

Run using PHP internal server and remote DB? #102

OKNoah opened this issue Jun 12, 2015 · 1 comment

Comments

@OKNoah
Copy link

OKNoah commented Jun 12, 2015

Is it possible to run this using foreman, thus using the environmental variables, and the DATABASE_URL variable locally? When I try this, I get the error Error establishing a database connection.

Here is how I'm doing it.

In my Procfile_dev file

web: php -S 127.0.0.1:80 -t ./

In my .env file:

AUTH_KEY=[ VALUE HERE ]
SECURE_AUTH_KEY=[ VALUE HERE ]
LOGGED_IN_KEY=[ VALUE HERE ]
NONCE_KEY=[ VALUE HERE ]
AUTH_SALT=[ VALUE HERE ]
SECURE_AUTH_SALT=[ VALUE HERE ]
LOGGED_IN_SALT=[ VALUE HERE ]
NONCE_SALT=[ VALUE HERE ]
DATABASE_URL=[ VALUE HERE ]
HEROKU_POSTGRESQL_BLUE_URL=[ VALUE HERE ]
AWS_ACCESS_KEY_ID=[ VALUE HERE ]
AWS_SECRET_ACCESS_KEY=[ VALUE HERE ]
SENDGRID_PASSWORD=[ VALUE HERE ]
SENDGRID_USERNAME=[ VALUE HERE ]

Then I run:

sudo foreman start -f Procfile_dev --env .env

I'm on OS X Yosemite using PHP 5.5 though Homebrew, with the php55-pdo-pgsql package installed.

@OKNoah
Copy link
Author

OKNoah commented Jun 12, 2015

I fixed this by changing part of wp-config.php. Originally (line 18):

// ** Heroku Postgres settings - from Heroku Environment ** //
$db = parse_url( $_ENV["DATABASE_URL"] );

Fix:

// ** Heroku Postgres settings - from Heroku Environment ** //
$db = parse_url( getenv("DATABASE_URL") );

Is there a reason all the other environment variables use getenv() but the database uses $_ENV?

Side note: I also added two more environment variables to the app and put the in wp-config.php like this,

define('WP_HOME',               getenv('WP_HOME'));
define('WP_SITEURL',            getenv('WP_SITEURL'));

These are then set to http://localhost/ in my .env file, and to my sites live domain on Heroku. This prevents Wordpress from redirecting to whatever URL values are in the database.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant