@@ -18,8 +18,8 @@ container (holding the Magento source code). Other containers can be added as
18
18
required for Varnish (recommended), Redis, RabbitMQ, and ElasticSearch. All
19
19
containers run Linux inside.
20
20
21
- The container developers interact with the most is the web container. The
22
- other containers are relatively shrink wrap.
21
+ Developers mainly interact with the web container. The other containers are
22
+ relatively shrink wrap.
23
23
24
24
Normally you set up containers and use them for a long time, removing them only
25
25
when no longer required. Containers can be 'stopped' without being 'removed' to
@@ -34,7 +34,8 @@ Mac and Windows cannot directly access the file system inside the web container
34
34
Storm has special support for "remote PHP interpeters" via ssh. This makes
35
35
source code development and debugging using PHP Storm relatively painless
36
36
even when PHP and the web server are running inside a Docker container.
37
- However, PHP Storm does need access to the the source code.
37
+ However, PHP Storm does need access to the the source code for editing and
38
+ debugging.
38
39
39
40
* There are several directories (such as log directories) which you can choose
40
41
to mount via Docker volumes for easy access directly from your laptop. These
@@ -46,89 +47,61 @@ Mac and Windows cannot directly access the file system inside the web container
46
47
"iNotify" file system events. Volume mounting on Windows does not support
47
48
iNotify events at this time.
48
49
49
- Where volume mounts are not suitable (that is, the Magento source code on Mac
50
- and Windows), DevBox syncs the local and container file systems using a program
51
- called Unison. Whenver a file in the watched local file system is changed, it
52
- is coped into the web container, and vice versa. This allows IDEs to be
53
- natively used on a laptop (or desktop) - Unison copies file changes as soon as
54
- they are made into the web conatiner.
50
+ Where volume mounts are not suitable (that is, the Magento source code
51
+ directory on Mac and Windows), DevBox syncs the local and container file
52
+ systems using a program called Unison. Whenver a file in the watched local file
53
+ system is changed, it is coped into the web container, and vice versa. This
54
+ allows IDEs to be natively used on a laptop (or desktop) - Unison copies file
55
+ changes as soon as they are written to disk into the web conatiner.
55
56
56
- ** Enabling Volume Mounts**
57
-
58
- To enable volume mounting for the Magento source code (e.g. for Linux laptops),
59
- uncomment the relevant volume mount line for ` /var/www ` in the provided
60
- ` docker-compose.yml ` file. For Unison (e.g. for Mac and Windows), ensure the
61
- line is commented out.
62
-
63
- ** Enabling Unison**
64
-
65
- For Windows, a BAT file is provided with the appropriate command line options
66
- to run Unison. For Mac, a shell script is provided. The scripts will restart
67
- Unison automatically if the web container is restarted for some reason.
68
- The script also does an optimized first pass to reduce noise on the console
69
- (it normally reports every synchronized file).
70
-
71
- On Windows, the easiest way to launch Unison is to run the Unison BAT file
72
- in its own window using the START command or by double clicking on the BAT
73
- file from Windows file explorer.
74
-
75
- START m2devbox-unison-sync.bat
76
-
77
- On Mac, it is recommended to run the script in a separate Terminal window.
78
-
79
- ./m2devbox-unison-sync.sh
80
-
81
- # Getting Started
57
+ # Installation
82
58
83
59
Now you understand what file syncing approach you are going to use, you are now
84
60
ready to get up and going with DevBox.
85
61
86
62
## Prerequisites
87
63
88
64
* Install a recent version of Docker from http://docker.com/ . Docker is
89
- available for Windows, Mac, and Linux. Volume mounting (described below)
90
- is not recommended for older versions of Docker or when using Docker inside
91
- VirtualBox on Windows.
65
+ available for Windows, Mac, and Linux.
92
66
* As part of the Docker installation process, on Windows 10 you may need to
93
67
turn on Hyper-V and then grant Docker access to the ` C: ` drive for Docker to
94
68
mount volumes correctly. This is described in the Docker documentation.
95
- Please note that turning on Hyper-V disables VirtualBox. If you run Docker
96
- in VirtualBox, please be aware that VirtualBox will have its own IP address
97
- (unlike Docker running in Hyper-V that default is accessed using
98
- "localhost").
99
69
* On Windows, it can be useful to install "Git Bash"
100
70
(https://git-for-windows.github.io/ ). As well as Git, it includes a terminal
101
- emulator that works well with Docker as well as a small collection of Linux
102
- commands.
71
+ emulator as well as a useful collection of Linux commands.
103
72
104
73
## Setting Up a New Environment
105
74
106
75
### 1. Create a Local Project Directory
107
76
108
- To start a new project, download a copy of the files in this project to a
109
- new empty directory. Normally you create a directory per project. (Developers
110
- at an system integrator or agency may work on multiple projects at once, one
111
- directory per project.) This project holds starter files for your project.
112
-
113
- GitHub provides a "download ZIP" option if you don't have git installed
114
- locally.
77
+ Create a new directory per project. Download a copy of the files in this
78
+ project to a empty directory.
115
79
116
- * TODO: http://github.com/alankent/magento2devbox-skeleton
80
+ * Go to http://github.com/alankent/magento2devbox-skeleton
81
+ * In the "Branch" drop down, select the tag closest to the project's version
82
+ of Magento. This is to get the correct version of PHP, MySQL, etc.
117
83
* Click on the green button "Clone or Download" and select "Download ZIP".
118
- * Extract the ZIP file contents into an empty directory.
84
+ * Extract the ZIP file contents into the project directory.
119
85
120
86
### 2. Review and Update the docker-compose.yml File
121
87
122
- Review the ` docker-compose.yml ` file in a text editor for adjustments such as
123
- preferred local port numbers. There are comments in the file describing
124
- the settings you are most likely to change.
88
+ Review the ` docker-compose.yml ` file in a text editor, making necessary
89
+ adjustments as described by comments in the file. This includes:
90
+
91
+ * You MUST ensure the container names are different per project to avoid
92
+ conflicts. For example, the default web service container name is
93
+ "proj1-m2web" and the default db service container name is "proj1-m2db".
94
+ Change all occurrences of "proj1" to your project name.
125
95
126
- If you work on multiple projects, create a separate directory per project (e.g.
127
- "proj1", "proj2", etc). DevBox is not designed to switch between projects. You
128
- must ensure the container names are different per project to avoid conflicts.
129
- For example, the default web container name is "m2web" (NOT "web") and the
130
- default database container is "m2db". Change these to "proj1-m2web" and
131
- "proj1-m2db" to match your project name.
96
+ * To enable volume mounting for the Magento source code (e.g. for Linux
97
+ laptops), uncomment the volume mount line for ` /var/www ` in the provided
98
+ ` docker-compose.yml ` file. For Unison (e.g. for Mac and Windows), ensure the
99
+ line is commented out.
100
+
101
+ * Check the port numbers. By default Docker will allocate random free port
102
+ numbers. Change "80" to "8080:80" if you want the web server port to be
103
+ always 8080. You cannot run different containers at the same time using
104
+ the same port numbers.
132
105
133
106
### 3. Launch the Containers
134
107
@@ -142,55 +115,30 @@ To get a bash prompt inside the web container, use
142
115
143
116
You should see a shell prompt of ` m2$ ` .
144
117
145
- You can check what containers are running using
146
-
147
- docker ps
148
-
149
- You can also see what containers exist but are currently not running using
118
+ You can check what containers exist using
150
119
151
120
docker ps -a
152
121
153
122
### 4. Composer Configuration
154
123
155
- This section is optional, but includes Composer performance optimizations worth
156
- considering if you work on multiple projects.
157
-
158
124
The recommended way to create and update projects is via Composer, a PHP
159
125
package manager. Magento provides a Composer repository from which Magento
160
126
(and extensions purchased from Magento Marketplace) can be downloaded.
161
127
162
- There is also a Magento ZIP download which is faster to download, but you will
163
- need to use Composer at some stage to install patches or extensions, so it is
164
- recommended to start with Composer from day 1.
165
-
166
- Composer supports a download cache. Having this mounted to a local directory on
167
- your laptop allows downloads to be shared betwen containers. Cached downloads
168
- make subsequent upgrades and new installs much faster. If you do not mount a
169
- shared volume for this directory, you cannot share the cache between containers
170
- and the cache will be lost when the container is removed. There is nothing
171
- wrong with this other than a potentially larger network bill for downloads and
172
- slower startup time for subsequent new projects.
173
-
174
- Be aware the Composer can be slow to run at times. Give it a minute or two even
175
- if no output is occurring.
176
-
177
- DevBox sets the ` COMPOSER_HOME ` environment variable to
178
- ` /home/magento2/.composer ` .
128
+ Composer caches downloads for performance. Mounting the cache directory on your
129
+ laptop is enabled by uncommenting the "~ /.composer" volume mount in the
130
+ ` docker-compose.yml ` file. This allows downloads to be shared betwen containers
131
+ (e.g. on different projects). If you do not mount a directory, the cache will
132
+ discarded when the container is removed.
179
133
180
134
The first time you run Composer, it may prompt you for a username and password.
181
135
Enter your 'public' and 'private' keys from http://marketplace.magento.com/ ,
182
- "My Profile", "Access keys" when prompoted. Just be aware that an ` auth.json `
136
+ "My Profile", "Access keys" when prompoted. Be aware that an ` auth.json `
183
137
file holding your keys will be saved into ` ~/.composer/ ` . You may want to share
184
138
the Composer downloaded files but have a different ` auth.json ` file per project
185
139
by moving the ` auth.json ` file into your project's home directory (but not
186
140
committing this file to git for security reasons).
187
141
188
- To summarize, the easiest thing is to do nothing - not mount a shared composer
189
- repository. For those wanting the improved performance, it is recommended to
190
- uncomment the line in the ` docker-compose.yml ` file to volume mount the
191
- ` /home/magento2/.composer ` directory. Manually create ~ /.composer on your
192
- laptop if it does not already exist.
193
-
194
142
### 5. Install Magento
195
143
196
144
Next you need to install your Magento project inside the web container under
@@ -202,25 +150,24 @@ the `/var/www/magento2` directory. (Apache is configured by default to use
202
150
If you have an existing project with all the source code already under
203
151
` shared/www ` , you can skip this section. If you use volume mounting, the code
204
152
will automatically be visible; if you use Unison, it will copy files on your
205
- laptop into the web container when Unison is started. Not additional
153
+ laptop into the web container when Unison is started. No additional
206
154
configuration is required.
207
155
208
- Note: If you decide to change the settings in ` docker-composer.yml ` after
209
- the containers have been created, you will need to remove the current
210
- containers and recreate them. This falls under the 'existing project' use case.
211
- MAKE SURE THE SOURCE CODE IS UP TO DATE UNDER THE ` shared/www ` DIRECTORY BEFORE
212
- DELETING THE CONTAINERS TO MAKE SURE YOU DO NOT ACCIDENTALLY LOSE ANY OF YOUR
213
- WORK.
214
-
215
- ** Creating a New Project**
156
+ Note: If you decide to change the settings in ` docker-composer.yml ` after the
157
+ containers have been created, you will need to remove the current containers
158
+ and recreate them (including the database contents). This falls under the
159
+ 'existing project' use case. MAKE SURE THE SOURCE CODE IS UP TO DATE UNDER THE
160
+ ` shared/www ` DIRECTORY BEFORE DELETING THE CONTAINERS TO MAKE SURE YOU DO NOT
161
+ ACCIDENTALLY LOSE ANY OF YOUR WORK.
216
162
217
- The following commands create a new, default, project.
163
+ ** Creating a New Project with Composer **
218
164
219
- First log into the web container.
165
+ Log into the web container.
220
166
221
167
docker-compose exec web bash
222
168
223
- Then create a new project under ` /var/www/magento2 ` . Update the project version number below as appropriate.
169
+ Create a new project under ` /var/www/magento2 ` . (Update the project version
170
+ number as appropriate.)
224
171
225
172
mkdir /var/www/magento2
226
173
cd /var/www/magento2
@@ -229,9 +176,8 @@ Then create a new project under `/var/www/magento2`. Update the project version
229
176
230
177
** Getting Code from a GitHub Project**
231
178
232
- Saving your code in a private git repository on a hosting provider such as
233
- GitHub or BitBucket is strongly recommended. Project structures can change
234
- between developers, but the following is a possible example.
179
+ It is strongly recommended to saving your project code in a private git
180
+ repository on a hosting provider such as GitHub or BitBucket.
235
181
236
182
Log into the web container:
237
183
@@ -241,7 +187,7 @@ Check out the project from inside the container into the `magento2` directory.
241
187
242
188
cd /var/www
243
189
git clone https://github.com/mycompany/myproject.git magento2
244
- cd /var/www/ magento2
190
+ cd magento2
245
191
composer install
246
192
247
193
** Magento Commerce (Cloud)**
@@ -250,9 +196,10 @@ TODO
250
196
251
197
** Internal Development**
252
198
253
- This section is relevant to internal Magento developers, or external developers
254
- wishing to submit a pull request. The following is NOT recommended for
255
- production sites. (It may however be worth exploring by extension developers.)
199
+ This section is ONLY relevant to internal Magento developers, or external
200
+ developers wishing to submit a pull request. The following is NOT recommended
201
+ for production sites. (It may however be worth exploring by extension
202
+ developers.)
256
203
257
204
Log into the web container:
258
205
@@ -287,43 +234,38 @@ Tun the following commands to create a MyQL database to use.
287
234
288
235
mysql -e 'CREATE DATABASE IF NOT EXIST magento2;'
289
236
290
- After the database is created, you can uncomment the line setting the default
291
- database in the MySQL ` ~/.my.cnf ` file so that when you run ` mysql ` from the
292
- command prompt it will log you in and select the ` magento2 ` database by
293
- default. (If this is set when the database does not exist, ` mysql ` will fail to
294
- start.) This is not mandatory, but is convenient.
237
+ After the database is created, uncomment the line setting the default
238
+ database in the MySQL ` ~/.my.cnf ` file.
295
239
240
+ sed -e 's/#database/database/' -i ~/.my.cnf
296
241
mysql
297
242
> SHOW TABLES;
298
243
> exit;
299
244
300
- Next, put the site into developer mode.
245
+ Put the site into developer mode.
301
246
302
247
cd /var/www/magento2
303
248
magento deploy:mode:set developer
304
249
305
250
Set up all the Magento 2 tables with the following command (adjusting command
306
251
line paramter values as desired).
307
252
308
- cd /var/www/magento2
309
253
magento setup:install --db-host=db --db-name=magento2 --db-user=root --db-password=magento2 --admin-firstname=Magento --admin-lastname=Administrator --admin-email=user@example.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --backend-frontname=admin
310
254
311
255
It is recommended to NOT include the ` --base_url ` option during development as
312
256
Docker can allocate a port number at random (including when container is
313
257
restarted). It also causes problems using BrowserSync and similar tools for
314
- frontend development. ( Some versions of Magento however have a bug requiring
258
+ frontend development. Some versions of Magento however have a bug requiring
315
259
` --base_url ` to be specified. If the URL to CSS files is incorrect, you may
316
- have a broken version of Magento.)
260
+ have a broken version of Magento.
317
261
318
262
If you are using RabbitMQ (AMPQ), the following command line arguments should
319
263
be added when the project is created.
320
264
321
265
--amqp-virtualhost=/ --ampq-host=ampq --amqp-port=TODO --amqp-user=guest --amqp-password=guest
322
266
323
- If you want to load the Luma sample data (optional), run the following
324
- additional commands.
267
+ To load the Luma sample data (optional), run the following additional commands.
325
268
326
- cd /var/www/magento2
327
269
magento sampledata:deploy
328
270
magento setup:upgrade
329
271
@@ -334,29 +276,27 @@ process (and keep it running). It is generally recommended to start this up
334
276
after you have installed Magento above.
335
277
336
278
On Windows, get a compatible version of the Unison binaries for Windows
337
- from inside the container using the following (adjust "m2web" to your
338
- web container name from the ` docker-compose.yml ` file - there is no
339
- ` docker-compose cp ` command at this time so you cannot use "web", the service
340
- name).
279
+ from inside the container using the following (adjust "proj1-m2web" to your
280
+ web container name from the ` docker-compose.yml ` file).
341
281
342
- docker cp m2web:/windows/unison.exe .
343
- docker cp m2web:/windows/unison-fsmonitor.exe .
282
+ docker cp proj1- m2web:/windows/unison.exe .
283
+ docker cp proj1- m2web:/windows/unison-fsmonitor.exe .
344
284
345
- Then run the supplied BAT file in a separate window using the START command or
346
- by double clicking via Windows explorer. Close the window to kill Unison.
285
+ Then run the supplied BAT file to launch Unison in a separate window using the
286
+ START command or by double clicking the BAT file via Windows explorer. Close
287
+ the window to kill Unison.
347
288
348
289
START m2devbox-unison-sync.bat
349
290
350
291
Each time you log in, make sure you restart this process, but be careful to not
351
- have multiple copies running. If you stop work on the project, you can close
352
- this window and start it up again later. It is not recommended to do
292
+ have multiple copies running in parallel. It is not recommended to do
353
293
significant work on the project without Unison running to avoid merge conflicts
354
294
(rare).
355
295
356
296
Mac binaries and a shell script are also provided:
357
297
358
- docker cp m2web:/macos/unison .
359
- docker cp m2web:/macos/unison-fsmonitor .
298
+ docker cp proj1- m2web:/macos/unison .
299
+ docker cp proj1- m2web:/macos/unison-fsmonitor .
360
300
chmod +x unison unison-fsmonitor
361
301
362
302
It is recommended to run the sync shell script in a separat Terminal window.
@@ -365,12 +305,7 @@ It is recommended to run the sync shell script in a separat Terminal window.
365
305
366
306
### 8. Connect with a Web Browser
367
307
368
- To access the web server, if you set the web port using the {localport}:80
369
- syntax (e.g. 8080:80), access the page using the specified localport (e.g.
370
- http://localhost:8080/ ). If you did not specify a local port, a random port
371
- that is not currently in use will be allocated by Docker. You can use
372
- ` docker-compose ` with the server name "web" to fetch the local port number
373
- that is bound to the web server port.
308
+ Run the following command to determine the web server port number.
374
309
375
310
docker-compose port web 80
376
311
0 commit comments