The easy magento environment for Dummies Supported Systems
- MacOs (Intel, Apple M1)
- Linux (AMD64, ARM64)
- Windows via WSL2 (AMD64)
MacOs
Install Docker for Mac: https://docs.docker.com/desktop/mac/install/
Linux
Install Docker with Compose plugin:
curl https://get.docker.com | sudo bash
sudo usermod -aG docker $USER
exec su -l $USER
Windows
Follow this guide: https://docs.docker.com/desktop/windows/wsl/
Install Homebrew by following guide https://brew.sh
You need to export COMPOSER_AUTH variable s othat Composer can use credentials inside containers
export COMPOSER_AUTH='{
"http-basic": {
"repo.magento.com": {
"username": "xxxxxxxxxxxx",
"password": "yyyyyyyyyyyy"
}
},
"github-oauth": {
"github.com": "xxxxxxxxxxxx"
}
}'You can get the value from local machine where composer already configure using following command:
echo "export COMPOSER_AUTH='"$(cat $(php -d display_errors=0 $(which composer) config --no-interaction --global home 2>/dev/null)/auth.json)"'"Optionally you can add this row to your
~/.bashrcor~/.zshrc
Install the formula via homebrew
brew install digitalspacestdio/docker-compose-magento/docker-compose-magento- Create the new projet directory
mkdir ~/magento2- Navigate to the projet directory
cd ~/magento2- Create the new magento project
docker-compose-magento composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=^2 /var/www- Deploy sample data
docker-compose-magento bin/magento sampledata:deploy- Install the application
docker-compose-magento bin/magento setup:install --backend-frontname="admin" --key="admin" --session-save="files" --db-host="database:3306" --db-name="magento2" --db-user="magento2" --db-password="magento2" --admin-user="admin" --admin-password='$ecretPassw0rd' --admin-email="johndoe@example.com" --admin-firstname="John" --admin-lastname="Doe" --key="26765209cb05b93729898c892d18a8dd" --search-engine=elasticsearch7 --elasticsearch-host=elasticsearch --elasticsearch-port=9200 --base-url="http://localhost:30280/" --base-url-secure="https://localhost:30280/"- Optionally: Disable 2FA module (if needed)
docker-compose-magento bin/magento module:disable Magento_TwoFactorAuth Magento_AdminAdobeImsTwoFactorAuth- Optionally: Disable FPC
docker-compose-magento bin/magento cache:disable full_page- Optionally: Disable Secure URLs
docker-compose-magento bin/magento config:set web/secure/use_in_adminhtml 0
docker-compose-magento bin/magento config:set web/secure/use_in_frontend 0
docker-compose-magento bin/magento cache:clean- Start the stack in the background mode
docker-compose-magento up -dApplication will be available by following link: http://localhost:30280/
- Clone the project source code
git clone https://github.com/magento/magento2.git ~/magento2- navigate to the project dir
cd ~/magento2- Install dependencies
docker-compose-magento composer install -o --no-interaction- Configure the application database credentials
docker-compose-magento bash -c 'bin/magento setup:config:set --quiet --db-host $DATABASE_HOST --db-user $DATABASE_USER --db-password $DATABASE_PASSWORD --db-name $DATABASE_NAME'
docker-compose-magento bin/magento app:config:import --quiet- Configure the application redis settings
docker-compose-magento bin/magento setup:config:set --quiet --cache-backend redis --cache-backend-redis-server redis --cache-backend-redis-port 6379 --cache-backend-redis-db 0
docker-compose-magento bin/magento setup:config:set --quiet --session-save redis --session-save-redis-host redissession --session-save-redis-port 6379 --session-save-redis-db 0
docker-compose-magento bin/magento app:config:import --quiet- Configure the application elasticsearch settings
docker-compose-magento bin/magento config:set catalog/search/elasticsearch7_server_hostname elasticsearch
docker-compose-magento bin/magento config:set catalog/search/elasticsearch7_server_port 9200
docker-compose-magento bin/magento app:config:import --quiet- Import database dump (supports
*.sqland*.sql.gzfiles)
docker-compose-magento database-import /path/to/dump.sql.gz- Optionally: Disable 2FA module (if needed)
docker-compose-magento bin/magento module:disable Magento_TwoFactorAuth- Optionally: Disable FPC
docker-compose-magento bin/magento cache:disable full_page- Optionally: Disable Secure URLs
docker-compose-magento bin/magento config:set web/secure/use_in_adminhtml 0
docker-compose-magento bin/magento config:set web/secure/use_in_frontend 0
docker-compose-magento bin/magento cache:clean- Start the stack in the background mode
docker-compose-magento up -dor if you want to bind custom port
COMPOSE_PROJECT_PORT_HTTP=80 docker-compose-magento up -dApplication will be available by following link: http://localhost:30280/
Stop containers
docker-compose-magento downDestroy containers and persistent data
docker-compose-magento down -vConnecting to the mysql container
docker-compose-magento mysqlConnecting to the cli container
docker-compose-magento bashGenerate compose config and run directly without this tool
docker-compose-magento config > docker-compose.ymldocker compose upCan be stored in the
.dockenv,.dockerenvor.envfile in the project root
COMPOSE_PROJECT_MODE- (mutagen|default)COMPOSE_PROJECT_COMPOSER_VERSION- (1|2)COMPOSE_PROJECT_PHP_VERSION- (7.4|8.0|8.1|8.2), the image will be built from a correspondingfpm-alpineimage, see https://hub.docker.com/_/php/?tab=tags&page=1&name=fpm-alpine&ordering=name for more versionsCOMPOSE_PROJECT_NODE_VERSION- (12.22.12|14.19.3|16.16.0) the image will be built from a correspondingalpineimage, see https://hub.docker.com/_/node/tags?page=1&name=alpine3.16 for more versionsCOMPOSE_PROJECT_MYSQL_IMAGE-mysql:8.0-oraclesee https://hub.docker.com/_/mysql/?tab=tags for more versionsCOMPOSE_PROJECT_ELASTICSEARCH_VERSION-7.17.5see https://www.docker.elastic.co/r/elasticsearch/elasticsearch-oss for more versionsCOMPOSE_PROJECT_NAME- by default the working directory name will be usedCOMPOSE_PROJECT_PORT_PREFIX-302by defaultCOMPOSE_PROJECT_PORT_HTTP-$COMPOSE_PROJECT_PORT_PREFIX+80by defaultCOMPOSE_PROJECT_PORT_XHGUI-$COMPOSE_PROJECT_PORT_PREFIX+81by defaultCOMPOSE_PROJECT_PORT_MYSQL-$COMPOSE_PROJECT_PORT_PREFIX+06by defaultCOMPOSE_PROJECT_PORT_ELASTICSEARCH-$COMPOSE_PROJECT_PORT_PREFIX+92by defaultCOMPOSE_PROJECT_PORT_MAIL_WEBGUI-$COMPOSE_PROJECT_PORT_PREFIX+25by default
In first you need to define the environment variable XDEBUG_MODE
export XDEBUG_MODE=debugor container specific
export XDEBUG_MODE_FPM=debug
export XDEBUG_MODE_CLI=debug
export XDEBUG_MODE_CRON=debugVisual Studio Code launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"hostname": "0.0.0.0",
"port": 9003,
"pathMappings": {
"/var/www": "${fileWorkspaceFolder}"
}
}
]
}Add required packages
docker-compose-magento composer require perftools/php-profiler
docker-compose-magento composer require perftools/xhgui-collector
docker-compose-magento composer require alcaeus/mongo-php-adapterApply the patch
docker-compose-magento xhprof-patchTo revert the patch run:
docker-compose-magento xhprof-revert