Installing Magento 2 in docker-compose php 7.4 / apache /
I like to work with docker-compose. And also like to use Magneto 2 for my eCommerce solutions. So this article will explain how to setup docker compose to install Magento 2 CE.
You can also check the Youtube video at https://www.youtube.com/watch?v=-oJZQYslQ_Y
Note that I’m not going to explain all the docker-compose setup. You can download the docker-compose files from my github repository.
https://github.com/theiconnz/magento2-docker-compose
I’ve created few docker services in the docker-compose file to support the Magento installation.
Services
- Apache Service
- PHP Service
- MariaDB Service
- Elasticsearch
- Phpmyadmin
You can find these docker services in my docker-compose file https://github.com/theiconnz/magento2-docker-compose/blob/master/docker-compose.yml
Also notice the .env file. .env file contains the configuration used in docker-compose file.
https://github.com/theiconnz/magento2-docker-compose/blob/master/.env
Note that in .env file All the project’s paths configuration were relative to your working directory.
WEB Service
In docker-compose.yml file we declare our web service and web service is pointing to the folder, where it contains the Dockerfile for Apache build.
In the docker/apache folder we have httpd.conf file. Note the ProxyPassMatch at line 267. This is very important. “fcgi://php:9000” the php in this line is reference to our PHP Service name in docker-compose file.
Since you may need to work on a multi store web site you may need to use virtual server in your local docker setup. In that case use httpd-vhosts.conf and turn on the reference to httpd-vhost.conf in the httpd.conf
PHP Service
For PHP Service, We use php:7.4-fpm image. if you look at docker/php/Dockerfile, you can see all the modules installed. In addition we also enable the xdebug for this project in the php service.
Elasticserch, Phpmyadmin and Maria DB
These services turn on the extra services we need to run Magento 2.
I’ve run this docker-compose setup in MacOs, Windows and Ubuntu and used this setup for my Magento projects.
In MYSQL service, you may need to add command to increase packet size if you are importing a already installed database.
It’s worth mentioning that you need to edit your hosts file to support the domain in the .env file. If you run a virtual host you need those domains in the host file too.
We can access our database using phpmyadmin by typing domain and port assigned in the .env file