Magento 2.4.5 Installation on ubuntu

First, check magento2 requirements. Based on the requirements, install third-party software dependencies. here, we install magento2.4.5 with sample data.

Here’s a step by step procedure will probably save you a headache. let’s start…

1. Apache Installation (Version 2.4)
run following commands to install Apache in your system:

sudo apt update

sudo apt install apache2 

check apache version:

apache2 -v

2. PHP Installation (Version 8.1)
run following commands to install PHP in your system:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.1 php8.1-common php8.1-mysql php8.1-gmp php8.1-curl php8.1-intl php8.1-mbstring php8.1-xmlrpc php8.1-gd php8.1-xml php8.1-cli php8.1-zip php8.1-soap php8.1-bcmath php8.1-fpm

Note: Make sure while running the above command, there is no any extra space.

3. Download Curl, GIT and composer(Version 2.2)
run following commands to install curl, git in your system:

sudo apt install curl git

Now, install composer (version 2.2) using following command:

curl -sS | sudo php -- --install-dir=/usr/local/bin --filename=composer

4. Elasticsearch Installation and configuration(Version 7.17)
Follow the below command one by one:

sudo apt install curl
sudo curl -sSfL | sudo gpg --no-default-keyring --keyring=gnupg-ring:/etc/apt/trusted.gpg.d/magento.gpg --import
sudo sh -c 'echo "deb stable main" > /etc/apt/sources.list.d/elastic-7.x.list'
sudo chmod 666 /etc/apt/trusted.gpg.d/magento.gpg
sudo apt update
sudo apt install elasticsearch

5. MySQL Installation (Version 8.0)
run following commands to install MySql in your system:

-> sudo apt update
-> sudo apt install mysql-server

If you have MySql in your system. Then, first check the version of it using following command.

-> sudo mysql;

If you are using older version then requirement. Then, upgrade it using the Following command in terminal.

=> wget -c
=> sudo dpkg -i mysql-apt-config_0.8.11-1_all.deb
=> sudo apt-get update
=> sudo apt-get install mysql-server

Now, you have required MySql version in your system.

6. Create DB for Magento
After installing MySql, create a new DataBase and its user for magento website. follow the below steps:
=> Go to the mysql shell without password:

sudo mysql -u root

=> Once you are logged in, create database:

mysql> CREATE DATABASE magentodb;

7. Downloading and Installing Magento 2.4.5
Go to your directory where you want to install your magento. Here, we are installing it in /var/www/html directory using below command:
-> cd /var/www/html
We are going to install Magento 2.4.4 using composer. You will require an access key for the next step.

Create an account at magento MarketPlace and create an access key. Once you have an access key, run the command in terminal to download magento2.4.5.

-> sudo composer create-project --repository-url= magento/project-community-edition=2.4.5 magento2.4.5

This will ask username and password. you have your access key which you taken from market place. Enter ,
username = public key
password = private key

Now, you have a magento2.4.5 folder in /var/www/html directory. go to the magento2.4.5 directory :
-> cd magento2.4.5

After download, run the following command to install magento2.4.5.

->sudo bin/magento setup:install --base-url-secure= --db-host=localhost --db-name=magentodb --db-user=root --db-password= --admin-firstname=Admin --admin-lastname=User --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1

Give the permission using below command:

-> sudo chown -R www-data:www-data /var/www/html/magento2.4.5
-> sudo chmod -R 755 /var/www/html/magento2.4.5

8. Configuring Apache for Magento:
Run following command to create virtual host:

-> sudo nano /etc/apache2/sites-available/

Now, add file content in the space that you see.

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/magento2.4.5
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html/magento2.4.5">
AllowOverride all

Next, run below command to enable site:
-> sudo a2ensite

Restart Apache2 using following command:
-> sudo systemctl restart apache2

Open gedit and update file content using following steps:
-> sudo gedit /etc/hosts
-> add content :->

Open URL:
which open magento website without sample data. to deploy sample data run following command:
-> bin/magento sampledata:deploy

9. Full deployment
complete installation using following commands:

-> bin/magento setup:upgrade
-> bin/magento setup:di:compile
-> bin/magento setup:static-content:deploy -f
-> bin/magento cache:flush
-> bin/magento cache:clean
-> bin/magento indexer:reindex

Happy Coding ..! 😉