# Installation


# Requirements

Elasticsearch Basic

There are multiple Elasticsearch versions and licenses, see the subscriptions page (opens new window). Rapidez requires at least the basic version which is free but not always installed by default. Make sure you use the "full" or "non-OSS" version otherwise you'll get "no handler for type flattened" errors while indexing.

# Create your first project

composer create-project rapidez/rapidez rapidez
php artisan rapidez:install

Credentials

Add the url and database credentials from your Magento 2 installation to the .env. Have a look at the configuration docs for all options.

yarn
yarn run prod
php artisan storage:link
php artisan rapidez:validate
php artisan rapidez:index

Use your favorite webserver (we like Valet+ (opens new window) on macOS) or use Laravel's built-in development server:

php artisan serve

See it in the browser! 🚀

Note

The rapidez/rapidez repository contains a fresh Laravel installation with the Rapidez Core and some other packages installed to give you a good start. If you have an existing project or want to start from scratch you can install the Rapidez packages yourself. Just have a look at the composer.json

Product image speed

The first time product images will load slowly as they are resized on the fly. Have a look at the Image Resizer (opens new window) package to read how this is working.

# CORS

# Magento

Rapidez is making AJAX requests to the Magento API which requires CORS to be opened.

# Elasticsearch

If you're using your own Elasticsearch installation you've to open CORS in elasticsearch.yml and restart Elasticsearch. An example can be found in the the project: elasticsearch.yml (opens new window). That configuration is used when you're using Elasticsearch from the Docker Compose config (opens new window).

# Flat tables

The flat tables need to be enabled in Magento because Rapidez needs them to easily query for products and categories. You can follow this guide (opens new window) to enable it. After that you need to make sure the Storefront Properties (opens new window) are configured correctly for all your attributes, you can validate the settings with php artisan rapidez:validate. If the result is that some attributes are not in the flat table you can enable "Used in Product Listing" on them and validate again.

WARNING

All attributes with "Used in Product Listing" enabled will be indexed into Elasticsearch. As this index is publicly available you should be careful with attributes which contain "sensitive" data like for example sale counts.

Finally when your settings are validated you should run the Magento indexes (opens new window). For example with bin/magento indexer:reindex from your Magento installation.

Row size too large

If you run into "row size too large" MySQL errors when indexing in Magento then you could install the magento2-optimizeflattable (opens new window) module. If you're still running into errors you should disable the "Used in Product Listing" on "Text field" and "Multiple Select" attributes, one by one until the index is running fine.

# Multistore

When you've setup multiple stores in Magento then Rapidez needs to know which store to show. Rapidez listens to the MAGE_RUN_CODE like Magento does. So just set that variable from your webserver.

With Nginx you could use a map, for example:

map $http_host $MAGE_RUN_CODE {
    default default_store_code;
    second-store.com second_store_code;
    thrid-store.com third_store_code;
}

And pass that to PHP-FPM:

fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;

# Demo Magento 2 webshop

If you do not have a Magento 2 installation yet, you want to test Rapidez or like to develop with a fresh Magento 2 installation you can use a Magento 2 and Elasticsearch installation in a Docker container.

TIP

Make sure Docker can use at least 4GB of memory!

docker-compose up -d
docker exec rapidez_magento magerun2 indexer:reindex

Edit the .env

MAGENTO_URL=http://localhost:1234
DB_PORT=3307
DB_DATABASE=magento
DB_USERNAME=magento
DB_PASSWORD=password