{"id":982,"date":"2021-12-06T18:15:49","date_gmt":"2021-12-06T16:15:49","guid":{"rendered":"https:\/\/plumrocket.com\/learn\/?p=982"},"modified":"2025-04-03T15:00:26","modified_gmt":"2025-04-03T12:00:26","slug":"how-to-install-magento-2-4-elasticsearch-varnish-with-docker","status":"publish","type":"post","link":"https:\/\/plumrocket.com\/learn\/install-magento-24-docker","title":{"rendered":"How to Install Magento 2.4 + ElasticSearch + Varnish with Docker"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full disable_zoom\"><img loading=\"lazy\" width=\"1600\" height=\"600\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/08\/install-magento-2-4-with-docker.png\" alt=\"How to Install Magento 2.4 + ElasticSearch + Varnish with Docker\" class=\"wp-image-1517\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/08\/install-magento-2-4-with-docker.png 1600w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/08\/install-magento-2-4-with-docker-300x113.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/08\/install-magento-2-4-with-docker-1024x384.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/08\/install-magento-2-4-with-docker-768x288.png 768w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/08\/install-magento-2-4-with-docker-1536x576.png 1536w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/08\/install-magento-2-4-with-docker-1568x588.png 1568w\" sizes=\"(max-width: 1600px) 100vw, 1600px\" \/><\/figure>\n\n\n\n<p>The following guide is our second tutorial dedicated to Magento installation with Docker. Whether you are just starting with Magento or a seasoned developer, you should be able to install Magento 2.4 in less than 30 minutes after reading the next simple eight steps.<\/p>\n\n\n\n<div class=\"wp-block-cover has-background-dim\" style=\"background-color:#f5f5f5;min-height:100px\"><div class=\"wp-block-cover__inner-container\">\n<p class=\"has-text-align-center has-dark-gray-color has-text-color\">Need help with your Magento installation or any other Magento-related needs? Don&#8217;t hesitate to <a href=\"\/magento-development\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"has-inline-color has-primary-color\">reach out to us<\/span><\/a> for <span class=\"has-inline-color has-dark-gray-color\">expert development and support<\/span>.<\/p>\n<\/div><\/div>\n\n\n\n<h2>Before you begin<\/h2>\n\n\n\n<h3>Prerequisites<\/h3>\n\n\n\n<p>This tutorial requires you to have the Devilbox installed along with the Docker and Docker-compose in Ubuntu on Windows (WSL). Please follow our guide to <a href=\"\/learn\/devilbox-docker-wsl2\">install Magento on Docker with Devilbox<\/a> before you proceed to install Magento 2.4 using the next steps.<\/p>\n\n\n\n<h3>Tools<\/h3>\n\n\n\n<p>In this guide, we will be using the free <a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Visual Studio Code<\/a> editor with <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=mikestead.dotenv\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">VSCode .env syntax highlighting<\/a> extension and new <a href=\"https:\/\/www.microsoft.com\/en-us\/p\/windows-terminal\/9n0dx20hk701\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Windows Terminal<\/a>.&nbsp;<\/p>\n\n\n\n<h2>1. Configure Docker for Magento 2.4<\/h2>\n\n\n\n<p>First, it&#8217;s important to make sure that our configuration file meets all <a href=\"https:\/\/devdocs.magento.com\/guides\/v2.4\/install-gde\/system-requirements.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Magento 2.4 system requirements<\/a>. The following configuration will be set in the environment file:&nbsp;<\/p>\n\n\n\n<ul><li>Apache v2.4<\/li><li>PHP v7.4<\/li><li>MariaDB v10.4<\/li><li>ElasticSearch v7.9.3 (check the list of <a href=\"https:\/\/www.docker.elastic.co\/r\/elasticsearch\/elasticsearch-oss\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">all available versions<\/a>)<\/li><li>Varnish 6.x<\/li><li>RabbitMQ 3.8<\/li><\/ul>\n\n\n\n<p>Open Devilbox environment file:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">cd ~\/devilbox\/\nvi .env<\/code><\/pre><\/div>\n\n\n\n<p>Comment out the Nginx web server line and uncomment Apache<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">HTTPD_SERVER=apache-2.4\n#HTTPD_SERVER=nginx-stable<\/code><\/pre><\/div>\n\n\n\n<p>Make sure that PHP version 7.4 is uncommented.<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">#PHP_SERVER=7.3\nPHP_SERVER=7.4<\/code><\/pre><\/div>\n\n\n\n<p>Enable Maria DB version 10.4<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">MYSQL_SERVER=mariadb-10.4\n#MYSQL_SERVER=mariadb-10.5<\/code><\/pre><\/div>\n\n\n\n<p>We recommend disabling the \u201cxdebug\u201d PHP module to speed up your webserver and \u201cpsr\u201d PHP module to avoid errors during Magento Installation.<\/p>\n\n\n\n<p>Find and replace the \u201cPHP_MODULES_DISABLE\u201d value:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">PHP_MODULES_DISABLE=oci8,PDO_OCI,pdo_sqlsrv,sqlsrv,rdkafka,swoole,xdebug,psr<\/code><\/pre><\/div>\n\n\n\n<p>Save changes.<\/p>\n\n\n\n<h2>2. Configure ElasticSearch, Varnish, and RabbitMQ for Magento 2.4<\/h2>\n\n\n\n<p>According to Magento devdocs, ElasticSearch is required for Magento 2.4.x installation, and the other two services are recommended. However, we will install them all in this tutorial.<\/p>\n\n\n\n<p>In order to add these services to the default Devilbox stack, we need to copy the <a href=\"https:\/\/docs.docker.com\/compose\/extends\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Docker Compose Override<\/a> configurations.<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">cd ~\/devilbox\/\ncp compose\/docker-compose.override.yml-all docker-compose.override.yml<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-group pr-notice pr-notice-info\"><div class=\"wp-block-group__inner-container\">\n<p><strong>Please note<\/strong>:<\/p>\n\n\n\n<p>Optionally, you can remove extra services (like Blackfire, MailHog, Ngrok, etc.) from the new docker-compose override file (<a href=\"https:\/\/devilbox.readthedocs.io\/en\/latest\/configuration-files\/docker-compose-override-yml.html#docker-compose-override-yml\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><strong>docker-compose.override.yml<\/strong><\/a>). However, this step can be skipped.<\/p>\n<\/div><\/div>\n\n\n\n<p>Let\u2019s add new variables at the end of the Devilbox environment file:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">cd ~\/devilbox\/\nvi .env<\/code><\/pre><\/div>\n\n\n\n<p><strong><strong>Add settings for <\/strong><a href=\"https:\/\/devilbox.readthedocs.io\/en\/latest\/custom-container\/enable-elk-stack.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><strong>ELK stack<\/strong><\/a><strong> (ElasticSearch, Logstash, and Kibana):&nbsp;<\/strong><\/strong><\/p>\n\n\n\n<p><em>Copy &amp; paste these settings at the bottom of .env file.<\/em><\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\"># ELK stack general\n# See here for all versions: https:\/\/www.docker.elastic.co\/\nELK_SERVER=7.9.3\n# Elastic Search settings\nHOST_PORT_ELK_ELASTIC=9200\n# Logstash settings\nHOST_PORT_ELK_LOGSTASH=9600\n# Kibana settings\nHOST_PORT_ELK_KIBANA=5601<\/code><\/pre><\/div>\n\n\n\n<p><strong>Add settings for <a href=\"https:\/\/devilbox.readthedocs.io\/en\/latest\/custom-container\/enable-varnish.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Varnish Cache<\/a> &amp; HAProxy.<\/strong><\/p>\n\n\n\n<p><em>Copy &amp; paste these settings at the bottom of .env file.<\/em><\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\"># Varnish version to choose\n#VARNISH_SERVER=4\n#VARNISH_SERVER=5\nVARNISH_SERVER=6\n\n# Varnish settings\nVARNISH_CONFIG=\/etc\/varnish\/default.vcl\nVARNICS_CACHE_SIZE=128m\nVARNISH_PARAMS=-p default_ttl=3600 -p default_grace=3600\nHOST_PORT_VARNISH=6081\n\n# HAProxy settings\nHOST_PORT_HAPROXY=8080\nHOST_PORT_HAPROXY_SSL=8443<\/code><\/pre><\/div>\n\n\n\n<p><strong>Add settings for <a href=\"https:\/\/devilbox.readthedocs.io\/en\/latest\/custom-container\/enable-rabbitmq.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">RabbitMQ<\/a>.<br><\/strong>Copy &amp; paste these settings at the bottom of the <em>.env<\/em> file.<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\"># RabbitMQ version to choose\n#RABBIT_SERVER=3.6\n#RABBIT_SERVER=3.6-management\n#RABBIT_SERVER=3.7\n#RABBIT_SERVER=3.7-management\n#RABBIT_SERVER=latest\n#RABBIT_SERVER=management\nRABBIT_SERVER=3.8\n\nRABBIT_DEFAULT_VHOST=my_vhost\nRABBIT_DEFAULT_USER=guest\nRABBIT_DEFAULT_PASS=guest\n\nHOST_PORT_RABBIT=5672\nHOST_PORT_RABBIT_MGMT=15672<\/code><\/pre><\/div>\n\n\n\n<h2>3. Create DNS records in Windows &amp; Ubuntu<\/h2>\n\n\n\n<p>In the terminal, edit the Ubuntu hosts file:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">sudo vi \/etc\/hosts<\/code><\/pre><\/div>\n\n\n\n<p>Add this line and save changes:<\/p>\n\n\n\n<p><code>127.0.0.1 my-magento24.loc<\/code><\/p>\n\n\n\n<p>In Windows, open Notepad as administrator and edit the following file:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">c:\\Windows\\System32\\Drivers\\etc\\hosts<\/code><\/pre><\/div>\n\n\n\n<p>Add the same line as in Ubuntu and save changes:&nbsp;<\/p>\n\n\n\n<p><code>127.0.0.1 my-magento24.loc<\/code><\/p>\n\n\n\n<h2>4. Start the Docker &amp; create a new Virtual Host directory<\/h2>\n\n\n\n<p><strong>Start our docker containers in Ubuntu:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">sudo service docker start\ndocker-compose up<\/code><\/pre><\/div>\n\n\n\n<p><strong>Enter the PHP Docker container<\/strong><\/p>\n\n\n\n<p>Open a new tab in the terminal and enter the following:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">cd ~\/devilbox\/\n.\/shell.sh<\/code><\/pre><\/div>\n\n\n\n<p><strong>Create a new Virtual Host directory<\/strong><\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">mkdir my-magento24<\/code><\/pre><\/div>\n\n\n\n<h2>5. Install Magento 2.4 with Docker<\/h2>\n\n\n\n<p>Feel free to use the official <a href=\"https:\/\/devilbox.readthedocs.io\/en\/latest\/examples\/setup-magento2.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Devilbox documentation<\/a>,&nbsp; as your additional resource. We will add a couple of changes to the installation process.<\/p>\n\n\n\n<h4>Install Magento 2.4 using composer<\/h4>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">cd my-magento24\ngit clone https:\/\/github.com\/magento\/magento2\ncd magento2\ngit checkout 2.4.2\ncomposer install\ncomposer update<\/code><\/pre><\/div>\n\n\n\n<h4>Symlink webroot<\/h4>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">cd \/shared\/httpd\/my-magento24\/\nln -s magento2\/ htdocs<\/code><\/pre><\/div>\n\n\n\n<h4>Add MySQL Database<\/h4>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">mysql -u root -h 127.0.0.1 -p -e 'CREATE DATABASE my_magento24;'<\/code><\/pre><\/div>\n\n\n\n<h4>Set file permissions<\/h4>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">cd \/shared\/httpd\/my-magento24\/htdocs\nfind var generated vendor pub\/static pub\/media app\/etc -type f -exec chmod g+w {} +\nfind var generated vendor pub\/static pub\/media app\/etc -type d -exec chmod g+ws {} +\nchmod u+x bin\/magento\n<\/code><\/pre><\/div>\n\n\n\n<h4>Testing ElasticSearch:&nbsp;<\/h4>\n\n\n\n<div class=\"wp-block-group pr-notice pr-notice-info\"><div class=\"wp-block-group__inner-container\">\n<p><strong>Tip:<\/strong> <\/p>\n\n\n\n<p>If needed, the default ElasticSearch IP address can be changed in your docker-compose.override.yml file.<\/p>\n<\/div><\/div>\n\n\n\n<p>To test if your ElasticSearch is working, just open the following URL in the browser: <a href=\"http:\/\/localhost:9200\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><strong>http:\/\/localhost:9200<\/strong><\/a> or run this command in the terminal:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">curl -XGET '172.16.238.240:9200'<\/code><\/pre><\/div>\n\n\n\n<p>You should receive a similar response to this:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">{\n  \"name\" : \"elastic\",\n  \"cluster_name\" : \"docker-cluster\",\n  \"cluster_uuid\" : \"mQ7yhl5NT1O8A3tcZGDjvg\",\n  \"version\" : {\n    \"number\" : \"7.9.3\",\n    \"build_flavor\" : \"oss\",\n    \"build_type\" : \"docker\",\n    \"build_hash\" : \"c4138e51121ef06a6404866cddc601906fe5c868\",\n    \"build_date\" : \"2020-10-16T10:36:16.141335Z\",\n    \"build_snapshot\" : false,\n    \"lucene_version\" : \"8.6.2\",\n    \"minimum_wire_compatibility_version\" : \"6.8.0\",\n    \"minimum_index_compatibility_version\" : \"6.0.0-beta1\"\n  },\n  \"tagline\" : \"You Know, for Search\"\n}<\/code><\/pre><\/div>\n\n\n\n<h4>Install Magento 2.4 using command line<\/h4>\n\n\n\n<p>Let&#8217;s use Magento 2 setup install command from the <a href=\"https:\/\/devdocs.magento.com\/guides\/v2.4\/install-gde\/composer.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">official online guide<\/a>, with tiny changes :-):<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">bin\/magento setup:install \\\n--base-url=http:\/\/my-magento24.loc \\\n--db-host=127.0.0.1 \\\n--db-name=my_magento24 \\\n--db-user=root \\\n--admin-firstname=admin \\\n--admin-lastname=admin \\\n--admin-email=admin@admin.com \\\n--admin-user=admin \\\n--admin-password=admin123 \\\n--language=en_US \\\n--currency=USD \\\n--timezone=America\/New_York \\\n--use-rewrites=1 \\\n--backend-frontname=admin  \\\n--elasticsearch-host=172.16.238.240<\/code><\/pre><\/div>\n\n\n\n<p>Here&#8217;s how your Magento 2.4 frontend will look after a successful installation:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1206\" height=\"673\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2021\/10\/magento-2-4-frontend.png\" alt=\"Magento 2.4 frontend\" class=\"wp-image-1008\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2021\/10\/magento-2-4-frontend.png 1206w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2021\/10\/magento-2-4-frontend-300x167.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2021\/10\/magento-2-4-frontend-1024x571.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2021\/10\/magento-2-4-frontend-768x429.png 768w\" sizes=\"(max-width: 1206px) 100vw, 1206px\" \/><\/figure>\n\n\n\n<p>We hope you found this article useful. If you have any difficulties, we are happy to help you with our <a href=\"https:\/\/plumrocket.com\/magento-development\">Magento Development services<\/a>. Please comment and share. Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following guide is our second tutorial dedicated to Magento installation with Docker. Whether you are just starting with Magento or a seasoned developer, you should be able to install Magento 2.4 in less than 30 minutes after reading the next simple eight steps.<\/p>\n<p>In this guide, we will be using the free Visual Studio Code editor with VSCode .env syntax highlighting extension and new Windows Terminal. <\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[126],"tags":[148,154,142,158,147],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento 2.4 Installation with Docker, Elasticsearch &amp; Varnish - Magento Tutorials for Beginners &amp; Professionals<\/title>\n<meta name=\"description\" content=\"Learn how to install Magento 2.4 with Docker, configure Elasticsearch for Magento 2, and set up Varnish Cache with Haproxy.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/plumrocket.com\/learn\/install-magento-24-docker\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento 2.4 Installation with Docker, Elasticsearch &amp; Varnish - Magento Tutorials for Beginners &amp; Professionals\" \/>\n<meta property=\"og:description\" content=\"Learn how to install Magento 2.4 with Docker, configure Elasticsearch for Magento 2, and set up Varnish Cache with Haproxy.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/plumrocket.com\/learn\/install-magento-24-docker\" \/>\n<meta property=\"og:site_name\" content=\"Magento Tutorials for Beginners &amp; Professionals\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-06T16:15:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-03T12:00:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/08\/install-magento-2-4-with-docker.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts\/982"}],"collection":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/comments?post=982"}],"version-history":[{"count":37,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts\/982\/revisions"}],"predecessor-version":[{"id":2377,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts\/982\/revisions\/2377"}],"wp:attachment":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/media?parent=982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/categories?post=982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/tags?post=982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}