Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
11 posts Page 1 of 2
Hi all,

I have created a multiple environment config.php file for current version of CouchCMS. This configuration allows you to set up multiple server environment for your website without having to modify your config.php for each server instance.

You can download the file from my github page:
https://github.com/lesaff/couchcms-multi-env

Feel free to use, share, modify (send me a pull request). I would really appreciate any feedback.

A shout to KK, great product!, keep it up.

Enjoy,
Rudy
Welcome and thank you very much indeed Rudy :)
Great contribution. I am sure everyone would find it immensely useful.

Thanks again.
Hi Rudy, thank you for taking the time to code this and share it with the rest of us.

My next project requires this type of multiple-environment setup, so I might use your config file in combination with a git deployment script such as https://github.com/markomarkovic/simple-php-git-deploy. I don't anticipate requiring more than 2 environments. I wonder though if you have any advice or insights for managing multiple Couch environments that you can share. Thanks again!
Hi Cheesypoof,

It's great that you find the config useful.

My workflow on Couch as well as other CMS is pretty much like this:

Local Env:
- Server runs on MAMP (basically any stack will do as long as it somehow matches your production env)
- Set up git and add cache, .htaccess and anything you don't need to push to git repo to your .gitignore. It is also useful to include any uploaded files/folder in the list.

Staging Env:
- This depends on how you want to set up your staging server. You can do either "staging.domain.com" or "domain.com/website". The latter requires modification on your file path if you are embedding images through the editor.
- I use Beanstalk to deploy to staging automatically every time I made a commit. You can do a post-commit hook on your git server if you don't want to use Beanstalk

Production Env:
- Same as above, except that in Beanstalk, you set it to deploy manually since you really don't want anything automatic sent to your live server.

Database sync:
I use Sequel Pro (OSX) to sync databases between environment. It's basically just a simple export/import.

Any changes you do it locally, promote to staging for testing and deploy to production whenever they're ready.

You also want to sync the upload folder from the live server to your staging/local. This can be done using FTP or rsync.

I hope this helps.

Cheers
Rudy
That makes perfect sense; I think I will end up with a very similar workflow. Thanks again for the pointers Rudy.
This is awesome! Thanks, can't wait to try it.
Even Easier, just add the following to the config.php file with your hostname/website names and database setting. You can put as many case statements as you want:
Code: Select all
    $theServerWeAreOn = getenv('SERVER_NAME');    
    switch($theServerWeAreOn){

        case "webitename.com": //LIVE SERVER DATABASE SETTINGS           
            define( 'K_DB_NAME', '' );
            define( 'K_DB_USER', '' );
            define( 'K_DB_PASSWORD', '' );
            define( 'K_DB_HOST', '' );
            define( 'K_DB_TABLES_PREFIX', '' );
            break;

        case "ubuntu": //DEVELOPMENT DATABASE SETTINGS         
            define( 'K_DB_NAME', '' );
            define( 'K_DB_USER', '' );
            define( 'K_DB_PASSWORD', '' );
            define( 'K_DB_HOST', 'localhost' );
            define( 'K_DB_TABLES_PREFIX', '' );
            break;

        case "localhost": //DEVELOPMENT DATABASE SETTINGS         
            define( 'K_DB_NAME', '' );
            define( 'K_DB_USER', '' );
            define( 'K_DB_PASSWORD', '' );
            define( 'K_DB_HOST', 'localhost' );
            define( 'K_DB_TABLES_PREFIX', '' );
            break;

        default: //YOU NO PASS GO!!   
            die("You No Pass GO!");
    }
Does anyone still uses this trick? I have coded a different approach known as "convention over configuration".
I use via ddev (https://ddev.readthedocs.io/en/stable/) context variables. This looks like this.

docker-compose.couch.yaml
Code: Select all
version: '3.6'

services:
  web:
    environment:
      - COUCH_CONTEXT=Development


config.php
Code: Select all
// MySQL settings. You need to get this info from your web host.
if (getenv('COUCH_CONTEXT') === 'Development') {
    define('K_DB_NAME', 'db');
    define('K_DB_USER', 'db');
    define('K_DB_PASSWORD', 'db');
    define('K_DB_HOST', 'db');
} else {
    include("_db.php");
}
UPDATE 2022

Code that I use:
https://github.com/trendoman/Extended-KFunctions
https://github.com/trendoman/Extended-Configs

Motivation is to avoid "switches", because list can grow too fat.

I can have subfolders with separate couchcms installations, I can have subdomains with separate installations. And I like "default" looks of configs - where every setting is in place, without cut and paste. Code from all above posts gets messy quickly!

I chose to avoid "configuration" (with switches and environment variables) in favor of "convention" - it is when I agree to use certain facts to keep everything simple. Such certain facts are: domain and database name. Another certain fact for more complex cases with subfolders is location of "couch" folder.

/couch/addons/kfunctions.php is also configurable since my "development" addons are not required on production.
Since each installation (including those in subfolders) has its own database, it is easy to maintain versions named after database name and I always know which addons are loaded for installations.

Repo with code has both examples and explanation in comments.

Result: I do not need to edit or set up variables - only care to name files appropriately. Plus, I can see configs in explorer by file names, without need to open config and without reading/searching/scrolling to current envronment.
11 posts Page 1 of 2
cron