How to setup stores and website using config.php file Magento 2?

config.php file in Magento contains the list of installed modules, Website, Store related setup, Locales, and system configuration settings.

You can see the config.php file location at the given path, app/etc/config.php

I will just highlight the Scopes section of the config file.

There will be different sections to be used within the config.php file.h

1. modules (Out of the box modules section contains the List of Modules available.)
2. scopes (This section contains the stores, store groups, and websites related information.)
3. system (This section is used to set system configuration value.)
4. themes (This section is used to setup themes related information.)

modules section:

All the modules are available with the system. Module with 0(Disabled) or 1(Enabled) value indicates Enabled/Disabled module.

'modules' => [
        'Magento_Store' => 1,
        'Magento_AdminAnalytics' => 1,
        'Magento_AdminNotification' => 1,
        'Magento_AdminGwsConfigurableProduct' => 1,
        'Magento_AdminGwsStaging' => 1,
        'Magento_Directory' => 1,
        .....
]

scopes section:

The scopes section contains the websites, and groups and stores related information as a child array.
You can see multiple websites (admin, base, and us_site), multiple stores (default, base, and us_site_store), and multiple store views (admin, default, and us_site) setup with the scopes section in the config.php file.

'scopes' => [
        'websites' => [
            'admin' => [
                'website_id' => '0',
                'code' => 'admin',
                'name' => 'Admin',
                'sort_order' => '0',
                'default_group_id' => '0',
                'is_default' => '0'
            ],
            'base' => [
                'website_id' => '1',
                'code' => 'base',
                'name' => 'Main Website',
                'sort_order' => '0',
                'default_group_id' => '1',
                'is_default' => '1'
            ],
            'us_site' => [
                'website_id' => '2',
                'code' => 'us_site',
                'name' => 'USA Website',
                'sort_order' => '0',
                'default_group_id' => '2',
                'is_default' => '0'
            ]
        ],
        'groups' => [
            [
                'group_id' => '0',
                'website_id' => '0',
                'code' => 'default',
                'name' => 'Default',
                'root_category_id' => '0',
                'default_store_id' => '0'
            ],
            [
                'group_id' => '1',
                'website_id' => '1',
                'code' => 'base',
                'name' => 'Main Website Store',
                'root_category_id' => '2',
                'default_store_id' => '1'
            ],
            [
                'group_id' => '2',
                'website_id' => '2',
                'code' => 'us_site_store',
                'name' => 'US Website Store',
                'root_category_id' => '42',
                'default_store_id' => '2'
            ]
        ],
        'stores' => [
            'admin' => [
                'store_id' => '0',
                'code' => 'admin',
                'website_id' => '0',
                'group_id' => '0',
                'name' => 'Admin',
                'sort_order' => '0',
                'is_active' => '1'
            ],
            'default' => [
                'store_id' => '1',
                'code' => 'default',
                'website_id' => '1',
                'group_id' => '1',
                'name' => 'Default Store View',
                'sort_order' => '0',
                'is_active' => '1'
            ],
            'us_site' => [
                'store_id' => '2',
                'code' => 'us_site',
                'website_id' => '2',
                'group_id' => '2',
                'name' => 'US Store View',
                'sort_order' => '0',
                'is_active' => '1'
            ]
    ]
]

system section:

The system contains the store configuration values. You can set any System Configuration values in the given section.

You can set up system configuration value by website level also using the 'websites' => [ 'website_code' => [ 'key' => 'value'] ]

'system' => [
    'default' => [
        'customer' => [
                'account_share' => [
                    'scope' => 1
                ]
            ],
            'twofactorauth' => [
                'general' => [
                    'enable' => '0'
                ]
            ],
            'system' => [
                'security' => [
                    'max_session_size_admin' => '0'
                ]
            ]
    ],
    'websites' => [
        'us_site' => [
            'design' => [
                    'theme' => [
                        'theme_id' => 'frontend/Rbj/us_site'
                    ]
                ],
        ]
    ]
]

themes section:

Contains the theme’s configuration value.

Two New themes setup using Rbj/default and Rbj/us_site

'themes' => [
        'frontend/Magento/blank' => [
            'parent_id' => null,
            'theme_path' => 'Magento/blank',
            'theme_title' => 'Magento Blank',
            'is_featured' => '0',
            'area' => 'frontend',
            'type' => '0',
            'code' => 'Magento/blank'
        ],
        'frontend/Magento/luma' => [
            'parent_id' => 'Magento/blank',
            'theme_path' => 'Magento/luma',
            'theme_title' => 'Magento Luma',
            'is_featured' => '0',
            'area' => 'frontend',
            'type' => '0',
            'code' => 'Magento/luma'
        ],
        'adminhtml/Magento/backend' => [
            'parent_id' => null,
            'theme_path' => 'Magento/backend',
            'theme_title' => 'Magento 2 backend',
            'is_featured' => '0',
            'area' => 'adminhtml',
            'type' => '0',
            'code' => 'Magento/backend'
        ],
        'frontend/Rbj/default' => [
            'parent_id' => 'Magento/blank',
            'theme_path' => 'Rbj/default',
            'theme_title' => 'Rbj default',
            'is_featured' => '0',
            'area' => 'frontend',
            'type' => '0',
            'code' => 'Rbj/default'
        ],
        'frontend/Rbj/us_site' => [
            'parent_id' => 'Rbj/default',
            'theme_path' => 'Rbj/us_site',
            'theme_title' => 'Rbj us store view',
            'is_featured' => '0',
            'area' => 'frontend',
            'type' => '0',
            'code' => 'Rbj/us_site'
        ]
    ],

You can use the config.php file as per your store’s setup and configuration value to define using the code level.