Deploy ContentBox on an existing ColdBox application.
If you already have a ColdBox application and wish to install ContentBox, you most definitely can.
System Requirements
Please note that ContentBox requires ColdBox 7.x
Step 1: Dependencies
Since version 3.5.0, you can now issue a command in CommandBox to install the ContentBox module into an existing ColdBox application. Just open a box shell in the root of your ColdBox application and use the following command:
install contentbox,contentbox-installer-module
This will install the ContentBox module with all of its dependencies under the /modules/contentbox and the ContentBox installer module under /modules/contentbox-installer.
Now open your Application.cfc and you will add the following updates:
Mappings
// UTC timezonethis.timezone ="UTC";// LOCATION MAPPINGSthis.mappings[ "/contentbox" ] =COLDBOX_APP_ROOT_PATH&"modules/contentbox";// THE LOCATION OF THE ORM MODULEthis.mappings[ "/cborm" ] =this.mappings[ "/contentbox" ] &"/modules/contentbox-deps/modules/cborm";
ORM Settings
/** * -------------------------------------------------------------------------- * ORM + Datasource Settings * -------------------------------------------------------------------------- * - Please update the cfcLocation as needed to locate more ORM entities for your app * - Dialect is incredibly important! Do not let Hibernate auto configur it, you can get nasty errors. * So Make sure you select one. */request.cbSystemHelper =newcoldbox.system.core.delegates.Env();// THE CONTENTBOX DATASOURCE NAMEthis.datasource ="contentbox";// ORM SETTINGSthis.ormEnabled =true;// cfformat-ignore-startthis.ormSettings = {// ENTITY LOCATIONS, ADD MORE LOCATIONS AS YOU SEE FIT cfclocation : [// If you create your own app entities"models",// The ContentBox Core Entities"modules/contentbox/models",// Custom Module Entities"modules_app",// Custom Module User Entities"modules/contentbox/modules_user" ],// THE DIALECT OF YOUR DATABASE OR LET HIBERNATE FIGURE IT OUT, UP TO YOU TO CONFIGURE. dialect :request.cbSystemHelper.getSystemSetting( "ORM_DIALECT","" ), dbcreate :"none", secondarycacheenabled:request.cbSystemHelper.getSystemSetting( "ORM_SECONDARY_CACHE",false ), cacheprovider :request.cbSystemHelper.getSystemSetting( "ORM_SECONDARY_CACHE","ehCache" ), logSQL :request.cbSystemHelper.getSystemSetting( "ORM_LOGSQL",false ), sqlScript :request.cbSystemHelper.getSystemSetting( "ORM_SQL_SCRIPT","" ),// ORM SESSION MANAGEMENT SETTINGS, DO NOT CHANGE flushAtRequestEnd :false, autoManageSession :false,// ORM EVENTS MUST BE TURNED ON FOR CONTENTBOX TO WORK DO NOT CHANGE eventHandling :true, eventHandler :"cborm.models.EventHandler",// THIS IS ADDED SO OTHER CFML ENGINES CAN WORK WITH CONTENTBOX skipCFCWithError :true,// TURN ON FOR Debugging if ORM mappings are not working. savemapping :false};// cfformat-ignore-end
Step 3: .env Settings
Below are the env settings for ContentBox to run, spice up as needed
################################################################## App Name and Environment#################################################################APPNAME=ContentBoxDev# This can be development, staging, production or custom.ENVIRONMENT=development# The password for the CFML Engine AdministratorCFCONFIG_ADMINPASSWORD=contentbox# The ColdBox Reinit passwordCOLDBOX_REINITPASSWORD=contentbox# How long do admin sessions last (In Minutes)COLDBOX_SESSION_TIMEOUT=60# Development CBDebuggerCBDEBUGGER_ENABLED=true################################################################## ContentBox ORM Settings# --------------------------------# This is used to configure the ORM via env settings usually for# different RDBMS settings or options################################################################## Dialect choices:# MySQL, Hypersonic => org.hibernate.dialect.MySQL5InnoDBDialect,# PostgreSQL => PostgreSQL# Microsoft SQL => org.hibernate.dialect.SQLServer2008Dialect# Oracle => Oracle10g# Derby => DerbyORM_DIALECT=org.hibernate.dialect.MySQL5InnoDBDialect# Log sql to the console or notORM_LOGSQL=false# Sql Script to execute after ORM is initializedORM_SQL_SCRIPT=# Activate secondary cache or disable itORM_SECONDARY_CACHE=falseORM_SECONDARY_CACHE_PROVIDER=ehcache################################################################## ContentBox Datsource and Migrations Variables# ----------------------------------------------------------------# These settings configure the datasource connection to your database# Please make sure you read the comments as there are differences# between Adobe and Lucee. Uncomment your rdbms of choice, the options are:# - MySQL 5.7# - MySQL 5.8# - PostgreSQL# - Microsoft SQL# - Custom Database######################################################################################################################## Database Datasource Connection######################################################DB_DRIVER=MySQLDB_CLASS=com.mysql.cj.jdbc.DriverDB_BUNDLEVERSION=8.0.24DB_BUNDLENAME=com.mysql.cj# DB LocationDB_HOST=localhostDB_PORT=3306DB_CONNECTIONSTRING=jdbc:mysql://localhost:3306/contentbox?allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useLegacyDatetimeCode=true
# DB CredentialsDB_DATABASE=contentboxDB_USER=rootDB_PASSWORD=ortussolutions################################################################## JWT Information# --------------------------------# You can seed the JWT secret below or you can also leave it empty# and ContentBox will auto-generate one for you that rotates# everytime the application restarts or expires#################################################################JWT_SECRET=YQSUGww+IQQUhOfZxVhFnDMNtN0fV1uH8hEvMTt+Nao=################################################################## AWS S3 or Digital Ocean Spaces# --------------------------------# If you are using any of our S3/Spaces compatible storages, you# will have to seed your credentials and information below#################################################################S3_ACCESS_KEY=S3_SECRET_KEY=S3_REGION=us-east-1S3_DOMAIN=amazonaws.comS3_BUCKET=
Open your CacheBox configuration file: config/CacheBox.cfc and add the following cache declarations:
// Register all the custom named caches you like herecaches = {// Named cache for all coldbox event and view template caching template = { provider ="coldbox.system.cache.providers.CacheBoxColdBoxProvider", properties = { objectDefaultTimeout =120, objectDefaultLastAccessTimeout =30, useLastAccessTimeouts =true, freeMemoryPercentageThreshold =0, reapFrequency =2, evictionPolicy ="LRU", evictCount =5, maxObjects =5000, objectStore ="ConcurrentSoftReferenceStore"//memory sensitive } },// ContentBox Sessions sessions = { provider ="coldbox.system.cache.providers.CacheBoxColdBoxProvider", properties = { objectDefaultTimeout =60, objectDefaultLastAccessTimeout =0, useLastAccessTimeouts =false, freeMemoryPercentageThreshold =0, reapFrequency =2, evictionPolicy ="LRU", evictCount =5, maxObjects =1000,// Can support up to 1000 user sessions concurrently. Modify if needed. 0 = unlimited objectStore ="ConcurrentStore" } }}
Once these updates are done, then you can start up the server and visit the installer URL: http://localhost:port/cbInstaller
Step 6 (Optional) : UI Route
By default ContentBox is in take over mode. Meaning that the UI module will intercept all calls made to the application and process them as pages or blog entries. If you DO NOT want this to happen, then you can segregate the UI module into a single entry point URL like blog or site or pages. You can do this by opening the following file: modules/contentbox-ui/ModuleConfig.cfc and looking for the following code:
// YOUR SES URL ENTRY POINT FOR CONTENTBOX, IF EMPTY IT WILL TAKE OVER THE ENTIRE APPLICATION
// IF YOU WANT TO SECTION OFF CONTENTBOX THEN FILL OUT AN SES ENTRY POINT LIKE /site OR /content
// BY DEFAULT IT TAKES OVER THE ENTIRE APPLICATION
this.entryPoint = "";
Now update the this.entryPoint to whatever you like the entry point URL to be. Restart the application and voila!