37 votes

Access environment information in template

In Craft 3 you can get the env using the getenv() function: {% set env = getenv('ENVIRONMENT') %} {% if env == 'dev' %} hello dev {% else %} hello world {% endif %} Or via the app’s config ...
  • 1,273
32 votes

Can I disable template caching for local development?

As of Craft 2.4, it is now possible to use the enableTemplateCaching config value. 'enableTemplateCaching' => false, Simply add that to your local environment in config/general.php, and it'll ...
  • 23.6k
26 votes
Accepted

Access environment information in template

When developing locally on Craft you would most likely have devMode => true set in your config file and set to false for your production config. app/config/general.php return array( 'mydevdomain....
  • 4,519
19 votes
Accepted

grab 'environmentVariables' with a tag

You can get to any of your config variables (including custom ones) like this: {{ craft.config.xyz }} The environmentVariables array is no different: {{ craft.config.environmentVariables.baseUrl }} ...
  • 7,248
13 votes
Accepted

Proper order of multi-environment config

In my experience, the order does matter. The array is read in order from top to bottom testing the domain for a match against each criteria (key). If there's a match, that array of settings is used ...
  • 2,583
9 votes
Accepted

How to set up multi-env in Craft 3 with .env files?

These are the two approaches I usually choose from: Option 1: the 'default' Craft 3 way Create a .env file for every environment you create, and add it to your .gitignore file (if it's not yet in it)...
  • 6,308
8 votes
Accepted

CSS is not loading on staging server

There are multiple ways to set the URLs to your files. I don't know if I got your folder structure right. But let's suppose that your web root is set to /var/www/craft-portfolio/public/, your CSS ...
  • 35.9k
7 votes
Accepted

Add localised tracking codes for production environments

If people don't need to change these through the control panel, I would put them in the general.php config file. Here's how I would do it: return array( '*' => array ( // default to not ...
7 votes

Access environment information in template

You can set a custom "environment label" variable inside config/general.php: return array( // ALL ENVIRONMENTS '*' => array( ), // LOCAL 'mysite.local' => array( '...
  • 1,075
6 votes
Accepted

Correct way to set up development and production environments for Craft?

I'd recommend you take a look at the excellent existing threads on this: Git Workflow and Multi Environment - how to approach What's the best practice for handling data migration and organization ...
  • 2,957
6 votes
Accepted

devMode, phpdotenv variable ignored

It looks like getenv returns a string (or false if the variable is not set, but it is in this case). So you need to cast the string to a boolean value to make it work. However, (bool)'false' gives ...
  • 35.9k
6 votes
Accepted

Is environmental routing possible?

The routes.php config file doesn't support multi-environment setups in the manner that general.php or db.php does – in other words, your example code using a multidimensional array would throw an ...
6 votes
Accepted

What are the best practices for the development setup?

That's the setup we use here. It's ok, but local development runs slowly because the database is off-site - we'll be moving to an internal database server in the new year because of that. Image ...
  • 3,084
5 votes

multi-environment config for {siteURL} not working

Multi-environment configs require you to create a '*' config array, even if it’s empty because there aren’t any config settings that you need to set globally. Simply having that '*' array is how Craft ...
5 votes

Can I disable template caching for local development?

I found this post and the answer by @carlcs helpful. However, I find the phrasing unless not in the cache logic a bit hard to wrap my head around. I want to note here an alternative to the syntax ...
  • 13.3k
5 votes
Accepted

Licensing a multi-lingual site using different domains

I got the official answer from Brandon, here is the summary for anyone that might be in a similar situation: I can do what I need with only one pro license the main portal (acme.com) will run the "...
5 votes
Accepted

Multi-Environment S3 Asset Paths

Unfortunately, this isn't currently possible. This feature request is very similar to what you're requesting... however, it would still require that all of your environments use the same type of ...
  • 23.6k
4 votes

Multi-environment configs and running sites on different ports

You can define CRAFT_ENVIRONMENT in your index.php like so: switch ($_SERVER['SERVER_PORT']) { case "8081": define('CRAFT_ENVIRONMENT', 'TRUNK'); break; case "8082": define('...
4 votes

Minimum database privileges for Craft front-end?

Short answer, no. You'll want to make sure that your DB user has all of the necessary privileges. Just because you're not entering your data into the database doesn't mean that Craft isn't writing ...
  • 23.6k
4 votes
Accepted

Covering both "www.domain.com" and "domain.com" in config file settings

What I like to do is explicitly set CRAFT_ENVIRONMENT in my index.php: switch($_SERVER['SERVER_NAME']) { case 'domain.dev': define('CRAFT_ENVIRONMENT', 'LOCAL'); break; case 'staging....
4 votes
Accepted

Multi-Env Craft Setup sharing DB

I wouldn't do it, personally. Especially if your plugin interacts with the database and you'll be creating/deleting tables, altering the schema, needing to restore the database, etc. Too much risk ...
  • 66.5k
4 votes

Can't remove index.php from my URLs

These are the settings I have in place for config.php and .htaccess file.
  • 2,455
4 votes
Accepted

Using an IP address in config/db.php

The short answer is yes — you need to use a domain names. You might also want to have a look at this multi-environment configuration method defined on the craft cookbook website that creates a global ...
4 votes
Accepted

Separated DB for each locale in subdomain with no shared Craft installation

Generally speaking, locales are designed to share the same templates, so craft is not necessarily looking for a /template/[locale]/ folder to find the correct templates to load. You may have to ...
4 votes
Accepted

Plugin Multi-Environment config not working

The issue is that you're putting the multi-environment config code in your plugins/pluginHandle/config.php file, which is just meant to supply default plugin config values. Users can set custom ...
  • 66.5k
4 votes

Linking a page in a multilanguage website

You could write a Twig macro to get the localized URL from an entry ID. Import it from _layout.html for example. {% macro urlFromId(entryId) %} {%- set entry = craft.entries.id(entryId).first() %}...
  • 35.9k
4 votes
Accepted

Why is Craft extremely slow when using a shared, external database?

My suggestion would be to do what is outlined in Database & Asset Syncing Between Environments in Craft CMS It's a little bit of logistical organization coupled with some scripts to do the asset/...
  • 11.1k
4 votes

What are the best practices for the development setup?

Matt Wilcox alluded to it in his original comment, but something like Craft-Scripts will really help out with this workflow. You can read more here: Database & Asset Syncing Between Environments ...
  • 11.1k
4 votes
Accepted

Does "preprod" count as a dev sounding sub-domain?

No, it doesn't match anything on the list: UPDATE After filing this request, the documentation has been improved to more clearly state that this is, in fact, an exhaustive list. I have update the ...
  • 23.6k
3 votes

Compress Craft Control Panel CSS and JS per environment

I don't think there's anything built into Craft. What I do is {% if craft.config.devMode %} <link rel="stylesheet" href="{{craft.config.environmentVariables['assetURL']}}css/style.css"> {% ...

Only top scored, non community-wiki answers of a minimum length are eligible