7

Is it possible to configure the base-url (secure & unsecure) within the array-based configuration files like env.php or config.php?

I tried with env.php but it didn't give me much:

<?php
return array (
    'web' => [
        'unsecure' => ['base_url' => 'test'],
        'secure' => ['base_url' => 'test'],
    ],
    ...

But it might just be that I'm overlooking something.

It however works nicely when I use the core config table, e.g. setting it with magerun2:

$ n98-magerun2.phar config:set web/secure/base_url https://example.com
web/secure/base_url => https://example.com
$ n98-magerun2.phar config:set web/unsecure/base_url http://example.com
web/unsecure/base_url => http://example.com

3 Answers 3

7

Yes, you can do that from Magento 2.2 in following way. Put this code in env.php file

<?php
return [
    'system' => [
        'default' => [
            'system' => [
                'smtp' => [
                    'host' => 'localhost',
                    'port' => '25'
                ]
            ],
            'web' => [
                'unsecure' => [
                    'base_url' => 'http://test/',
                    'base_link_url' => '{{unsecure_base_url}}'
                ],
                'secure' => [
                    'base_url' => 'https://test/',
                    'base_link_url' => '{{secure_base_url}}'
                ],
                'default' => [
                    'front' => 'cms'
                ],
                'cookie' => [
                    'cookie_domain' => 'test'
                ]
            ],
        ],
    ],

    ...

This is for default scope solution, but you can define scope in same way as discrabed on https://devdocs.magento.com/guides/v2.2/config-guide/prod/config-reference-var-name.html section Find a website or store view scope in the database

1
2

You cannot, since in Magento you can config multiple stores, and since these are store specific configs, you cannot store them in env.php. config.php is only for module related info.

It is also the reason there are 2 commands :

bin/magento setup:store-config:set

for store related config, which is stored in the database, and

bin/magento setup:config:set

which sets environment configs in env.php

2
  • Is there no way to add store-specific settings files, containing the base-url for a specific store?
    – Andrea
    May 11, 2016 at 10:48
  • No @Andrea it can only be store in the DB.
    – Maddy
    May 11, 2016 at 14:57
1

One way to set configuration per store, is to set environment variables: http://devdocs.magento.com/guides/v2.2/config-guide/prod/config-reference-var-name.html

I have tried and could not get them working so far. The variables I set showed up when I put phpinfo();die(); at the top of index.php, so I'm not sure why they were not used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.