Setting up and configuring a local server for Magento 2 can be a daunting task for developers. However, with the Reward tool, this process is simplified, making it easy to set up Magento 2 development environments on your local computer.
During my technical session titled “Rewardenv - A better CLI tool to create dev environment” at Meet Magento India 2023, I highlighted how Reward can streamline this setup process for developers.
Table of contents
Open Table of contents
- What is Reward?
- Steps to Install Magento 2.4.7 with Sample Data
- Conclusion
What is Reward?
Reward is an environment management tool designed to streamline the setup and configuration of various development environments, including Magento 2. It significantly reduces the time and effort required to get a Magento 2 environment up and running.
Steps to Install Magento 2.4.7 with Sample Data
Let’s walk through the steps to install Magento 2.4.7 with sample data using Reward.
Step 1: Prerequisite
Ensure that Reward is already installed on your local computer.
Step 2: Create a directory for your Magento 2 project
mkdir -p /var/www/html/m247
cd /var/www/html/m247
Step 3: Initialize the Reward .env file
This step creates the .env file that we can use to configure the environment, including settings like PHP, Varnish, and Composer versions.
reward env-init m247
Step 4: Edit and configure the .env file
Let’s edit the .env file and disable Varnish, Redis, and RabbitMQ by updating the following environment variables for a local development environment. You can keep them enabled if you prefer.
Update the following environment variables:
REWARD_ENV_NAME=m247
REWARD_ENV_TYPE=magento2
REWARD_WEB_ROOT=/
TRAEFIK_DOMAIN=m247.test
TRAEFIK_SUBDOMAIN=
TRAEFIK_EXTRA_HOSTS=
REWARD_DB=true
REWARD_ELASTICSEARCH=false
REWARD_OPENSEARCH=true
REWARD_OPENSEARCH_DASHBOARDS=false
REWARD_VARNISH=false # change to false
REWARD_RABBITMQ=false # change to false
REWARD_REDIS=false # change to false
REWARD_MERCURE=false
ELASTICSEARCH_VERSION=7.16
OPENSEARCH_VERSION=1.2
MARIADB_VERSION=10.4
NODE_VERSION=16
PHP_VERSION=8.2
RABBITMQ_VERSION=3.9
REDIS_VERSION=6.0
VARNISH_VERSION=7.0
COMPOSER_VERSION=2.2.22
REWARD_SYNC_IGNORE=
REWARD_ALLURE=false
REWARD_SELENIUM=false
REWARD_SELENIUM_DEBUG=false
REWARD_BLACKFIRE=false
REWARD_SPLIT_SALES=false
REWARD_SPLIT_CHECKOUT=false
REWARD_TEST_DB=false
REWARD_MAGEPACK=false
BLACKFIRE_CLIENT_ID=
BLACKFIRE_CLIENT_TOKEN=
BLACKFIRE_SERVER_ID=
BLACKFIRE_SERVER_TOKEN=
XDEBUG_VERSION=.env
Step 5: Set up the Magento composer keys
reward env up -- php-fpm
reward shell
composer config -a -g http-basic.repo.magento.com yourpublickey yourprivatekey
exit
Step 6: Install and bootstrap the Magento 2 environment
reward bootstrap --disable-tfa --full --magento-version=2.4.7
Explanation of the parameters
--disable-tfa: Disables Magento two-factor authentication, which is enabled by default.--full: Installs Magento with sample data. You can skip this if you don’t want to include sample data, it can be installed later if needed.--magento-version: Specifies the Magento version to install.
Additional useful parameters when setting up an existing project
--skip-admin-user: Skip creation of admin user.--skip-composer-install: Skip running composer install if the vendor directory is already present.--reset-admin-url: Set admin/url/use_custom and admin/url/use_custom_path configurations to 0.
Step 7: Check the installation output
Once the reward bootstrap command completes successfully, you will see output similar to the following:
...
...
full_page
config_webservice
translate
INFO ...cache flushed.
INFO ...Magento installed successfully.
INFO Base Url: https://m247.test
INFO Backend Url: https://m247.test/admin
INFO Admin user: localadmin
INFO Admin password: 0UvA2GisxYjIkXKn
INFO ...bootstrap process finished.
The Base URL is the Magento frontend link, and the Backend URL is the Magento admin URL. It creates the default admin user with username localadmin with a randomly generated password for admin login.
Conclusion
As demonstrated, installing a fresh Magento 2 environment with Reward is straightforward and can be completed within a few minutes. This tool greatly simplifies the process, making it much more efficient for developers.
For more details, refer to the Reward documentation.