Magento

How To Setup Magento 2.4 Locally Using Valet Plus

By July 14, 2021 August 6th, 2021 No Comments

Magento 2.4 Catalog Search Engine Requirement

As of Magento 2.4, all installations must be configured to use Elasticsearch as the catalog search solution. Elasticsearch provides the following benefits:

  • Quick and advanced searches on products in the catalog
  • Support for multiple languages
  • Support for stop words and synonyms
  • Shoppers are not disrupted while Elasticsearch reindexes
  • Accurate, performant, and scalable
  • Works well out of the box
  • Easy to horizontally scale
  • Supports real-time data and analysis
  • Can be used as a document-oriented data-store
  • Applications in framework beyond search, including reporting, personalization, performance, and storage Supported versions

Message from Magento Regarding Compatibility :

You must install and configure Elasticsearch 7.6.x before upgrading to Magento 2.4.x.Magento 2.4.x is tested with Elasticsearch 7.6.x only. You can use other 7.x versions at your discretion, but we recommend using the tested version of Elasticsearch. Magento does not support Elasticsearch 2.x, 5.x, and 6.x.

Import Note: We have been able to use Magento 2.4 locally using ElasticSearch 6.8 and this documentation is based on that ElasticSearch version. At the time of writing this we are not able to install a version higher than 6.8

Configuring Elasticsearch

Valet Plus Comes with Elasticsearch by default . To configure Elasticsearch you have to do some customization. See Below :

Run the commands below to open up your Elastic Search configuration in nano. You can use another editor like Vim or Atom if you like.

sudo nano /usr/local/etc/nginx/valet/elasticsearch.conf 

Add the configurations below to your file.

server {
   listen 80;
   server_name elasticsearch.test www.elasticsearch.test;
   charset utf-8;
   client_max_body_size 128M;
   location / {
       chunked_transfer_encoding on;
       proxy_set_header X-NginX-Proxy true;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       proxy_http_version 1.1;
       proxy_redirect off;
       proxy_buffering off;
       proxy_pass http://localhost:9200;
   }
}

To Install the latest version of ElasticSearch follow the instructions below:

brew uninstall [email protected]< existing/older version> 
valet elasticsearch install 

The second command installs the latest version of Elasticsearch available from brew.

If for some reason “valet elasticsearch install” it throws an exception. Please run the following :

valet use es 6.8

Installing PHP 7.4 (optional)

Install php 7.4 if needed  running the command below :

valet use 7.4 && valet restart

Testing Elasticsearch

For testing , use this documentation.

Configuring Nginx

Create a file at the path ~/.valet/Nginx/all.conf

Add the configurations below inside it

proxy_buffer_size   4096k;
proxy_buffers   128 4096k;
proxy_busy_buffers_size   4096k;

Append the text below to /usr/local/etc/nginx/fastcgi_params

fastcgi_buffer_size 4096k;
fastcgi_buffers 128 4096k;
fastcgi_busy_buffers_size 4096k;

Restart Valet Plus

valet restart

Installing Magento 2.4

Download Magento 2.4 from Composer or using this link.

After Downloading it extract the file in your Valet Parked Directory rename the directory to “magento-24”

Magento 2.4 doesn’t support a GUI installation so you have to run the command below in the root directory.

php bin/magento setup:install --base-url=http://magento-24.test/ \--db-host=localhost --db-name=MagentoDB --db-user=root --db-password=root \--language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 \--search-engine=elasticsearch7 --elasticsearch-host=127.0.0.1 \ 
--elasticsearch-port=9200

If you want to configure your admin credentials in the same step use the command below :

php bin/magento setup:install --base-url=http://magento-24.test/ \--db-host=localhost --db-name= MagentoDB --db-user=root --db-password=root\--admin-firstname=Magento --admin-lastname=User [email protected] \--admin-user=admin --admin-password=admin123 --language=en_US \--currency=USD --timezone=America/Chicago --use-rewrites=1 \--search-engine=elasticsearch7 --elasticsearch-host=127.0.0.1\--elasticsearch-port=9200
  • –base-url: base url of project.
  • –db-host: Host name of database.
  • –db-name: Database name.
  • –db-user: Username of database.
  • –db-password: Password of database if you have.
  • –admin-firstname: Firstname of magento backend admin.
  • –admin-lastname: Lastname of magento backend admin.
  • –admin-email: Email address for magento backend admin.
  • –admin-user: Username for magento backend admin.
  • –admin-password: Password for magento backend admin.
  • –language: Default language of your store.
  • –currency=USD: Default currency of your store.
  • –timezone: Default timezone of your store.
  • –use-rewrites:1means you use web server rewrites for generated links in the storefront and Admin. 0disables the use of web server rewrites. This is the default.
  • –search-engine: The version of Elasticsearch to use as the search engine. Possible values areelasticsearch7,elasticsearch6, andelasticsearch5. The default iselasticsearch7. Elasticsearch 5 has been deprecated and is not recommended.
  • –elasticsearch-host: The host name or IP address where Elasticsearch is running. The default is localhost.
  • –elasticsearch-host: The host name or IP address where Elasticsearch is running.

After running this command you should see a message similar to the following display to indicate a successful installation:

Post installation file permissions check...
For security, remove write permissions from these directories: '/var/www/html/magento2/app/etc'
[Progress: 274 / 274]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Admin Panel URI: /admin_puu71q

The Magento software is installed in the magento2 directory relative to the web server docroot on localhost and the path to the Magento Admin is admin; therefore:

Your storefront URL is http://magento-24.test

The database server is on the same host as the web server.

The database name is magento, and the username and password are both magento.

Uses server rewrites.

The Magento administrator has the following properties:

First and last name are Magento User.

Username is admin and the password is admin123.

E-mail address is [email protected]

Default language is en_US (U.S. English).

Default currency is U.S. dollars.

Default time zone is U.S. Central (America/Chicago).

Elasticsearch 7 is installed on es-host.example.com and connects on port 9200.

Leave a Reply