Magento 2.4.5 Installation on ubuntu

Magento 2.4.5 Installation on Ubuntu: First, check Magento 2 requirements. Subsequently, based on the requirements, install third-party software dependencies. After that, here, we install Magento 2.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)

To begin with, run the following commands to install Apache on your system:

sudo apt update

sudo apt install apache2 

check apache version:

apache2 -v

2. PHP Installation (Version 8.1)

Next, run the following commands to install PHP on 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: Additionally, ensure that there are no extra spaces while running the above command.

3. Download Curl, GIT and composer(Version 2.2)

First, run the following commands to install curl and git on your system. Additionally, ensure these tools are up-to-date to avoid any potential issues during the installation process.

sudo apt install curl git

Next, install Composer (version 2.2) using the following command. After installation, verify the Composer version to ensure it is correctly set up and ready for use.

curl -sS https://getcomposer.org/installer | 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 https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --no-default-keyring --keyring=gnupg-ring:/etc/apt/trusted.gpg.d/magento.gpg --import
sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt 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)

Then, run the following commands to install MySQL on your system. After installation, first, configure MySQL settings in order to optimize performance and secure your database environment.

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

If MySQL is already installed on your system, first check its version using the following command. This step, therefore, ensures you are working with a compatible version for your setup and, in turn, can help avoid any version-related issues.

-> sudo mysql;

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

=> wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.11-1_all.deb
=> 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. Firstly, follow the below steps:
=> Go to the mysql shell without password:

sudo mysql -u root

=> Once you are logged in, then start creating database.

mysql> CREATE DATABASE magentodb;

7. Magento 2.4.5 Installation and Downloading on ubuntu

Go to your directory where you want to install your magento. In this case, 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. Firstly, 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, then run the command in the terminal in order to Magento 2.4.5 Installation on ubuntu.

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


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

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

After download, Start running the following command to install magento2.4.5.

->sudo bin/magento setup:install --base-url-secure=https://local.magento.com/ --db-host=localhost --db-name=magentodb --db-user=root --db-password= --admin-firstname=Admin --admin-lastname=User --admin-email=admin@example.com --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/local.magento.com.conf

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

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

Next, run below command to enable site:
-> sudo a2ensite local.magento.com.conf

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

Open gedit and update file content using following steps:
-> sudo gedit /etc/hosts
-> add content :-> 127.0.0.1 local.magento.com

Open URL: local.magento.com
To deploy Magento without sample data, you can set up the website using the standard installation process.However, If you later decide to add sample data then run the following command to deploy it. Consequently, This allows you to customize the initial setup and integrate sample data as needed.

-> bin/magento sampledata:deploy

9. Full deployment

Complete Magento 2.4.5 Installation on ubuntu 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 ..! 😉

Check more like this:

Mutation in GRAPHQL

Query in GRAPHQL