Using this docker project you can initiate a new project or import the existent one.
- Open https://www.docker.com/
- Register new account or login with an existent one
- Download and install docker app
-
Import "magento2-docker" repository
-
Open "magento2-docker" folder in terminal app
-
Create "magento" folder:
mkdir magento
-
If you want to import existing DB dump
- 4.1 Create "db" folder:
mkdir db
- 4.2 Copy the
.sql
or.sql.gz
file
- 4.1 Create "db" folder:
-
Build and run all docker components:
docker-compose up --build
-
After configuration is build and running open a new terminal tab and connect to php container:
docker exec -it %PHP_CONTAINER_ID% bash
You can easily get any container name via:docker ps
-
Open "magento" folder and verify that the folder is empty:
cd /var/www/magento; ls -la
-
Choose your approach below and install the project
-
8.1 If you want to install a vanilla Magento instance you need to go to https://devdocs.magento.com/guides/v2.4/install-gde/composer.html and create a new project to the current directory.
Example:
composer create-project --repository=https://repo.magento.com/ magento/project-enterprise-edition .
-
8.2 If you want to install an existent project you need to clone project repository to the "magento" folder:
git clone <--project_repository_url--> .
-
When prompted, enter your Magento authentication keys.
- Once composer install is done run Magento install command:
php bin/magento setup:install \
--db-host=db \
--db-name=magento \
--db-user=magento \
--db-password=123123q \
--base-url=https://magento.local \
--backend-frontname=admin \
--admin-user=admin \
--admin-password=123123q \
[email protected] \
--admin-firstname=Magento \
--admin-lastname=User \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--skip-db-validation \
--elasticsearch-host=elasticsearch \
--elasticsearch-port=9200 \
--amqp-host=rabbitmq \
--amqp-port=5672 \
--amqp-user=guest \
--amqp-password=guest \
--amqp-virtualhost="/" \
&& chown -R www-data:www-data .
-
Update your laptop hosts file:
127.0.0.1 magento.local
Connect to php container vis ssh and run the following commands:
php bin/magento setup:config:set --session-save=redis --session-save-redis-host="redis" --session-save-redis-port=6379 --session-save-redis-db=1
php bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server="redis" --cache-backend-redis-port=6379 --cache-backend-redis-db=2
For connecting to container via SSH you have to use the command:
docker exec -it %CONTAINER_ID% bash
docker exec -it %WEB_CONTAINER_ID% /etc/init.d/nginx reload
docker container restart %PHP_CONTAINER_ID%
You're able to connect to MySQL using "0.0.0.0" as host, port should be default one - "3306", credentials from .env file
You're able to find all the email you send from Magento instance on http://localhost:8025/
-
Shutdown your current docker instance
-
Change PHP version in ./php/Docker file to needed version
Example:
If you need to change PHP version from 7.4 to 7.3 you need to change FROM php:7.4-fpm-buster
to FROM php:7.3-fpm-buster
- Build and run all docker components:
docker-compose up --build
By default Xdebug is enabled in the container, Configure Xdebug in PHPSTORM IDE follow below steps
- Goto
Files
>Settings
>PHP
>Servers
- Add new server by clicking
+
icon- name: magento.local
- host: magento.local
- port: 443
- Check
Use path mappings
- Absolute path on the server →
/var/www/magento/
- Absolute path on the server →
- Start listening to the PHP Debug connecitons
- Add
XDEBUG_CONFIG=idekey=phpstorm
before the comment. e.gXDEBUG_CONFIG=idekey=phpstorm bin/magento cache:flush
- connect to php container:
docker exec -it %PHP_CONTAINER_ID% bash
- edit
/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
usingnano
orvi
and comment the first line i.e.,;zend_extension=xdebug
- restart the PHP container
docker container restart %PHP_CONTAINER_ID%
- connect to php container:
docker exec -it %PHP_CONTAINER_ID% bash
- run with your server ID and Token
blackfire-agent --register --server-id={YOUR_SERVER_ID} --server-token={YOUR_SERVER_TOKEN}
- run
/etc/init.d/blackfire-agent start
to start the agent - Start the profiling from browser with blackfire extension.