Skip to content

Instantly share code, notes, and snippets.

@TiuTalk
Last active May 19, 2021 23:59
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save TiuTalk/dd18b2797f9bbddce8dc to your computer and use it in GitHub Desktop.
Save TiuTalk/dd18b2797f9bbddce8dc to your computer and use it in GitHub Desktop.
CakePHP on Heroku

CakePHP via composer

composer.json

{
  "name": "assando-sites",
  "require": {
    "cakephp/cakephp": ">=2.5.0",
    "ext-apcu": "*",
    "ext-imagick": "*",
    "ext-memcached": "*"
  },
  "config": {
    "vendor-dir": "Vendor/"
  }
}

webroot/index.php

<?php
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . APP_DIR . "/Vendor/cakephp/cakephp/lib");

Config/bootstrap.php

<?php
// Load Composer autoload.
require APP . '/Vendor/autoload.php';

// Remove and re-prepend CakePHP's autoloader as Composer thinks it is the
// most important.
// See: http://goo.gl/kKVJO7
spl_autoload_unregister(array('App', 'load'));
spl_autoload_register(array('App', 'load'), true, true);

.gitignore

tmp/*
app/tmp/*
!empty
Vendor

CakePHP on Heroku

config/nginx.conf

location / {
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    rewrite ^(.*)$ /index.php last;
}

location ~ ^/index.php$ {
    fastcgi_pass heroku-fcgi;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
}

Procfile

web: Vendor/bin/heroku-php-nginx -C Config/nginx.conf webroot

Config/database.php

<?php
class DATABASE_CONFIG {

	public $default;

	public $test = array(
		'datasource' => 'Database/Mysql',
		'persistent' => false,
		'host' => 'localhost',
		'login' => 'user',
		'password' => 'password',
		'database' => 'test_database_name',
		'prefix' => '',
		//'encoding' => 'utf8',
	);

	public function __construct() {
    $DATABASE_URL = parse_url($_ENV['DATABASE_URL']);
    $this->default = array(
      'datasource' => 'Database/Postgres',
      'persistent' => false,
      'host'       => $DATABASE_URL['host'],
      'login'      => $DATABASE_URL['user'],
      'password'   => $DATABASE_URL['pass'],
      'database'   => substr($DATABASE_URL['path'], 1),
      'prefix'     => '',
      'encoding'   => 'utf8',
    );
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment