40 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 ...
kr37's user avatar
  • 1,355
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)...
Paul's user avatar
  • 6,338
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 ...
carlcs's user avatar
  • 36.2k
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 ...
Mats Mikkel Rummelhoff's 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 ...
Matt Wilcox's user avatar
  • 3,199
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 ...
Lindsey D's user avatar
  • 24k
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() %}...
carlcs's user avatar
  • 36.2k
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/...
andrew.welch's user avatar
  • 11.6k
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 ...
andrew.welch's user avatar
  • 11.6k
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 ...
Lindsey D's user avatar
  • 24k
3 votes
Accepted

Can entries be disabled by default for 2/3 of the languages on my website

Is it possible to have the Japanese and English version disabled by default? Yes. Visit Settings -> Sections -> [Your Section Name] inside the Control Panel. Under the heading Which locales should ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Multiple localhost config settings

Here's a multi environment config guide that I think will accomplish all you need. It allows for environment specific DB connection parameters, but can also set filepaths, that why you can keep your ...
mrsmn's user avatar
  • 731
3 votes
Accepted

multi-domain setup: template entry.url includes index.php

OMG I'm so angry at myself! Not 'omitScriptNameInUrls' => 'true', but 'omitScriptNameInUrls' => true,
Amanda Lutz's user avatar
3 votes
Accepted

How do I configure multiple environments for console commands?

Alternatively, you could write your own yiic shell wrapper for each environment that defined CRAFT_ENVIRONMENT. Something like yiicstaging: #!/usr/bin/env php <?php define('CRAFT_ENVIRONMENT', '...
Brad Bell's user avatar
  • 67.4k
3 votes
Accepted

Can multi-environment configuration be used in 'index.php'?

Should be able to. Use a switch statement to check on the host and then server up the correct environment configuration like so: public/index.php: switch (strtolower($_SERVER['SERVER_NAME'])) { /...
Ian Young's user avatar
  • 584
3 votes

Staging Server Database Not Connecting

It looks as if you've sorted thing out (dev.nec... vs nec.dev...) In general, I find the domain name matching in the config files to be confusing and error prone. I always follow the advice in the ...
Marion Newlevant's user avatar
3 votes

Access environment information in template

I know this is an old question, but just an update: If you're on Craft CMS v3+, craft.config.[setting-name] has been deprecated. Use craft.app.config.general.[setting-name] instead. So if you wanted ...
Mage's user avatar
  • 31
3 votes

What is the most adviceable way to combine a staging and live database?

The way we do it is we take a copy of the live database when we begin development work, do the dev work on local/stage, get sign off... then manually add the new fields etc onto the live database. ...
Matt Wilcox's user avatar
  • 3,199
3 votes
Accepted

Craft 3: Environment variables are not parsed when used in Assets source field

Environmental variables as such don't exist "as a thing" in Craft 3. Instead, you'd define your Volumes in the AdminCP and override anything you need in craft/config/volumes.php You can see an ...
andrew.welch's user avatar
  • 11.6k
3 votes

phpdotenv with multi-lang Craft setup on MAMP

Some troubleshooting steps: Make sure a vendor/ folder exists two levels up from es/. If not, you need to run composer install in your terminal from the directory that contains a composer.json file. (...
Brandon Kelly's user avatar
3 votes

phpdotenv with multi-lang Craft setup on MAMP

My current setup for multilingual sites: as Brandon said, make sure there is a vendor/ folder at project root level (there should be one in this case otherwise the site wouldn't run). extract the ...
Jérôme Coupé's user avatar
3 votes

Staging / Production w/ common DB and Assets

Database I strongly discourage you from letting Staging and Production share a database. That is a recipe for disaster. Your Staging site should be semi-disposable, and it's likely that your client ...
Lindsey D's user avatar
  • 24k
3 votes
Accepted

Less complicated local development w/Craft 3, is it possible?

If you're used to Local you can also use that for Craft. Here's 2 articles to get you started: https://medium.com/@madebyraygun/a-quick-and-easy-local-environment-for-craft-3-4fd7c7ff5815 and ...
erwinheiser's user avatar
3 votes
Accepted

Enironment Variable being rendered literal

You can't append anything to the value if you use environment variables. You need to use aliases for this. In you config/general.php, add this: '*' => [ 'aliases' => [ 'assetBasePath'...
nstCactus's user avatar
  • 1,149
2 votes

Moved from local to remote "Service Unavailable Our site is temporarily unavailable. Please try again later."

I recently ran into this issue as well for a site with multiple locales using a multi-environment configuration. The issue turned out to be that the secondary locales did not have a multi-environment ...
Ben Parizek's user avatar
  • 13.4k
2 votes

Multilingual MAMP port number siteUrl issue

Pretty sure the issue is that a port number won't work as part of the key in a multi-environment config. Because unless you explicitly set CRAFT_ENVIRONMENT to use it, Craft is just going to use $...
Brad Bell's user avatar
  • 67.4k
2 votes

multi environment nginx, how to check $_SERVER['SERVER_NAME']

$_SERVER['SERVER_NAME'] is a global server variable (not a craft variable) and should be available. I don't use nginx, so I can't comment on where the $_SERVER['SERVER_NAME'] comes from exactly — but ...
Douglas McDonald's user avatar
2 votes
Accepted

Possible to share assets, templates and plugins across two domains but not all content?

As long as your sites are hosted on the same server, you can easily share templates and plugins between them by defining the appropriate path constants in the index.php files for your sites: define('...
Mats Mikkel Rummelhoff's user avatar
2 votes

Multi-Environment S3 Asset Paths

We created a plugin to help solve this problem: https://github.com/Firstborn/Craft-CMS-Environment-Settings This plugin allows you to specify different configurations per environment on a single ...
Ziad Hilal's user avatar
2 votes
Accepted

Using Symbolic Links for Very Large Image directories

Am I missing something or is there a better/easier/default way to do handle large numbers of images/assets across DEV & LIVE environments when they are on the same server/account? Ideally you'd ...
Brad Bell's user avatar
  • 67.4k

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