# Installation guide for Magento 2 (Adobe Commerce) with Docker ## What is Magento 2? Magento is an open-source e-commerce platform that allows businesses to create and manage online stores. It was first released in 2008 and has since become one of the most popular and powerful solutions in the e-commerce market. After Adobe's acquisition of Magento in June 2018, the platform has been promoted by Adobe under the name "Adobe Commerce." However, it is important to note that the community and users continue to use the term "Magento 2" to refer to this specific version of the platform. The reason people call it "Magento 2" is because this version represents a significant upgrade and technical improvement over Magento 1. Magento 2 offers a range of enhancements and new features compared to its predecessor, such as a more modular architecture, an improved admin interface, better performance and scalability, and increased ease of use. Although Adobe has promoted the platform as "Adobe Commerce" to highlight its integration within the Adobe solutions ecosystem, the designation "Magento 2" is still widely used by the community and users to refer to this specific version of the platform. This is due to the familiarity and established user base that has been built around the "Magento 2" brand over the years. Official Page Magento2 [EE.UU](https://business.adobe.com/products/magento/magento-commerce.html)/ [SPAIN](https://business.adobe.com/es/products/magento/magento-commerce.html) ## Magento 2 Installation with Docker For the installation of Magento 2, we will use Docker. ### What is Docker? Docker is an open-source platform for creating, deploying, and running applications in isolated and lightweight containers. It allows packaging everything needed to run an application into a container, including code, dependencies, and configurations. It simplifies the development and deployment of applications by providing standardized and reproducible environments. It enables running multiple applications on the same server without conflicts. It offers tools to automate the building, deployment, and scaling of applications in different environments. It leverages operating system-level virtualization without the cost and complexity of traditional virtual machines. It enables faster development, application portability, and more efficient resource utilization. It facilitates collaboration among developers and avoids compatibility issues. It allows working in isolated environments, avoiding conflicts between systems. It is widely used in the development and deployment of modern applications. ## Docker Installation on an Ubuntu Distribution: Previous [requirements](https://docs.docker.com/desktop/install/ubuntu/) for a successful Docker installation. Uninstall the tech preview or beta version of Docker Desktop for Linux. Run: ``` sudo apt install gnome-terminal ``` Uninstall the tech preview or beta version of Docker Desktop for Linux. Run: ``` sudo apt remove docker-desktop ``` For a complete cleanup, remove configuration and data files at $HOME/.docker/desktop, the symlink at /usr/local/bin/com.docker.cli, and purge the remaining systemd service files. ``` rm -r $HOME/.docker/desktop sudo rm /usr/local/bin/com.docker.cli sudo apt purge docker-desktop ``` #### Install Docker Desktop Recommended approach to install Docker Desktop on Ubuntu: **1.Set up [Docker’s package](https://docs.docker.com/engine/install/ubuntu/#set-up-the-repository) repository.** #### Set up the repository * Update the apt package index and install packages to allow apt to use a repository over HTTPS: ``` sudo apt-get update sudo apt-get install ca-certificates curl gnupg ``` * Add Docker’s official GPG key: ``` sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg ``` * Use the following command to set up the repository: ``` echo \ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ``` #### Install Docker Engine * Update the apt package index: ``` sudo apt-get update ``` * Install Docker Engine, containerd, and Docker Compose. ``` sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin ``` * Verify that the Docker Engine installation is successful by running the hello-world image. ``` sudo docker run hello-world ``` **2. Download latest [DEB package](https://desktop.docker.com/linux/main/amd64/docker-desktop-4.19.0-amd64.deb?utm_source=docker&utm_medium=webreferral&utm_campaign=docs-driven-download-linux-amd64).** **3. Install the package with apt as follows:** ``` sudo apt-get update sudo apt-get install ./docker-desktop-<version>-<arch>.deb ``` ***Please replace <version> and <arch> with the correspoding values, for example: arch: amd64 version: 4.19.0 For example: sudo apt-get install ./docker-desktop-4.19.0-amd64.deb If something fails, please open terminal where the downloaded file is and execute the command again*** > *Note > > At the end of the installation process, apt displays an error due to installing a downloaded package. You can ignore this error message. ``` N: Download is performed unsandboxed as root, as file '/home/user/Downloads/docker-desktop.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied) ``` ### Launch Docker Desktop ``` systemctl --user start docker-desktop ``` After you’ve successfully installed Docker Desktop, you can check the versions of these binaries by running the following commands: ``` docker compose version ``` ``` docker --version ``` ``` docker version ``` ## Install Composer You will need to install composer, but before installing it, check if you already have composer * > (You should have Composer installed on the academy laptops.) Run the following command to check if you already have composer: ``` composer ``` ## Download Magento2 [Magento2](https://www.mageplaza.com/download-magento/#download-tar-gz) version 2.4.4-p3 ## Create an account on marketplace magento [Site to create your account](https://marketplace.magento.com/) * Go to "My profile" * Go to "Acces Keys" * Create A new Access Key and create a new key --- Decide a location on your local machine that you want to put the website files to live. Please open a command line terminal window. Please replace the placeholder path with the final path where you will install Magento(***path/to/magento***), before copying and pasting the code below. * Note: Before proceeding to the next step, remember to extract the previously downloaded Magento2 file into the desired folder where your Magento2 files will be located (we can call this route ***path/to/magento***) ``` cd /path/to/magento && \ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition ``` * You may encounter an error if you don't have the php-soap extension To solve this, execute the next command line: ``` sudo apt-get install php-soap ``` Finally, select a domain name that you would like to access the site, then add it to your host’s file. * Note: Replace "**local.domain**" with the name that you want(This will be the domain you will use to access Magento2) ``` sudo -- sh -c "echo '127.0.0.1 local.domain.com' >> /etc/hosts" ``` ## Generate a docker-compose.yml file 1. You need to select a place to put your Docker configuration files. Refer this location as **/path/to/docker**. 1. Next, open a new document. 1. Now, click on “copy” and paste the following code into a new file: ``` version: '3' services: web: image: webdevops/php-apache-dev:8.1 container_name: web restart: always user: application environment: - WEB_ALIAS_DOMAIN=mimagento2.com - WEB_DOCUMENT_ROOT=/app/pub - PHP_DATE_TIMEZONE=EST - PHP_DISPLAY_ERRORS=1 - PHP_MEMORY_LIMIT=2048M - PHP_MAX_EXECUTION_TIME=300 - PHP_POST_MAX_SIZE=500M - PHP_UPLOAD_MAX_FILESIZE=1024M volumes: - /home/reboot/code/downloadMagento:/app:cached ports: - "80:80" - "443:443" - "32823:22" links: - mysql - opensearch mysql: image: mariadb:10.2 container_name: mysql restart: always ports: - "3307:3306" environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=magento volumes: - db-data:/var/lib/mysql phpmyadmin: container_name: phpmyadmin restart: always image: phpmyadmin/phpmyadmin:latest environment: - MYSQL_ROOT_PASSWORD=root - PMA_USER=root - PMA_PASSWORD=root ports: - "8080:80" links: - mysql:db depends_on: - mysql opensearch: image: opensearchproject/opensearch:latest container_name: opensearch restart: always environment: - cluster.name=opensearch-cluster - discovery.type=single-node ports: - "9200:9200" - "9300:9300" volumes: - opensearch-data:/usr/share/opensearch/data volumes: db-data: external: false opensearch-data: external: false ``` 4. Remember to save the new file as /path/to/docker/docker-compose.yml. ### Ready to start with your virtual machine 1. In this step, you still need to open your terminal to /path/to/docker. 2. It’s time to fire up your virtual machine. As soon as you spin up, it takes some minutes so that Dockers can download the images. After that, spin-ups in the future will take a few seconds. ``` docker-compose up -d --build ``` * You may encounter an error if you don't have docker-compose installed. To solve this, execute the next command line: ``` sudo apt install docker-compose ``` 3. Please make sure that everything is set up and run as per your plan. Then, you need to go to 127.0.0.1.8080 in your web browser, and you will see phpMyAdmin. Congrats, it’s successful if you can see it. ## Install Magento 2 in detail It’s time to do the most important step. Let’s get going! 1. Go to your magento folder location and open the terminal 2. Go to /app/etc and modify the file env.php ``` sudo nano env.php ``` The file env.php might not exist, in that case create it and put this inside it: ``` <?php return [ 'remote_storage' => [ 'driver' => 'file' ], 'backend' => [ 'frontName' => 'admin' ], 'queue' => [ 'consumers_wait_for_messages' => 1 ], 'crypt' => [ 'key' => '0265b3431151b79face8630e265a65cc' ], 'db' => [ 'table_prefix' => '', 'connection' => [ 'default' => [ 'host' => 'mysql', 'dbname' => 'magento', 'username' => 'root', 'password' => 'root', 'model' => 'mysql4', 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', 'driver_options' => [ 1014 => false ] ] ] ], 'system' => [ 'default' => [ 'catalog' => [ 'search' => [ 'engine' => 'opensearch7', 'host' => '0.0.0.0', 'port' => '9200' ] ] ] ], 'resource' => [ 'default_setup' => [ 'connection' => 'default' ] ], 'x-frame-options' => 'SAMEORIGIN', 'MAGE_MODE' => 'default', 'session' => [ 'save' => 'files' ], 'cache' => [ 'frontend' => [ 'default' => [ 'id_prefix' => 'f53_' ], 'page_cache' => [ 'id_prefix' => 'f53_' ] ], 'allow_parallel_generation' => false ], 'lock' => [ 'provider' => 'db', 'config' => [ 'prefix' => '' ] ], 'directories' => [ 'document_root_is_pub' => true ], 'cache_types' => [ 'config' => 1, 'layout' => 1, 'block_html' => 1, 'collections' => 1, 'reflection' => 1, 'db_ddl' => 1, 'compiled_config' => 1, 'eav' => 1, 'customer_notification' => 1, 'config_integration' => 1, 'config_integration_api' => 1, 'full_page' => 1, 'config_webservice' => 1, 'translate' => 1 ], 'downloadable_domains' => [ 'mimagento2.com' ], 'install' => [ 'date' => 'Fri, 19 May 2023 11:49:55 +0000' ] ]; ``` 4. Access your command line that contains your Docker web:(***remember to open the terminal inside the folder where you had your docker-compose.yml file***) ``` docker exec -it web bash ``` 5. Execute the next command line: ``` chmod -R 777 /app ``` 6. Please go ahead to the web document root: ``` cd /app ``` 7. Install Magento 2. Remember copying and pasting the following command into the Docker terminal. Note that **you must replace the values on lines 2-6** with your own details. **On lines 7-8, please replace the placeholder domain with your created domain name before**. ``` php bin/magento setup:install \ --admin-firstname=John \ --admin-lastname=Doe \ --admin-email=johndoe@example.com \ --admin-user=admin \ --admin-password='SomePassword123' \ --base-url=https://local.domain.com \ --base-url-secure=https://local.domain.com \ --backend-frontname=admin \ --db-host=mysql \ --db-name=magento \ --db-user=root \ --db-password=root \ --use-rewrites=1 \ --language=en_US \ --currency=USD \ --timezone=America/New_York \ --use-secure-admin=1 \ --admin-use-security-key=1 \ --session-save=files \ --use-sample-data ``` 8. Navigate to your website at `https://local.domain.com` or whatever domain you select. You need to spend some minutes loading the page when you access the website for the first time. The reason for this is that nothing is cached and the Magento system will automatically create files when loading the pages. Don’t worry, as the loading process will be quicker next time. Additionally, as the web container applies **a self-signed SSL certificate**, you can get a security alert from the browser when visiting the URL for the first time. 9. Congratulations! You succeed in setting up Magento 2 on Docker. Please remember that you can repeat this process for other projects through our step-by-step guide. :smiley: