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
~/.bashrc
or~/.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="[email protected]" --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 -d
Application 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
*.sql
and*.sql.gz
files)
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 -d
or if you want to bind custom port
COMPOSE_PROJECT_PORT_HTTP=80 docker-compose-magento up -d
Application will be available by following link: http://localhost:30280/
Stop containers
docker-compose-magento down
Destroy containers and persistent data
docker-compose-magento down -v
Connecting to the mysql container
docker-compose-magento mysql
Connecting to the cli container
docker-compose-magento bash
Generate compose config and run directly without this tool
docker-compose-magento config > docker-compose.yml
docker compose up
Can be stored in the
.dockenv
,.dockerenv
or.env
file 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-alpine
image, 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 correspondingalpine
image, see https://hub.docker.com/_/node/tags?page=1&name=alpine3.16 for more versionsCOMPOSE_PROJECT_MYSQL_IMAGE
-mysql:8.0-oracle
see https://hub.docker.com/_/mysql/?tab=tags for more versionsCOMPOSE_PROJECT_ELASTICSEARCH_VERSION
-7.17.5
see 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
-302
by defaultCOMPOSE_PROJECT_PORT_HTTP
-$COMPOSE_PROJECT_PORT_PREFIX
+80
by defaultCOMPOSE_PROJECT_PORT_XHGUI
-$COMPOSE_PROJECT_PORT_PREFIX
+81
by defaultCOMPOSE_PROJECT_PORT_MYSQL
-$COMPOSE_PROJECT_PORT_PREFIX
+06
by defaultCOMPOSE_PROJECT_PORT_ELASTICSEARCH
-$COMPOSE_PROJECT_PORT_PREFIX
+92
by defaultCOMPOSE_PROJECT_PORT_MAIL_WEBGUI
-$COMPOSE_PROJECT_PORT_PREFIX
+25
by default
In first you need to define the environment variable XDEBUG_MODE
export XDEBUG_MODE=debug
or container specific
export XDEBUG_MODE_FPM=debug
export XDEBUG_MODE_CLI=debug
export XDEBUG_MODE_CRON=debug
Visual 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-adapter
Apply the patch
docker-compose-magento xhprof-patch
To revert the patch run:
docker-compose-magento xhprof-revert