In Magento 2, the equivalent to app/etc/local.xml is app/etc/env.php.
You need to edit that file and everything should be fine.
In case you need an example...
'db' =>
array (
'connection' =>
array (
'indexer' =>
array (
'host' => 'localhost',
'dbname' => '<your_database_name>',
'username' => '<your_database_username>',
'password' => '<your_database_password>',
'active' => '1',
'persistent' => NULL,
),
'default' =>
array (
'host' => 'localhost',
'dbname' => '<your_database_name>',
'username' => '<your_database_username>',
'password' => '<your_database_password>',
'active' => '1',
),
),
'table_prefix' => '',
In case you are a lazy coder just like me...
Create a custom command in Magento 2
app/code/Octopius/Commands/Console/Command/SwitchToLive.php
<?php
namespace Octopius\Commands\Console\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* An Abstract class for support tool related commands.
*/
class SwitchToLiveCommand extends Command
{
protected $_storeManager;
protected $_fileManager;
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Filesystem\Io\File $fileManager
) {
$this->_storeManager = $storeManager;
$this->_dataObjectHelper = $dataObjectHelper;
$this->_fileManager = $fileManager;
parent::__construct();
}
/**
* Define the shell command
* @return void
*/
protected function configure()
{
$this->setName('switch:env:live')
->setDescription('Switch environment file...');
parent::configure();
}
/**
* Execute function
* @param InputInterface $input Input
* @param OutputInterface $output Output
* @throws \Magento\Framework\Exception\LocalizedException
* @return null|int null or 0 if everything went fine, or an error code
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Switching to live environment...');
$liveEnv = BP . '/' . 'app/etc/env.php.live';
$env = BP . '/' . 'app/etc/env.php';
if ($this->_fileManager->fileExists($liveEnv)) {
$this->_fileManager->mv($liveEnv, $env);
}
$output->writeln('Environment switched successfully.');
}
}
app/code/Octopius/Commands/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="octopiusSwitchToLiveCommand" xsi:type="object">Octopius\Commands\Console\Command\SwitchToLiveCommand</item>
</argument>
</arguments>
</type>
</config>
app/code/Octopius/Commands/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Octopius_Commands" setup_version="0.1.0"/>
</config>
app/code/Octopius/Commands/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Octopius_Commands',
__DIR__
);
Obviously, make sure you have app/etc/env.php.live before start using bin/magento switch:env:live
Best Answer
This YouTube tutorial might help: https://www.youtube.com/watch?v=OOIzGpXCuT4
Once you've copied all the files to your local
htdocs
folder, I believe you'll need to migrate yourMySQL database
from your live to your local. Additionally, make sure to update theweb/unsecure/base_url
and 'web/secure/base_url' in thecore_config_data
table.