Skip to content

Commit 4f7af74

Browse files
authored
Make Magento 2 staging article self-contained
Make Magento 2 staging article self-contained The article previously deferred to the Magento 1 version for some of its content. Inline the relevant parts so readers no longer have to switch articles
1 parent e35a45a commit 4f7af74

1 file changed

Lines changed: 92 additions & 3 deletions

File tree

docs/ecommerce-applications/magento-2/how-to-set-up-a-basic-staging-environment-for-magento-2.md

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,33 @@ redirect_from:
1313

1414
# How to Set Up a Basic Staging Environment for Magento 2
1515

16-
This article is an extension to the [article for Magento 1](../magento-1/how-to-set-up-a-staging-environment-for-magento-1.md). For information about the capabilities of the staging environment, please read it first.
16+
A staging environment is very useful, for things such as:
1717

18-
Your staging environment **shares resources**(disk, CPU, memory) with your production site. If you want to do things such as automated load tests, it is recommended to order a [development plan](../../hypernode-platform/tools/how-to-use-hypernode-development-plans.md) instead, so your production site will not be affected.
18+
- Let a customer (shop-owner) click around a proposed change
19+
- Quickly make a copy of a production shop to analyse a bug that didn't show up during development
20+
- Automated testing by external tools
21+
22+
This article explains how you set one up on Hypernode for a Magento 2 shop. For Magento 1, see [How to Set Up a Staging Environment for Magento 1](../magento-1/how-to-set-up-a-staging-environment-for-magento-1.md).
23+
24+
Keep in mind:
25+
26+
- Your staging environment **shares resources** (disk, CPU, memory) with your production site. If you want to do things such as automated load tests, it is recommended to order a [development plan](../../hypernode-platform/tools/how-to-use-hypernode-development-plans.md) instead, so your production site will not be affected.
27+
- We don't recommend creating hardlinks from your production media folder to your staging media folder as our backup mechanism does not cope well with hardlinks.
28+
29+
## How Does it Work
30+
31+
A second document root (/data/web/staging) is provided and supports all defined vhosts (notably: every SSL vhost). It is reachable on port 8888 and 8880 (http) and 8443 (https).
32+
33+
For Nginx configuration (in /data/web/nginx/\*), the following rules apply:
34+
35+
- http.\* files are included only once in HTTP context
36+
- server.\* files are included in every vhost
37+
- public.\* files are ONLY included in the production vhosts
38+
- staging.\* files are ONLY included in the staging vhosts
39+
40+
This has two distinct advantages. First, there's no need to change DNS, so its very easy to send your customer a link and it just works. Second, SSL certificates will work the same without warning.
41+
42+
Remember that you will need to update the base_url for every storefront (with the new port number). You would have to update the config anyway, as you will likely require a separate database for MySQL and Redis. See below for a simple command.
1943

2044
## How to Make a Copy of a Live Site
2145

@@ -139,9 +163,48 @@ Keep in mind:
139163
- Regenerate your sitemap as it may still contain links to your live site.
140164
- Change all custom links and references that are in your staging installation pointing to the production install.
141165

166+
You can update symlinks using the `ln` tool with the `-f` (force) feature flag:
167+
168+
```bash
169+
ln -sf /data/web/magento2_staging/some_file /data/web/magento2_staging/some_other_file
170+
```
171+
142172
Now you should be able to reach your Magento 2 staging environment on `http://example.hypernode.io:8888`
143173

144-
For additional configuration and troubleshooting refer to the [Magento 1 staging environment article](../magento-1/how-to-set-up-a-staging-environment-for-magento-1.md)
174+
### How to Limit Access to a Staging Environment
175+
176+
If you want to restrict access, you can do so by editing /data/web/nginx/staging.access. There are two options.
177+
178+
- Restrict by IP, use this code:
179+
180+
```nginx
181+
allow your.ip.add.ress;
182+
deny all;
183+
```
184+
185+
- Restrict by password (called HTTP basic authentication).
186+
187+
```nginx
188+
auth_basic "Restricted area";
189+
auth_basic_user_file /data/web/htpasswd-staging;
190+
```
191+
192+
And run this command to add a Hypernode/Hypernode user for the staging environment:
193+
194+
```bash
195+
htpasswd -bc /data/web/htpasswd-staging hypernode hypernode
196+
```
197+
198+
Read more [here](../../hypernode-platform/nginx/how-to-protect-your-magento-store-with-a-password-in-nginx.md) about using HTTP basic authentication on Hypernode.
199+
200+
## Nginx Configuration
201+
202+
To make config adjustments that are only active in the staging environment, use Nginx config files starting with staging. (For example staging.rewrites instead of server.rewrites)
203+
204+
all configuration files for Nginx in /data/web/nginx starting with "staging." will only be included in the staging server block.
205+
206+
_Files starting with "public." will be included in the public environment only.
207+
Files starting with "server." will be included in both the public and the staging environment._
145208

146209
## Staging Environment and Varnish
147210

@@ -182,6 +245,32 @@ root /data/web/public;
182245

183246
So now we want to set this to: `root /data/web/example_staging;` and save the file. Now you can set the Magento installation in this location and you're set.
184247

248+
## Troubleshooting
249+
250+
### Do You Have Enough Disk Space?
251+
252+
If you don't import log and report tables, it will save you a lot. Use [**this script**](https://gist.github.com/hn-support/be909515580cd08bd23a45dc561c3b78#file-check-enough-space-sh%5B/embed%5D) to check whether you have enough space to make a copy of your live site.
253+
254+
To use this script, save it in your home directory on the Hypernode and execute with `bash scriptname.`
255+
256+
### Find and Remove Hardlinks
257+
258+
We do not recommend linking the media folder of your staging site to the media folder of the production site using hardlinks, as our backup mechanism can not cope with hardlinks and restores the linked files as individual files, causing the restored backup to be a lot larger than the original.
259+
260+
To detect earlier created hardlinks, use find:
261+
262+
```bash
263+
find /data/web/ -type f -links +1
264+
```
265+
266+
### External Module Crashes on Different base_url?
267+
268+
The updated base_url will possibly conflict with external modules that use the base_url (with the new port) as license key. Usually, you can fix this by updating the module or asking the vendor to add your staging base_url to the license check.
269+
270+
### Product Feeds Pushed for Staging Environment
271+
272+
If you use extensions that push a product feed to merchant indexing sites like Bol, Google and Marktplaats or Ebay, turn off these feeds for your staging environment to be sure your staging product feeds are not being pushed to any merchant index site.
273+
185274
## Cleanup and Refresh
186275

187276
If you created a staging environment before on the same machine, you might want to do a resync of the content and the database or remove all staging components

0 commit comments

Comments
 (0)