Hello World,

Today I will be going to explain to you how to set up Magento 2 in your local machine (Ubuntu OS).

Below are the Prerequisites which should be there in order to successfully install Magento 2 in your local machine.

  • Apache2
  • Mysql – 8.0
  • Php 7.4 (7.3+ is supported)
  • Elasticsearch 7

Please install these dependencies with the respective version which I have mentioned so that you won’t face any issues while installing.

Step1: Install Php extensions

sudo apt-get install php7.4-bcmath php7.4-curl php7.4-dom php7.4-gd php7.4-intl php7.4-mbstring php7.4-mysql php7.4-simplexml php7.4-soap php7.4-xsl php7.4-zip php7.4-sockets

Copy-paste the above command and install these extensions. If you are using other PHP versions then replace 7.4 with the appropriate version you are using.

Step2: Install Composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

The above commands will download the latest composer file and it will be moved to /usr/local/bin/composer so that you can access composer globally.

Step3: Create Magento 2.4 Composer project

 composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento24

This command will create a Magento 2.4 project in your local and this process might take some time because it needs to install all the dependencies mentioned in the composer.json file.

Step4: Database Setup in CLI

bin/magento setup:install  --base-url=http://magento24.local/  --db-host=localhost  --db-name=magento24  --db-user=root  --db-password=root@1234  --backend-frontname=admin  --admin-firstname=Sandesh  --admin-lastname=S  --admin-email=sandeshs6666@gmail.com  --admin-user=sandesh  --admin-password=sandesh@1234  --language=en_US  --currency=INR  --timezone=Asia/Kolkata  --use-rewrites=1  --elasticsearch-host localhost  --elasticsearch-port 9200  --elasticsearch-index-prefix magento_

The above-mentioned configurations can be changed as per your need. Mention the elastic search port number of your local machine.

Step 5: Setup Virtual host for the Magento url

sudo gedit /etc/apache2/sites-available/magento24.local.conf

##add the below lines in that file and save

<VirtualHost *:80>
    ServerAdmin admin@magento24.local
    ServerName magento24.local
    ServerAlias www.magento24.local
    DocumentRoot /var/www/html/magento24/pub
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

a2ensite magento24.local.conf
a2enmod rewrite

nano /etc/hosts

##add below lines

127.0.0.1       magento24.local

service apache2 restart

Step 6: Run Magento Commands.

bin/magento setup:upgrade && chmod -R 777 var/ pub/ generated/

Step 7: Check in browser

Go to any browser in your computer and hit http://magento24.local/ and you will get to see the luma home page by default.