This is just a personal docker-compose setup that I put together after frustrations trying to set up Magento on Windows and only seeing Nginx Docker configs for Magento instead of Apache + PHPFPM.
This isn't intended to be a comprehensive guide for setting up a Magento 2 Apache Docker environment, but some people might find it helpful or have suggestions for improvement.
Most of the helper bin commands are from Mark Shust's Docker Magento project, with some tweaks.
- Set your
.env
file, see.env.example
for reference. - Import your db either using the cli helpers or using phpmyadmin
- Run
bin/copytocontainer --all
- Run commands
bin/magento setup:di:compile upgrade cache:clean cache:flush
- Clear content directories
rm -rf var/cache/* var/di/* generated/* var/page_cache/* var/view_preprocessed/* pub/static/frontend/*
bin/magento deploy:mode:set developer
- Deploy static contents if page is blank:
bin/magento setup:static-content:deploy -f
- Run
bin/magento config:set dev/static/sign 0
since static-content:deploy sets this value to 1 - Reset to developer mode
- Run
Reference: https://devdocs.magento.com/guides/v2.3/config-guide/sessions.html
env.php
'session' => [
'save' => 'files',
'save_path' => '/var/www/html/var/session'
],
php.ini
session.save_handler = files
session.save_path = "/var/www/html/var/session"
bin/clinotty mysql -hdb -u{magento_user} -p{magento_db_pw} {magento_db_name} < existing/magento.sql
Exception: Warning: SessionHandler::read(): open(/var/www/html/var/session/sess_..., O_RDWR) failed: Permission denied (13) in`
Causes:
- Incorrect file permissions for session directory
Solution: Run bin/fixowns
rm -rf pub/static/*
bin/magento config:set dev/static/sign 0
(this is set to 1 if you use static-content:deploy)- Reset developer mode
bin/magento deploy:mode:set developer
Cause: Incorrect file permissions / running Magento commands that generate files as root (static-content:deploy
, upgrade
, etc.) instead of Magento filesystem owner (app:www-data).
Solution:
- Run
bin/fixperms
- Run
bin/magento setup:upgrade