magento-sparta / magento2docker

Magento2 Docker Environment based on LAMP stack
MIT License
1 stars 3 forks source link

Magento2Docker Environment

A near to perfect Magento2 Development Environment OS agnostic, OSX focused. Key features of the project:

Pre-requirements

Directory requirements

  1. Magento2Docker as a tool can be located in any directory, e.g. ~/tools/m2d
  2. Web container will use /var/www/html as its root folder for web content.
  3. The M2D_SOURCE_DIRECTORY must point to a local path where you want to sync /var/www/html from the web container.
  4. The M2D_SOURCE_DIRECTORY must not point to symlink or it will trigger errors when Mutagen is responsible for sync process.

Installation

You can download archive of this project on Release Page.

Supported services and tools

Web Servers

DB Engines

Search Engines

DB Cache Engines

Web Cache Engines

Tools

Domains

With the default setup, Magento2Docker will use nip.io in this way: http://{LEVEL_2}.{LEVEL_1}.127.0.0.1.nip.io where:

Assume you have a multi-website Magento setup in the m246 folder; your domains can look like this:

Usage

To work with Magento2Docker you can use m2d CLI command located in bin of Magento2Docker project.

Quick Start

With Magento2Docker v3 it is super easy to start or stop containers:

# Display help
./bin/m2d --help

# To start containers:
./bin/m2d up

# To stop containers:
./bin/m2d stop

# To stop and remove containers and networks:
./bin/m2d down

# To enable service e.g. mailcatcher
./bin/m2d enable mailcatcher

# To disable service e.g. elasticsearch:
./bin/m2d disable search-engine

# To edit any .env parameter (e.g. PHP version):
./bin/m2d set M2D_WEB_SERVER_PHP_VERSION 8.1

# To display any .env parameter (e.g. search engine type):
./bin.m2d show M2D_SEARCH_ENGINE_VENDOR

# To start containers after enabling or disabling services or editing parameters:
./bin/m2d up --build

How to install a magento inside container

How to deploy dumps (backups) inside container

How to link Composer versions

Containers with PHP 7.x have Composer 1 set as default, containers with PHP 8.x have Composer 2 set as default version.

Usage:

How to Enable xDebug

The container already includes PHP xDebug extension. The xDebug extension is disabled by default because it is dramatically decrease performance.

Usage

How to use https

It requires two steps:

  1. Using local CA certificate.
  2. Adding 443 port to Apache.
  3. Changing the config in m2install to use https.

Using local CA certificate

To use https install minica: \ https://github.com/jsha/minica

After installation this library, you need to generate the wildcard certificate:

minica --domains '*.127.0.0.1.nip.io'

That will generate two files:

Copy these files to your main directory src/html.

You need to add cert.pem to your system keychains.

  1. On MacOS you can do it by opening the application Keychain Access (choose the option Open Keychain Access).
  2. Then drag and drop the file cert.pem.
  3. Double-click on the certificate minica root ca 5b360b.
  4. Expand Trust section.
  5. In When using this certificate: select Always Trust.

Adding 443 port to Apache

Check if your SSL certificate is ready to use inside the container:

$ bin/m2d go web
magento@b975beb70178:/var/www/html$ ls -la | grep cert.pem
-rw-rw-r--   1 magento magento 1184 Jan 31 12:53 cert.pem

If you see the certificate, you can change the Apache configuration. Open two files:

web-servers/apache/etc/apache2/sites-enabled/000-default.conf
web-servers/apache/etc/apache2/sites-enabled/second-level.nip.io.conf

And remove comments from the section:

#<VirtualHost *:443>
# ...
#</VirtualHost>

When you uncomment this section in both files, rebuild the container:

$ bin/m2d up --build

Now, your webserver is ready to use https connections to the port 443.

Changing the config in m2install to use https

To change the configuration to use https, you can edit or create a file:

/home/magento/.m2install.conf

Add or modify the environment variable:

HTTP_HOST=https://${CURRENT_DIR_NAME}.127.0.0.1.nip.io/

The host should start from https, not http.

Persistent folders

Any file saved out of these folders will be lost when the container is terminated

How to start using Blackfire

Blackfire Profiler is a PHP profiler and automated performance testing tool. It enables you to investigate performance issues in very simple way, just install a browser extension and press the button. You will get granular performance report to measure CPU, IO, Memory, Network, etc. Profiling with Blackfire is on-demand. This means that Blackfire adds no overhead for your end users, which makes it safe to use in production.

Get your Blackfire credentials

Blackfire provides you a free account "Hack" which allows you to run profiles on your development environment.

How to run PHPStorm inside container

Pre-requirements

docker-compose -f docker-compose.phpstorm.yml up -d --build

Todo List

Contributing

  1. Fork this repository.
  2. Create your feature branch: git checkout -b feature/my-cool-feature.
  3. Commit your changes: git commit -am 'Add some feature'.
  4. Push to the branch: git push origin feature/my-cool-feature.
  5. Submit a pull request.

Credits

Special thanks to @snosov and @tshabatyn who share their ideas and inspired to build this project.