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 subdirectory. This has the advantage that the test shop can be accessed via the same domain as the liveshop and therefore all plugin licenses are available.
To mirror the liveshop in a subdirectory, the following steps are necessary.
Create a subfolder in the public directory of the main shop, e.g. testshop.
Then copy the files of your live environment into the newly created subfolder.
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 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 a 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.
Finally, it is necessary to adjust the domains of the sales channels in Admin. You can reach the Admin under https://my-shop.com/testshop/public/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.com/testshop.
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.