Setup Environments
Published: 2023-08-24 07:17:38

Step 1: XAMPP and Composer

### XAMPP

First of all, you need to download and install [Xampp](https://www.apachefriends.org/download.html), a simple tool helps developers to create and test their applications on a local web server.

You might wanna go with PHP 8.1 since it got pretty solid support.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a760jzji1pjwpggmvxoe.png)

Next, run set up file and proceed with all steps to install Xampp. In Select Components step, make sure to select Mysql and PHP, PHPmyadmin.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1qxqqgcpuijtiz25beq.png)



Now open XAMPP and start Apache and Mysql, green color of Apache and MySQL indicates that its been started successfully.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mo8e4z1gbjn3bvrm2ngp.png)



### COMPOSER
Now we need to install [Composer](https://getcomposer.org/download/), a tool for dependency management in PHP.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/46ywf5knu5c2362foi3l.png)

After the installation is complete, verify that Composer is installed correctly by running the following command

```
composer
```
If the installation was successful, the command should display the version of the installed Composer.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1wsx3mrq251w3wgpz6c.png)


## Step 2: PHP & MySql

### Enable PHP extensions

We need to install and enable all required PHP extensions to make the installation go smoothly

```
bcmath	ctype	curl	dom
gd	hash	iconv	intl
mbstring	openssl	pdo_mysql	simplexml
soap	xsl	zip	ext-sockets
```

Quickly open php.ini on Xampp interface with this button
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9e9uu3sa52zs829o1mv.png)

```
[PHP]
;extension=gd
;extension=intl
;extension=soap
;extension=xsl
;extension=sockets
;extension=sodium
;extension=zip
```

`Remove ; from the above lines of php.ini file`. Save the file.
The other extensions are enabled by default after we install Xampp, so we don’t need to include them here. Remember to save files before exiting.

### Configure PHP settings

In php.ini file, search and change the following values as below

```
max_execution_time=18000
max_input_time=1800
memory_limit=4G
```

These values will keep the installation go properly without interruption.

Finally, restart apache to apply php settings by click on apache Stop and Start button on XAMPP
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pob1uqz31nnalgt9pwv1.png)

## Create database for Magento 2
Before we process the installation, we have to create a database for Magento 2 website to store all settings related to products, catalog, users, store configuration….

In Xampp interface, open PHPmyadmin by clicking on Admin button to open phpmyadmin

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ja1i707nsdunhib7mjl.png)

On phpmyadmin page, click on New => type database name => click on Create to create a new database. For example, I create magento2 database here
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k7zb9sxsn1o1jwac34w9.png)

By default, Xampp does not set a password for MYSQL, so we will need to create a new root password for mysql.

On Xampp, click on Shell button to open command interface

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgeowfdo7xlhcv1lconw.png)

Next, input the following command to change mysql root password

```console
mysqladmin.exe -u root password root
```
and press Enter. I put `root` as password.

Now, to use phpmyadmin, you will also need to enter the new password. To make phpmyadmin automatically login with your new password, Open config.inc.php , to open this file, see the screenshot below

 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4nk3311u6wl3nq2rhwk.png)

And insert your new password here

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kyu8355izam4t5lb81q3.png)


Finally, restart apache to apply php settings by click on apache Stop and Start button on XAMPP

## Step 3: Elasticsearch

### Download
[Elasticsearch (https://www.elastic.co/downloads/elasticsearch)is now a required application to install Magento 2.4, the installation process will stop if there’s something wrong with Elasticsearch verification.

Next, unzip archived file at the “C:\xampp\htdocs\”

## Install and Run

Go to `\elasticsearch\bin`

Right click on `elasticsearch.bat` and select **run as administrator**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uyhgce6irjwgvwmfvw0e.png)

Leave this window running on background

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ktbnd63hefnel9qms4xg.png)

### Set Passwords 

Before we continue, we must set password for all [built-in users](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/built-in-users.html).

Open another terminal inside `C:\xampp\htdocs\elasticsearch\bin` and run this command

```
./elasticsearch-setup-passwords.bat interactive
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjfuxfnkbvgdhhcnv8s8.png)

If you encounter this error

write the following line in `/elasticsearch/elasticsearch.yml`:

```
xpack.security.enabled: true
```

### Verify

To check if Elasticsearch is running on your system, open your browser and enter the following address: `http:localhost:9200`. When prompted for login credentials, use root user `elastic` and the password you just reset.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxvyhskg0yo32fr0xf1b.png)

If you see this result page => Elasticsearch is running properly

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eyobxfvjcojgq4m27rti.png)