2022 Developer Survey is open! Take survey.
36 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 ...
user avatar
  • 1,263
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 ...
user avatar
  • 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....
user avatar
  • 4,509
25 votes
Accepted

Git Workflow and Multi Environment - how to approach

Matt has a point, this is similar to What's the best practice for handling data migration and organization across development environments?, but that question focuses mainly on how to handle the ...
user avatar
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 }} ...
user avatar
  • 7,228
18 votes
Accepted

Can I disable template caching for local development?

When working with multiple environments you most likely want to disable caching for all but one environment, because Craft saves the absolute URL to entries/assets in the cache. I achieved this by ...
user avatar
  • 35.8k
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 ...
user avatar
  • 2,563
12 votes

How can I use multi-environment configuration to set each root URL?

Make sure to change the "Site URL" setting to {siteUrl} in your control panel settings... Control Panel > Settings > General > "Site URL" Within your config file, you'll also want to put your ...
user avatar
  • 23.6k
10 votes
Accepted

Export database from control panel or Sequel Pro? What's the difference?

The difference in both size and speed is likely because Sequel Pro (and any other MySQL client) is likely using mysqldump, which is a native CLI command and highly optimized. Craft can't rely on ...
user avatar
  • 66.4k
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)...
user avatar
  • 6,288
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 ...
user avatar
  • 35.8k
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( '...
user avatar
  • 1,075
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 ...
user avatar
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 ...
user avatar
  • 2,947
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 ...
user avatar
  • 35.8k
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 ...
user avatar
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 ...
user avatar
  • 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 ...
user avatar
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 ...
user avatar
  • 13.2k
5 votes
Accepted

Config option to disable update capability per environment

I believe you're looking for the 'allowAutoUpdates' config option combined with multi-environment configs.
user avatar
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 "...
user avatar
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 ...
user avatar
  • 23.6k
4 votes
Accepted

Template error: Method "siteUrl" for object "Craft\ConfigVariable" does not exist

Did you configure siteUrl in general.php? return array( // ... 'siteUrl' => array( 'en' => 'http://example.com/en/', 'de' => 'http://example.com/de/', ), );
user avatar
  • 35.8k
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('...
user avatar
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 ...
user avatar
  • 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....
user avatar
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 ...
user avatar
  • 66.4k
4 votes

Can't remove index.php from my URLs

These are the settings I have in place for config.php and .htaccess file.
user avatar
  • 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 ...
user avatar
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 ...
user avatar

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