¡Speed Up Magento2 en Mac! – Structure
¡Speed Up Magento2 en Mac! – Structure
The objective of this tutorial is that you can optimize your productivity when you propose to work and/or program with magento2 on your MAC.
We've all had headaches when DOCKER first came out.
But why is Docker for Mac so slow?
Performance issues are related to file access. Our application has more than 14,000 files that must be synchronized between both systems. This synchronization is unnecessary in Linux environments, it is done osxfs in macOS . This causes performance issues in applications of this size.
So at the end of the tutorial you won't have to trash your MAC anymore! and you will be able to work "decently" so to speak when you decide to make online stores with magento2.
And for sure you will learn some tricks to work faster in the console (TERMINAL)
So welcome and enjoy!
Requirements
- MACOS >= 10.15 
- DOCKER DESKTOP 
- DOCKER COMPOSE 
- MAGENTO >= 2.3 
- NGINX 
- VARNISH 
- REDIS 
- ELASTICSERACH 
- MYSQL|MARIADB 
- MAGERUN2 

Steps to follow
Open Terminal
On the Mac, do one of the following:
- Click the Launchpad icon  in the Dock, type Terminal in the search field, then click Terminal. in the Dock, type Terminal in the search field, then click Terminal.
- In Finder  , open the /Applications/Utilities folder, and then double-click Terminal. , open the /Applications/Utilities folder, and then double-click Terminal.
create directories
Create a folder on our computer anywhere. In this case from the terminal we will execute the following command:
    cd && mkdir -p Projects/magento2 && cd "$_"Staying organized is always a good idea! so in this case we will create the following structure, once inside our project from the terminal we execute:
    mkdir bin config && cd $_ && mkdir php elasticsearch varnish nginxcreate files
We create the necessary files to start both our server and magento2. From the terminal we execute the following:
    touch docker-compose.yml && \ 
    touch Dockerfile && find config/php config/elasticsearch -maxdepth 0 -exec cp Dockerfile {} \; \ 
    && rm Dockerfileedit files
In order not to make the Post boring and long, you can download or clone the files from our repository.
Necessary files
- config/php/Dockerfile 
- config/php/php.ini 
- config/nginx/includes/* 
- config/ssl 
- config/nginx/backend.conf 
- config/nginx/frontend.conf 
- config/varnish/default 
- config/elasticsearch/config/elasticsearch.yml 
To compose! 
Finally, we declare the necessary services to be able to start, we edit our docker-compose.yml file
    version: '3'
    
    services:
      php:
        image: magento2/php:7.4
        build:
            -./config/php
        environment:
          COMPOSER_HOME: /var/www/html/.data/composer
          TZ: Europe/Berlin
        volumes:
          - .:/var/www/html:delegated,rw
        depends_on:
          - cache
          - elasticsearch
          - database
    
      cache:
        image: redis:latest
    
      elasticsearch:
        image: mzentrale/elasticsearch:7.10.2
        build: ./config/elasticsearch
        environment:
          discovery.type: 'single-node'
          xpack.security.enabled: 'false'
          xpack.monitoring.enabled: 'false'
          xpack.watcher.enabled: 'false'
        volumes:
          - .data/elasticsearch:/usr/share/elasticsearch/data:delegated
          - ./config/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
    
      database:
        image: mariadb/server:10.4
        environment:
          MYSQL_USER: user
          MYSQL_PASSWORD: password
          MYSQL_DATABASE: database
          MYSQL_ROOT_PASSWORD: password
          TZ: Europe/Berlin
        ports:
          - 3306:3306
        volumes:
          - .data/mysql:/var/lib/mysql:delegated
We start!!!
Once everything is ready, we have to start our project. For which we execute from the Terminal the following instruction:
    docker-compose up -dCreate help executables
Once all our containers running!. We will create the following executables, from the Terminal we execute:
    touch bin/composer && touch bin/mage && touch bin/php && touch bin/magerun2 && chmod +x bin/*The content of each file below:
bin/composer
    #!/usr/bin/env bash
    docker-compose exec -u www-data php php -d memory_limit=6G /usr/bin/composer "$@"bin/console
    #!/usr/bin/env bash
    docker-compose exec -u www-data php php -d memory_limit=-1 bin/magento "$@"bin/php
    #!/usr/bin/env bash
    docker-compose exec -u www-data php php "$@"bin/magerun2
    #!/usr/bin/env bash
    docker-compose exec -u www-data php php -d memory_limit=-1 /usr/bin/n98-magerun2.phar "$@Composer!!!!
Now it's time for composer! The first thing we need is our composer.json file, so from the terminal we execute the following:
    touch composer.jsonThe content is as follows:
    {
        "name": "magento/dev",
        "description": "Magento",
        "type": "project",
        "license": "proprietary",
        "require": {
            "magento/product-community-edition": "2.4.1"
        },
        "autoload": {
            "psr-4": {
                "Magento\\Setup\\": "setup/src/Magento/Setup/",
                "Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/"
            },
            "files": [
                "app/etc/NonComposerComponentRegistration.php"
            ],
            "exclude-from-classmap": [
                "**/dev/**",
                "**/update/**",
                "**/Test/**"
            ]
        },
        "autoload-dev": {
            "psr-4": {
                "Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/",
                "Magento\\Tools\\": "dev/tools/Magento/Tools/",
                "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",
                "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/"
            }
        },
        "minimum-stability": "dev",
        "prefer-stable": true,
        "repositories": {},
        "extra": {
            "magento-force": "override",
            "enable-patching": true,
            "patches-file": "composer.patches.json",
            "magento-deploy-ignore": {
                "magento/magento2-base": [
                    "/SECURITY.md",
                    "/.travis.yml.sample",
                    "/.github",
                    "/.gitignore",
                    "/.htaccess",
                    "/.htaccess.sample",
                    "/.php_cs.dist",
                    "/.travis.yml",
                    "/.user.ini",
                    "/auth.json.sample",
                    "/CHANGELOG.md",
                    "/COPYING.txt",
                    "/LICENSE.txt",
                    "/LICENSE_AFL.txt",
                    "/grunt-config.json.sample",
                    "/Gruntfile.js.sample",
                    "/nginx.conf.sample",
                    "/package.json.sample",
                    "/php.ini.sample",
                    "/phpserver"
                ]
            }
        },
    
        "config": {
            "preferred-install": {
                "*": "dist"
            },
            "sort-packages": true
        }
    }«Speed Up Start!»
Now we start with one of the improvements that we can do, which will allow us to perform composer downloads in parallel, which will save us a lot of time!
From the terminal we execute the following:
    bin/composer global require hirak/prestissimoOnce installed we are ready to install magento! 🙂
From the terminal we execute the following:
    bin/composer installAs you can see, first all the necessary files will be downloaded and then they will be installed in your “vendor” directory.
Finally the turn of Magento arrives! 
Once everything is installed we have to install magento. Well, to make it simple, we will do it by executing a couple of commands from the terminal. ;
First:
    find var vendor pub/static pub/media app/etc -type f -exec chmod u+w {} \; && find var vendor pub/static pub/media app/etc -type d -exec chmod u+w {} \; && chmod u+x bin/magentoThen:
    bin/mage setup:install --base-url=http://magento.dev/ \
    --elasticsearch-host=elasticsearch --elasticsearch-port=9200 \
    --db-host=database --db-name=database --db-user=user --db-password=password \
    --admin-firstname=User --admin-lastname=Admin --admin-email=admin@test.com \
    --admin-user=admin --admin-password=admin123 --language=en_US \
    --currency=EUR --timezone=Europe/Berlin --use-rewrites=1Ready friends with that we finished the first part of the tutorial, I hope you enjoyed!
If you want to see the video tutorial then I leave it below. 🙂
