Prepare an existing shop for connection

This guide describes how you need to configure an existing Shopware installation before connecting it to the ECA. We assume you have already executed the Shopware server configuration guide

What is the ECA trying to do?

The ECA tries to upload and install the Connector plugin.

  1. Upload the plugin zip file to the remote /tmp directory
  2. Extract it to a newly created directory in _shop_/engine/Shopware/Plugins/Local/Backend/
  3. Execute the cli installer through bin/console
  4. Clear the caches to finish the execution

Granting ECA full Access

If you follow this path the ECA will be fully setup, but also gain write privileges on your shop.

Why is it not working out of the box?

To connect an existing Shop to the ECA it is necessary to set the filesystem permissions manually. On a fresh installation the ECA can control file ownership and set it so that the webserver and deployment user can access the installation. This is then secured by the plugin and the ECA.

But since existing shops don't have the plugin yet, file ownership needs to be changed manually in order for the ECA to deploy the plugin.

To give you an overview how the ECA sets the ownership this is the output of ls -ahl of a freshly installed shop root:

drwxrwxr-x 12 ssh-deploy ssh-deploy 4.0K Jul 29 07:55 .
drwxr-xr-x  6 ssh-deploy ssh-deploy 4.0K Jul 29 07:51 ..
-rw-rw-r--  1 ssh-deploy ssh-deploy 2.9K Sep 16  2015 .htaccess
-rw-rw-r--  1 ssh-deploy ssh-deploy 3.4K May 23 09:45 CONTRIBUTING.md
-rw-rw-r--  1 ssh-deploy ssh-deploy 4.5K Sep 16  2015 README.md
-rw-rw-r--  1 ssh-deploy ssh-deploy  72K May 23 09:45 UPGRADE.md
-rw-rw-r--  1 ssh-deploy ssh-deploy 1.4K May 23 09:45 autoload.php
drwxrwxr-x  2 ssh-deploy ssh-deploy 4.0K Jul 29 07:54 bin
-rw-rw-r--  1 ssh-deploy ssh-deploy 2.8K May 23 09:45 composer.json
-rw-rw-r--  1 ssh-deploy ssh-deploy 146K May 23 09:45 composer.lock
-rw-rw-r--  1 ssh-deploy ssh-deploy  191 Jul 29 07:51 config.php
drwxrwxr-x  4 ssh-deploy ssh-deploy 4.0K Sep 16  2015 engine
-rw-rw-r--  1 ssh-deploy ssh-deploy  48K May 23 09:45 eula.txt
-rw-rw-r--  1 ssh-deploy ssh-deploy  47K May 23 09:45 eula_en.txt
drwxrwxr-x  4 ssh-deploy ssh-deploy 4.0K Sep 16  2015 files
-rw-rw-r--  1 ssh-deploy ssh-deploy  35K Sep 16  2015 license.txt
drwxrwxr-x  9 ssh-deploy ssh-deploy 4.0K Jul 29 07:54 media
drwxrwxr-x  5 ssh-deploy ssh-deploy 4.0K Sep 16  2015 recovery
-rw-rw-r--  1 ssh-deploy ssh-deploy 3.7K May 23 09:45 shopware.php
drwxrwxr-x 13 ssh-deploy ssh-deploy 4.0K Jul 29 07:54 templates
drwxrwxr-x  4 ssh-deploy ssh-deploy 4.0K Jul 29 07:54 themes
drwxrwxr-x  4 ssh-deploy ssh-deploy 4.0K May 23 09:45 var
drwxrwxr-x 19 ssh-deploy ssh-deploy 4.0K Jul 29 07:54 vendor
drwxrwxr-x  3 ssh-deploy ssh-deploy 4.0K Sep 16  2015 web

As you can see the deployment user (in this case ssh-deploy) owns all files and, since the webserver and deployment user share the same unix groups, everything is group readable and writable.

In almost all linux systems changing file ownership is restricted to root. Therefore you yourself will have to take care of this change.

What do I need to do then?

Log into your shop servers shell and adjust the filesystem access permissions manually.

  1. Set ownership of the shop to either your webserver or your deployment user
  2. Update file permissions to make the files group readable and writable
  3. Set bin/console to be executable

On your usual linux system this should look like the following commands:

chown -R ssh-deploy:ssh-deploy _shop_/
chmod -Rv u+rwX g+rwX _shop_/
chmod  +x _shop_/bin/console

After executing these commands you should be able to connect the shop through the ECA's user interface.

Simulating the ECA

If - for some security reason - you can not give the ECA write access to your shop server. You need to simulate the ECA's steps to connect an existing shop to the ECA. Keep in mind though, that cloning of that shop will not work then.

Prepare the shop for connection

Go to the ECAs Admin panel, login and and download the plugin by clicking on Plugin download located in the footer section on every page. Now go to your shop and install and activate the plugin.

The last thing we need is setting up a propper API user. The ECA-Plugin comes with a command able to generate one.

> bin/console sw:eca:apiusercreate "api-password"

Connect the shop to the ECA

This part basically mirrors the shop create functionality present in the ECA WEB-UI. First you need a server id. You can find it be listing the existing servers with this command:

> app/console server:list
+----+----------+---------------+
| Id | Title    | Host          |
+----+----------+---------------+
| 1  | Client 1 | 10.200.200.27 |
| 2  | Client 2 | 10.200.200.28 |
+----+----------+---------------+

Now we just add a shop create command and add the appropriate data like this:

> app/console shop:create --title "TITLE" --baseUrl "/test-cli-connect" --databaseName "test-cli-connect" --httpHost "10.200.200.27" --path "/var/www/test-cli-connect" --shopwareVersion "5.2.5" --serverId 1 --databaseHost "mysql" --apiUserPassword "test-it-api"

After executing this command the ECA is trying to send a request to the shop and check its ability to communicate through REST. The shop is now connected.