Running Magento 2.4.0 on Valet+

Valet Plus+, Magento 2

As just about everyone i wanted to play with Magento 2.4.0 as it came out. Just do a composer create-project, wait some time, and run bin/magento install, right? Noooope. Magento will fail with an ElasticSearch error. No problem, Valet+ supports ElasticSearch, so just install it. You check the wiki, Valet+ supports ElasticSearch 6.8. Hmm, Magento requires version 7.6. There is an open PR, but no official release. Are there any other solutions?

Docker to the rescue

You can install ElasticSearch directly onto your system but that might bite other projects you have running. Luckily for us, it is quite easy to get ElasticSearch up and running. First of all, make sure you don't have any existing ElasticSearch instances running:

brew services stop elasticsearch

You can check if it is stopped by opening http://localhost:9200 in your browser, you shouldn't get a response.

Next, add this docker-compose.yml file to your project:

version: '2.2'
services:
elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
    container_name: elasticsearch
    environment:
        - cluster.name=docker-cluster
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        - node.name=node-1
        - cluster.initial_master_nodes=node-1
    ulimits:
        memlock:
            soft: -1
            hard: -1
    volumes:
        - esdata:/usr/share/elasticsearch/data
    ports:
        - "9200:9200"
    networks:
        - esnet
kibana:
    image: docker.elastic.co/kibana/kibana:7.6.2
    container_name: kibana
    environment:
        - ./kibana.yml:/usr/share/kibana/config/kibana.yml
    ports:
        - "5601:5601"
    networks:
        - esnet
volumes:
esdata:
    driver: local
networks:
esnet:

Then start the containers by running this command:

docker-compose up -d

Downloading and starting the container takes a moment, but it also takes a few minutes for ElasticSearch to start up, so give it some time. When everything is started you can check if it is working again by opening http://localhost:9200 in your browser again. You should get a response similar to this:

{
  name: "node-1",
  cluster_name: "docker-cluster",
  cluster_uuid: "zuOL47PLSRqM3WzUHEyREg",
  version: {
	  number: "7.6.2",
	  build_flavor: "default",
	  build_type: "docker",
	  build_hash: "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
	  build_date: "2020-03-26T06:34:37.794943Z",
	  build_snapshot: false,
	  lucene_version: "8.4.0",
	  minimum_wire_compatibility_version: "6.8.0",
	  minimum_index_compatibility_version: "6.0.0-beta1"
  },
  tagline: "You Know, for Search"
}

Kibana

Next to ElasticSearch this docker-compose.yml also adds Kibana, a tool that can be used to discover the contents of your ElasticSearch installation. You can view it by navigating to http://localhost:5601. If Kibana asks for an index pattern, enter magento2_product*. After going through the installation wizard you can view your database contents by clicking the Discover tab.

Michiel Gerritsen
About the author

Michiel Gerritsen

Connect on LinkedIn

Founder of Control Alt Delete, a Magento agency specialised in testing, CI/CD and checkout integrations. Working with Magento since 2015, and board member of Mage-OS.

Missing anything?
What are you missing? X
Thank you for your feedback!