This is a part of the local infrastructure project which aims to create easy to install and use environment for PHP development based on Ubuntu LTS.
-
Ubuntu post-installation scripts - install software, clone repositories with
Docker infrastructureandDockerizer for PHPtool. Infrastructure is launched automatically during setup and you do not need start it manually. Check this repo to get more info about what software is installed, where the files are located and why we think this software is needed. -
Docker infrastructure - run Traefik reverse-proxy container with linked MySQL 5.6, 5.7 and phpMyAdmin containers. Infrastructure is cloned and run automatically by the Ubuntu post-installation scripts. Check this repository for more information on how the infrastructure works, how to use xDebug, LiveReload etc.
-
Dockerizer for PHP(this repository) - install any Magento 2 version in 1 command. Add Docker files to your existing PHP projects in one command. This repository is cloned automatically by the Ubuntu post-installation scripts. Read below to get more information on available commands and what this tool does.
# This file is from the `Ubuntu post-installation scripts` repository
# https://github.com/DefaultValue/ubuntu_post_install_scripts
# Reboot happens automatically after pressing any key in the terminal after executing a script. This must be done before moving forward
sh ubuntu_18.04_docker.sh
# Fill in your `auth.json` file for Magento 2. You can add other credentials there to use this tool for any other PHP apps
cp /misc/apps/dockerizer_for_php/config/auth.json.sample /misc/apps/dockerizer_for_php/config/auth.json
subl /misc/apps/dockerizer_for_php/config/auth.json
# Fill in your root password here so that the tool can change permissions and add entries to your hosts file
echo 'USER_ROOT_PASSWORD=<your_root_password>' > /misc/apps/dockerizer_for_php/.env.local
# Install Magento 2 (PHP 7.2 by default) with self-signed SSL certificate that is valid for you. Add it to the hosts file. Just launch in browser when completed!
php /misc/apps/dockerizer_for_php/bin/console setup:magento example-232.local 2.3.2 -nfP.S.: See notes for MacOS users at the bottom.
Works best without additional adjustments with systems installed by the Ubuntu post-installation scripts.
To use this application, you must switch to PHP 7.1 or 7.2. Magento installation happens inside the Docker container, so do not worry about its' system requirements.
After cloning the repository (if you haven't run the commands mentioned above):
- copy
./config/auth.json.samplefile to./config/auth.jsonand enter your credentials instead of the placeholders; - add your root password to the file
.env.local(in the root folder of this app):USER_ROOT_PASSWORD=<your pass here> - run
composer install
Other settings can be found in the file .env.dist. There you can find database connection settings and information
about the folders where projects and SSL keys are stores. Move these environment settings to your .env.local file
if you need to customize them (especially database connection settings like DATABASE_HOST and DATABASE_PORT).
The setup:magento command deploys clean Magento instance of the selected version into the defined folder. You will be asked to select PHP version if it has not been provided.
Simple usage from any location:
php /misc/apps/dockerizer_for_php/bin/console setup:magento magento-232.local 2.3.2Install Magento with the pre-defined PHP version:
php /misc/apps/dockerizer_for_php/bin/console setup:magento magento-232.local 2.3.2 --php=7.2Force install/reinstall Magento with the latest supported PHP version, without questions, erase the previous installation if the folder exists:
php /misc/apps/dockerizer_for_php/bin/console setup:magento magento-232.local 2.3.2 -n -fIMPORTANT!!! Do not enter the root password when you see the command asks for it. This is just because it works in the interactive mode and shows all input!
You will get:
- all website-related files are in the folder `/misc/apps//';
- Docker container with Apache up and running;
- MySQL database with the name, user and password based on the domain name (e.g.
magento_232_localfor domainmagento-232.local); - Magento 2 installed without Sample Data (can be installed from inside the container if needed). Web root and respective configurations are set to './pub/' folder;
- Admin Panel path is
admin- like https://example.com/admin/ - Admin Panel login/password are:
development/q1w2e3r4; - self-signed SSL certificate;
- reverse-proxy automatically configured to serve this container and handle SSL certificate;
- domain(s) added to your
/etc/hostsif not there yet (this is why your root password should be added to.env.local).
By default, container name equals to the domain you enter. See container name in existing configurations in docker-compose.yml
# here "example.com" is a container name example
docker exec -it example.com bash
php bin/magento sampledata:deploy
php bin/magento setup:upgrade
php bin/magento indexer:reindex
exitThe dockerize command copies Docker files to the current folder and updates them as per project settings. You will be asked to enter production/development domains, choose PHP version and web root folder.
Development domains can be left empty if they are not needed.
If you made a mistype in the PHP version or domain names - just re-run the command, it will overwrite existing Docker files.
Example usage in the interactive mode:
php /misc/apps/dockerizer_for_php/bin/console dockerizeExample usage without development domains:
php /misc/apps/dockerizer_for_php/bin/console dockerize --php=7.2 --prod='example.com www.example.com' --dev=''Example usage with development domains:
php /misc/apps/dockerizer_for_php/bin/console dockerize --php=7.2 --prod='example.com www.example.com example-2.com www.example-2.com' --dev='example-dev.com www.example-dev.com example-2-dev.com www.example-2-dev.com'Magento 1 example with custom web root:
php /misc/apps/dockerizer_for_php/bin/console dockerize --php=5.6 --prod='example.com www.example.com' --dev='' --webroot='/'Docker containers are not run automatically, so you can still edit configurations before running them. The file /etc/hosts is not populated automatically.
Stop composition:
docker-compose -f docker-compose.yml -f docker-compose-dev.yml downStart composition, especially after making any changed to .yml files:
docker-compose -f docker-compose.yml -f docker-compose-dev.yml up -d --force-recreateRebuild container if Dockerfile was changed:
docker-compose -f docker-compose.yml -f docker-compose-dev.yml up -d --force-recreate --buildPlease, refer the Docker and docker-compose documentation for more information on docker commands.
Manually generated SSL certificates must be places in /misc/share/ssl/. This folder is linked to Docker containers and
can be shared with VirtualBox or other virtualization tools if needed.
If the SSL certificates are not valid in Chrome/Firefox when you first run Magento then run the following command and restart the browser:
mkcert -installManually clone infrastructure and dockerizer repositories.
Since MacOS Catalina it is not possible to create folder in the filesystem root. So, all repositories should be cloned
to the ~/misc/apps/ folder instead. The folder /misc/share/ssl must be created as well. Additionally to the fourth
command to that sets your root password you should also run:
echo "
PROJECTS_ROOT_DIR=/Users/$USER/misc/apps/
SSL_CERTIFICATES_DIR=/Users/$USER/misc/share/ssl/" >> ~/misc/apps/dockerizer_for_php/.env.localAll commands must be executed taking into account this new location, e.g. like this:
cp ~/misc/apps/dockerizer_for_php/config/auth.json.sample ~/misc/apps/dockerizer_for_php/config/auth.json
php ~/misc/apps/dockerizer_for_php/bin/console setup:magento magento-232.local 2.3.2
php ~/misc/apps/dockerizer_for_php/bin/console dockerize@TODO: write how to run containers and what should be changed in the docker-compose* files on Mac