Creating a test environment

In some cases it's useful to make changes to test environment, prior to changing a live system.
This recommended for updates, to make sure everything runs as intended without interfering with you live system. In this documentation we will show you the possibilities that exist.

Test environment in the secondary directory of the live shop.

The easiest way to set up a test environment is to copy the Liveshop into a secondary  directory. The public folder in this directory can then be accessed through, for example, a subdomain of the hoster.

In Shopware 5 it was usual to copy the test environment into a subdirectory of the main shop. In Shopware 6 we advise against this and recommend choosing a secondary directory to the main shop, as otherwise problems may arise in the operation of the test environment.


The following steps are necessary to mirror the liveshop into a secondary directory.

Copying the live system

Create a new folder next to the main store directory, e.g. "testshop".
Then copy the files of your live environment into the newly created folder.

It is important that you also copy the .env and .htaccess files. Please note that files beginning with "." may not be displayed directly. In this case, you may need to adjust the display settings of the program that you are using to copy the files. For more information, see the documentation for the program you are using.

Create a subdomain

At your hoster you should now create a subdomain of your main domain. This can look like this: https://subdomain.my-shop.de
Now route this domain to the newly created folder, in which you have copied the main store. 

This subdomain should be different from the shop domain, otherwise the main domain will route to the test environment.

Creating an empty database

Many hosters have their own interface to do this. Usually you can find them, for example, in your host's customer account after logging in. The hoster will be able to provide support in this regard. In this case, the following methods may not be available at all.

Working in the database is inherently coupled with certain risks. Please ensure that you made a backup before executing the following steps.

  • New database using phpMyAdmin

Open the database overview via the item New (1) or the tab Databases. Then enter a name (2) for the test database and select as collation (3) "utf8mb4_unicode_ci".

  • New database using Adminer

Click on Create Database (1) and, in the following mask, select a Name (2) as well as the collation (3). Here, too, this has to be "utf8mb4_unicode_ci"

  • New database with the MySQL Command-Line Client

In the MySQL console you can, of course, also create a new database. First, we have to log into the console:


mysql -u Username -p NameOfTheDatabase

Change Username and NameOfTheDatabase according to your system. The command to create a new database is:


CREATE DATABASE IF NOT EXISTS NameOfYourDatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Changing the .env-file

Adapt the .env file of the test environment according to the newly created database. The file is located directly in the root directory of the test environment
In the file, the line beginning with DATABASE_URL= must be adjusted. Behind the "=" you will find the information of the database. At the very end behind the "/" is the database name to be used. Here you enter the name of the new database.

For instance, this could look like this:

DATABASE_URL=mysql://user:passwort@localhost:3306/testshop

You should also adjust the APP_URL entry so that the complete call for the test shop is stored there.
For instance, this could be as shown below:


APP_URL=http://my-shop.com/testshop/public

It may also be necessary to adjust the entry under COMPOSER_HOME.
This is only necessary if the path stored there leads to your Shopware directory. If the Composer is located outside of the Shopware installation, no adjustment is necessary.

Copying the Live Database

Copy the contents of the live database to the newly created test database.
This is, for example, possible via the export/import function within phpMyAdmin, Adminer or the SQL console. It is worth mentioning that you might run into limitations due to filesizes or server-side timeout settings, thus requiring you to do this via the SQL console. Either way, the console should always be the fastest way, making it the standard procedure.

  • Export & Import with phpMyAdmin

For the export select the database of the live shop (1) and switch to the Export tab (2). Usually you don't have to make any adjustments to the settings and you can perform the export by clicking on Go (3). This creates an SQL file with the name of the database.

This file can now be imported into the database of the test environment.
 

To perform the import, first select the database of the test instance (1). Now open the tab Import (2). You can select the exported file "liveshop.sql" with the Browse button (3). If you have used the default settings when exporting, you normally do not need to make any further adjustments here and can start the import by clicking the Go button (4).

  • Export & Import with Adminer

To create the export, first, click on Export (1). The default settings might not be ideal for our scenario, so select save (2) for Output. Now, click on Export(3) to start the export, resulting in the file being saved or, depending on the scenario, being able to download the result afterwards.

The import can now be executed with the option Import (1). First, select the exported file (2) you want to upload and confirm this with Execute (3). The exported database will now be imported.

  • Export & Import via CLI

An export of the whole database (this is called dump) can also be accomplished via CLI with the following command:


mysqldump -u Username -p NameOfTheDatabase > Filename.sql

Username, NameOfTheDatabase and Filename have to be adapted according to your specifications.

Afterwards, we can import the dump with the following command:


mysql -u Username -p NameOfTheDatabase < NameOfTheExport.sql

Username, NameOfTheDatabase & NameOfTheExport have to be adapted again. Please note that the export file has to be present in the same directory in which you are executing this command in, otherwise the file will not be found.

Some extensions store an APP_URL in the database, which contains the URL of the Shopware installation. In the copy of the database created here, this URL then no longer matches the URL of the test environment in the secondary directory. This leads to a message when the admin is called up for the first time: 
Your shop domain has changed
Here you select the second option Reinstall your apps. This automatically adjusts the entry in the database. 
 

Some extensions may not have been installed from Shopware Store or may require a monthly fee to be paid to the plugin manufacturer. In any of these cases, you should consult the manufacturer of these extensions so you are not billed twice for a copy of the database.

Customize the sales channel domain

Finally, it is necessary to adjust the domains of the sales channels in Admin. You can reach the Admin under https://my-shop.subdomain.com/admin

 

In Admin you select the sales channel (1) in the menu on the left side. In the domain section you can now adjust the URL for the sales channel (2). You can reach the edit view by clicking the "..." button on the right side of the respective line. To make the testshop accessible, add a /testshop at the end. (This depends on how you named the folder in step 1). After you have saved the change, the testshop in our example is accessible at https://my-shop.subdomain.com.

Local test environment

Another way to create a test environment, is setting on up locally. Please note, that plug-ins can only be used correctly if the test environment is accessed through the domain stored in the Shopware account. Since the local environment is usually accessible through a different URL, this can be simulated, for example, with a hosts entry. How this can be implemented is described in this section.

In addition, it is important that the test environment can reach the Shopware server to be able to perform a comparison for the booked plan. Please bear in mind, if you need support the local system should be reachable over the internet.

Making a hosts entry

To access the test environment from your computer under the URL that is stored in the Shopware account

For better understanding we use the domain "my-shop.com" in this example. The test environment can be reached under the IP address 192.168.0.123.

Pay attention with the domain whether it is deposited in the Shopware account with or without "www". It is necessary that you use exactly the same spelling.

Windows

The hosts file in Windows is located in the directory C:\WINDOWS\System32\drivers\etc.In this file you can then enter the IP address of the test environment and also the plan domain.
These are as follows for our example:


192.168.0.123    my-shop.com


Linux (Ubuntu)

The hosts file in Ubuntu is located in the /etc/ directory. In the file you add the IP address of the test environment and domain above the line.

# The following lines are desirable for IPv6 capable hosts

For our example, these are off:


192.168.0.123    my-shop.com


MacOS

For MacOS, the hosts file is located in the /etc/ directory. You can edit the file via the terminal using the following command.


sudo nano /etc/hosts

In the file, you then add the IP address of the test environment and the domain at a random position (it makes sense to do this in a separate line).

These are as follows for our example:


192.168.0.123    my-shop.com

Calling the local environment

After you have adapted the hosts file on your computer, you can now access the local environment via the live shop domain.
In our example, we can only reach the local test environment from our computer at my-shop.com instead of the liveshop.

Provided that the test environment can communicate with the Internet, the license comparison is also possible and the purchased plugins can also be used in the test environment.

Please note:
As long as the hosts entry is stored for the local test environment, you cannot access the liveshop from your computer via the URL.

Was this article helpful?