1

I am trying to move my local Magento site to my Live server. (XAMPP to cPanel)

To do this I have exported the database, etc and all those steps are fine.

However i get error on tables in my phpmyadmin on cpanel, also i read that i should edit the local.xml file but i don't have that file in my app/etc folder rather i have config.php, env.php, di(which is xml)file.

Does anybody know if I am doing this step correctly, or is there a different way to get my Magento files from my Local site to my Live site. or how i can manually set local.xml in magento 2.0

My env.php looks like this

<?php
  return array (
  'backend' => 
  array (
  'frontName' => 'admin',
  ),
 'install' => 
  array (

 'date' => 'Mon, 18 Apr 2016 14:27:37 +0000',

  ),
   'crypt' =>
  array (
    'key' => '51b8c74ff74f2b568c1025da3b4be0f4',
  ),
  'session' => 
  array (
    'save' => 'files',
  ),
  'db' => 
  array (
    'table_prefix' => '',
    'connection' => 
    array (
      'default' => 
      array (
        'host' => 'localhost',
        'dbname' => 'fashmart247',
        'username' => 'root',
        'password' => '',
        'active' => '1',
      ),
    ),
  ),
  'resource' => 
  array (
    'default_setup' => 
    array (
      'connection' => 'default',
    ),
  ),
  'x-frame-options' => 'SAMEORIGIN',
  'MAGE_MODE' => 'default',
  'cache_types' => 
  array (
    'config' => 1,
    'layout' => 1,
    'block_html' => 1,
    'collections' => 1,
    'reflection' => 1,
    'db_ddl' => 1,
    'eav' => 1,
    'config_integration' => 1,
    'config_integration_api' => 1,
    'full_page' => 1,
    'translate' => 1,
    'config_webservice' => 1,
  ),
);
2
  • What do i have to edit? apologies for my question, i have just been reading too many articles but i just need clarity.
    – Josephine
    Apr 19, 2016 at 8:04
  • The file you need to edit is app/etc/env.php. Please consider to mark an answer as solution if you think it solved your problem. Apr 19, 2016 at 8:07

2 Answers 2

8

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

4
  • OK so you saying the same information edited in local.xml, is what i have to edit in env.php
    – Josephine
    Apr 19, 2016 at 8:12
  • @Josephine: Check my updated answer. Apr 19, 2016 at 8:23
  • @Tony: Great i guess i can move forward from here. Just one question, do i edit before on localhost or when i have moved the to live server
    – Josephine
    Apr 19, 2016 at 9:13
  • @Tony great you have just helped me get things sorted. thumps up.
    – Josephine
    Apr 20, 2016 at 9:46
2

In magento1 Local.xml has credentials for connection to DB. In magento2 credentials are stored in file env.php. Just edit in this file credentials for DB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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