Step 1 create the app:
(source: https://devcenter.heroku.com/articles/cedar)-
in the directory containing the CakePHP app run
heroku create
output: http://quiet-sky-6888.herokuapp.com/ | git@heroku.com:quiet-sky-6888.git -
Add the repository as a remote
git remote add heroku git@heroku.com:quiet-sky-6888.git
*Make sure you use the repo in your output, not mine.
Step 2 add the database:
(source: https://devcenter.heroku.com/articles/heroku-postgresql)-
Run
heroku addons:add heroku-postgresql:dev
output: Attached as HEROKU_POSTGRESQL_RED_URL -
Run
heroku pg:promote HEROKU_POSTGRESQL_RED_URL
* Make sure you use the name from your output, not mine. -
Get your new DB credentials
heroku pg:credentials DATABASE
output: dbname=dee932clc3mg8h host=ec2-123-73-145-214.compute-1.amazonaws.com port=6212 user=user3121 password=98kd8a9 sslmode=require
Step 3 setup environment vars:
Using the credentials from when you ran the last step, run:heroku config:add DB_NAME=dee932clc3mg8hheroku config:add DB_HOST=ec2-123-73-145-214.compute-1.amazonaws.comheroku config:add DB_USER=user3121heroku config:add DB_PASS=98kd8a9
While we are at it, setup security salt and cipher vars also:
-
heroku config:add SECURITY_SALT=ffdsdsgdfgdfgfdghgfdhfghfgdhUse a random string -
heroku config:add CIPHER_SEED=32432847328472389473Use random digits
Step 4 write some code:
Open up the file app/Config/core.php and edit the security salt and cypher string to:
Configure::write('Security.salt', getenv('SECURITY_SALT'));
Configure::write('Security.cipherSeed', getenv('CIPHER_SEED'));
Rename the file app/Config/database.php.default to app/Config/database.php
Open up the new file app/Config/database.php and edit the database config to:
class DATABASE_CONFIG {
public $default;
function __construct() {
$this->default = array(
'datasource' => 'Database/Postgres',
'persistent' => false,
'host' => getenv('DB_HOST'),
'login' => getenv('DB_USER'),
'password' => getenv('DB_PASS'),
'database' => getenv('DB_NAME'),
'prefix' => '',
'encoding' => 'utf8',
);
}
}
You have to set the $default array in the __construct function instead of the usual way in order to be able to use the getenv methods.
You will need to force add app/Config/database.php to the repo since it is ignored:
-
Run
git add app/Config/database.php -f
Once you have all these changes done and commited push them to heroku
- Run
git push heroku master - Now visit your site:
heroku open
You should be greeted with a vanilla CakePHP app with all green statuses telling you that Cake is able to connect to the database. Your page should look like the example in the top of this article. You are all setup for Heroku, now all you need to do is build your app.
If you have problems with step 4 you can fork my repo with that part already setup for you.
4 Comments
Leave A Comment