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.
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.
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.
This subdomain should be different from the shop domain, otherwise the main domain will route to the test environment.
Create a new, empty database in e.g. 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". In our example we call the database "testshop".
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.
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:
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.
Copy the contents of the live database to the newly created test database.
This is possible e.g. via the export/import function within 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. In our example this is "liveshop.sql".
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). Depending on the size of the live database, the import may take some time.
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 charge monthly fees. In any case, you should consult the manufacturer of the plug-in so that the copy of the database does not lead to double billing of the extension.
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.
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 license server to be able to perform the license comparison. Please bear in mind, if you need support the local system should be reachable over the internet.
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.
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 license domain.
These are as follows for our example:
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:
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:
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.
As long as the hosts entry is stored for the local test environment, you cannot access the liveshop from your computer via the URL.