Docker for services, php locally. No sync, no mental overhead, no performance
penalties.
php
, nginx
, https
, http/2
, varnish
, mysql
elasticsearch
,
rabbitmq
, mailhog
Docker is easy, docker scales, we love Docker, but docker's volume mounting is slow, we can't have slow.
The problem with all the docker devboxes is that they require running php inside a vm. The problem with php in a VM is that files need to be available in the VM, but it also needs to have files outside the VM, because programs like PHPStorm and others do not accept network drives.
Sync is slower than no sync. docker-sync, unison, mutagen offer good sync solutions, but always slower than no sync.
Hovever, syncs require additional HDD space and additional mental overhead: Are my files synced?, Is my sync broken? Are there sync conflicts? Why did that file appear here? Where should I execute my php cli scripts? Where should I run node cli? Why is my system slow? Sync is bad.
- It should be possible for a frontend developer without any backend skillsto set up a development environment.
- It should be possible for a backend developer to add or upgrade services.
- It should be possible for a backend developer to propagate the changes to the rest of the team with version control.
- No magic: As few CLI tools that will automatically 'fix' things. Do not use wrappers around existing tools: docker / etc. Exception: php runs locally, needs to be set up.
- Declarative: Developer should define the final state instead of running upgrade scripts (hence, docker).
- Minimal: Use as few cpu cycles and memory as possible.
- Recent OSX
Since we're running some things locally it probably is a good time to clean some stuff up.
- Run
brew doctor
and make sure you don't have errors. - Run
brew update
to update to the latest version.
You should not have any services running like.
php
: find them withbrew list | grep php
, uninstall them usingbrew uninstall โf <packages>
. With the force flag you'll delete all installed versions of formula.httpd
: Disable apache that is OSX native. http://localhost/ should not return anything.mysql
: uninstall or disable mysql, or at least make sure it doesnt run on the default MySQL port.nginx
: uninstall
Take a look at ~/.bash_profile
or ~/.zshrc
and make sure it doesn't contain
any references to /usr/local/Cellar/php*
.
Since we're running a hybrid docker+local system we need to set up PHP to run locally.
# Cleans existing brew php (will not remove Valet stuff) + installs php on OSX!
curl -s https://raw.githubusercontent.com/ho-nl/docker-development-box/2.x/install.sh | bash -s -- -i
It will (re)install multiple php-fpm services, one for each version (port: 9072, 9073, 9074) and one for each version with xdebug (port: 9172, 9173, 9174).
brew unlink php@7.3
brew link php@7.2 --force
php -v
Should now show the right version. If it doesn't there might be still be a version linked or your ~/.bash_profile should be cleaned up or you need to reopen your CLI.
- Install docker for mac 2.1.0.1.
- Start Docker
- Exclude
~/Library/Containers
from your backups brew install ctop
: can be used to show container metrics.- Open Docker -> Preferences
- Set memory to 3-4 GB
Note: Newer versions of Docker for Mac have network latency issues, see #10
sudo nano /etc/exports
add:/System/Volumes/Data -alldirs -mapall=501:20 localhost
sudo nano /etc/nfs.conf
add:nfs.server.mount.require_resv_port = 0
sudo nfsd restart
- Download the raw .pem file (Open Raw, then CMD + S):
- ./hitch/*.localhost.reachdigital.io.pem
- Open keychain.app, add this file (you can drag and drop files in the keychain app).
- Open certificate and trust the certificate.
You are now done with the global installation ๐
- Install this in the project
composer require reach-digital/docker-devbox ^2.0.6
- Install
static-content-deploy
patch and removepub/static/frontend/*
. - Disable services you don't need in
docker-compose.yml
(required:hitch
,varnish
,nginx
anddb
). - Commit the
docker-compose.yml
file to prevent future accidental changes. - Update or create an env.php file and with the following info
'host' => '127.0.0.1', 'dbname' => 'magento', 'username' => 'magento', 'password' => 'magento',
- Create a setup script for the base-urls and run it.
- Start:
docker-compose up -d
- Logging:
ctop
- Stop:
docker-compose down
Delete data (mysql/elasticsearch):
rm -rf var/.esdata
rm -rf var/.mysqldata
You now have all services set up ๐. See individual services below to set urls, caches, etc.
- Web: Xdebug should work by default when you have the Xdebug helper installed + PHPStorm is listening to connections.
- Cli: Use
XDEBUG_CONFIG="" php -c /usr/local/etc/php/7.2/php-xdebug.ini bin/magento
- Tests: Create a local interpreter, the PHP version you're looking for should
be suggested and add the
๐ Xdebug path:
to enable xdebug (you should have seen that with the installation). The path is something like/usr/local/Cellar/php/7.4.3/pecl/20190902/xdebug.so
(lookup your exact path)
- For all other services, start
ctop
and press<-
on your keyboard. - phplogs: tail -f /usr/local/var/log/php* (will probably be empty as it will only output true errors)
https only with hitch. The docker container does not support http, only https.
bin/magento config:set --lock-env web/unsecure/base_url https://blabla.localhost.reachdigital.io/
bin/magento config:set --lock-env web/secure/base_url https://blabla.localhost.reachdigital.io/
# You can use any domain that points to 127.0.0.1, you can't use https://localhost because Magento can't handle that.
# *.localhost.reachdigital.io always resolves to 127.0.0.1
Cache by default with https://www.varnish-software.com/
bin/magento setup:config:set --http-cache-hosts=127.0.0.1:6081
bin/magento config:set --lock-config system/full_page_cache/caching_application 2
- You can use
bin/magento cache:clean
orcache:flush
to flush Varnish. - You can use
CMD+SHIFT+R
to bypass Varnish for any page.
php bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-db=0 --cache-backend-redis-port=6379
php bin/magento setup:config:set --session-save=redis --session-save-redis-db=2 --session-save-redis-port=6379
How do I flush Redis directly when bin/magento
is broken?
docker-compose down && docker-compose up -d
bin/magento config:set --lock-config catalog/search/enable_eav_indexer 0
bin/magento config:set --lock-config catalog/search/engine [elasticsearch6 OR elasticsuite]
bin/magento config:set --lock-env catalog/search/elasticsearch6_server_port 9200
bin/magento config:set --lock-env catalog/search/elasticsearch6_server_hostname localhost
composer require mageplaza/module-smtp
php bin/magento setup:upgrade
bin/magento config:set --lock-env system/smtp/disable 0
bin/magento config:set --lock-env system/smtp/host localhost
bin/magento config:set --lock-env system/smtp/port 1025
bin/magento setup:config:set --amqp-host=localhost --amqp-port=5672 --amqp-user=guest --amqp-password=guest
http://localhost:15672
No support yet.
- Open up
ctop
- โฎ on your service
exec shell
Please note that the containers are as minimal as possible, so not all common tools are available, but you should be able to get around.
Everything is set up via the docker-compose.yml file. You see paths to the configuration file there.
- Change the path to your custom configuration file.
- Run
docker-compose down && docker-compose up -d
- Changes should be applied, check
ctop
if your container is able to start.
pkill php-fpm
Commits are validated with https://github.com/conventional-changelog/commitlint
Gittower: Gittower doesn't properly read your PATH variable and thus commit
validation doesn't work. Use gittower .
to open this repo.