Devdocs: how can Set up Magento2 backend on a separate node?

Created on 31 Aug 2016  路  12Comments  路  Source: magento/devdocs

##how can Set up Magento2 backend on a separate node?
I want to install magento in 3 servers,

  • server 1: front
  • server 2: backend
  • server 3: database

Anyone achieved that?

Most helpful comment

yes, here a solution

First of all, We have to install magento in Server1 and configure it as you wish.

Here my proposal

Our goal will be to achieve this one

Then, In server1 we have to modify the file "/var/www/magetest/app/etc/env.php"

We'll set as database server Server3

array (
    'table_prefix' => 'mg_',
    'connection' => 
    array (
        'default' => 
            array (
                'host' => '192.168.207.130,
                'dbname' => 'mage',
                'username' => 'myUser',
                'password' => 'myPassword',
                'active' => '1',
            ),
    ),
),

And set this config to save sessions in the database, you can use Redis or other options for that, but this time we'll use the database.

'session' => 
    array (
        'save' => 'db',
    ),

Now we have to duplicate magetest from server1 to server2

In server1 Set this config at backend:

"Stores->Configuration->General->Web->Url Options->Auto-redirect to Base URL" to "No"
"Stores->Configuration->Advanced->Admin->Admin Base Url->Use Custom Admin URL" to "Yes"
"Stores->Configuration->Advanced->Admin->Admin Base Url->Custom Admin URL" to "https://192.168.207.129/magetest/"

In server1 we have to install "nfs-kernel-server" to share the directory "/var/www/magetest/pub/media/" with server2:

aptitude install nfs-kernel-server nfs-common

Now modify the file "/etc/exports", to share the media directory "/var/www/magetest/pub/media/":

nano /etc/exports
/var/www/magetest/pub/media 192.168.207.129/32(rw,insecure,nohide,sync,anonuid=48,anongid=48)

service nfs-kernel-server restart

Go to server2 to install and configure nfs-client

aptitude install nfs-client nfs-common

Drop the content of /var/www/magetest/pub/media/

rm -r /var/www/magetest/pub/media/*

Mount the new directory using nfs-client

mount 192.168.207.128:/var/www/magetest/pub/media /var/www/magetest/pub/media

Important: You'll have to configure the file "/etc/fstab" to maintain the configuration as permanent

In both servers drop the content of these directories:

rm -r /var/www/magetest/var/cache/*
rm -r /var/www/magetest/var/page-cache/*
rm -r /var/www/magetest/var/generation/*

And finally, execute this command in both servers

php /var/www/magetest/bin/magento cache:clean

Now everything should be working, frontend, backend and database in separate nodes

http://192.168.207.128/magetest
https://192.168.207.129/magetest/admin/

All 12 comments

Created internal issue MAGETWO-60159 to track.

Any updates to this?

yes, here a solution

First of all, We have to install magento in Server1 and configure it as you wish.

Here my proposal

Our goal will be to achieve this one

Then, In server1 we have to modify the file "/var/www/magetest/app/etc/env.php"

We'll set as database server Server3

array (
    'table_prefix' => 'mg_',
    'connection' => 
    array (
        'default' => 
            array (
                'host' => '192.168.207.130,
                'dbname' => 'mage',
                'username' => 'myUser',
                'password' => 'myPassword',
                'active' => '1',
            ),
    ),
),

And set this config to save sessions in the database, you can use Redis or other options for that, but this time we'll use the database.

'session' => 
    array (
        'save' => 'db',
    ),

Now we have to duplicate magetest from server1 to server2

In server1 Set this config at backend:

"Stores->Configuration->General->Web->Url Options->Auto-redirect to Base URL" to "No"
"Stores->Configuration->Advanced->Admin->Admin Base Url->Use Custom Admin URL" to "Yes"
"Stores->Configuration->Advanced->Admin->Admin Base Url->Custom Admin URL" to "https://192.168.207.129/magetest/"

In server1 we have to install "nfs-kernel-server" to share the directory "/var/www/magetest/pub/media/" with server2:

aptitude install nfs-kernel-server nfs-common

Now modify the file "/etc/exports", to share the media directory "/var/www/magetest/pub/media/":

nano /etc/exports
/var/www/magetest/pub/media 192.168.207.129/32(rw,insecure,nohide,sync,anonuid=48,anongid=48)

service nfs-kernel-server restart

Go to server2 to install and configure nfs-client

aptitude install nfs-client nfs-common

Drop the content of /var/www/magetest/pub/media/

rm -r /var/www/magetest/pub/media/*

Mount the new directory using nfs-client

mount 192.168.207.128:/var/www/magetest/pub/media /var/www/magetest/pub/media

Important: You'll have to configure the file "/etc/fstab" to maintain the configuration as permanent

In both servers drop the content of these directories:

rm -r /var/www/magetest/var/cache/*
rm -r /var/www/magetest/var/page-cache/*
rm -r /var/www/magetest/var/generation/*

And finally, execute this command in both servers

php /var/www/magetest/bin/magento cache:clean

Now everything should be working, frontend, backend and database in separate nodes

http://192.168.207.128/magetest
https://192.168.207.129/magetest/admin/

@jorbope If you'll submit this to us in a PR, I will use your name as a contributor similar to this page: http://devdocs.magento.com/guides/v2.1/test/integration/integration_test_execution_phpstorm.html (Upper right corner)

I'd suggest you add a new file here: https://github.com/magento/devdocs/tree/develop/guides/v2.0/config-guide

Don't' worry too much about formatting, I'll fix that.

OK

Just a few comments:

  1. Cache should be on Redis.
  2. I would not recommend to store sessions in the DB, Redis is better

Yes, you are right.

Another addition - instruction on how to pass admin traffic to the admin node should be added. It could be redis, aws elb or smth else + probably separate subdomain

@samm-git Can you clarify/amplify? Thanks

Sure. If we are adding > 1 node we should also load balance traffic between them. If we want to make admin node - we should route admin traffic (and only to it) based on subdomain or path

Hi All,

I'm facing the issue while configuring Magento backend on another server.

Example:
server1: 192.168.207.142 : front: http://192.168.207.142/magetest
server2: 192.168.207.143 : backend: https://192.168.207.143/magetest/admin/
server3: 192.168.207.144 : database

I have tried these steps mentioned in this article:
https://github.com/magento/devdocs/issues/802#issuecomment-275545778

After did the changes admin is redirected to 404 page.

Does anyone have a solution for this issue?

Thanks in advance.

Regards,
-Vimal

@jorbope Not working. Still getting infinite redirections from front-end to back-end. Using Redis session storage and EFS for media folder sharing.

Was this page helpful?
0 / 5 - 0 ratings