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 ...
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 ...
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....
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 ...
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 }}
...
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 ...
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 ...
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 ...
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 ...
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)...
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 ...
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(
'...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
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 ...
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/',
),
);
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 ...
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 ...
4
votes
Can't remove index.php from my URLs
These are the settings I have in place for config.php and .htaccess file.
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
multi-environment × 102config × 24
database × 14
multi-domain × 13
localization × 12
environmentvariables × 10
assets × 9
multi-site × 8
craft3 × 7
templating × 4
server × 4
s3 × 4
license × 4
environments × 4
url × 3
language × 3
siteurl × 3
subdomain × 3
plugin-development × 2
control-panel × 2
image-transforms × 2
mysql × 2
performance × 2
security × 2
configuration × 2