150 Views

Magento is a powerful open-source e-commerce platform designed for online businesses. It offers multiple methods for product searching and sorting and can easily integrate with various third-party websites needed for a successful e-commerce site.

To install Magento 2.4.5, ensure you meet the following requirements:

  1. Install Apache2
  2. Install MySQL
  3. Install PHP 8.1 and its extensions
  4. Install Elasticsearch
  5. Install Composer
  6. Install Magento 2.4.5

Step 1: Install Apache2

First, we’ll install Apache2. The standard Ubuntu software repositories contain Apache. Start by updating the local package index to reflect the latest changes.

Open the terminal and run:

bash

Copy code

sudo apt update

Then, install Apache using:

bash

Copy code

sudo apt install apache2

After installation, check the Apache version:

bash

Copy code

sudo apache2ctl -v

Verify that Apache is correctly installed by entering your domain name, IP address, or 127.0.0.1 in your browser. You should see the Apache default page.

Enable auto-start for Apache:

bash

Copy code

systemctl is-enabled apache2

Step 2: Install MySQL and Create a Database for Magento

Install MySQL with the following command:

bash

Copy code

sudo apt install mysql-server

Configure password access for the MySQL root account:

bash

Copy code

sudo mysql SELECT user,authentication_string,plugin,host FROM mysql.user;

Replace ‘your_password’ with your secure password:

bash

Copy code

ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘your_password’; exit

Create a user for Magento:

bash

Copy code

mysql -u root -p SELECT user,authentication_string,plugin,host FROM mysql.user; CREATE USER ‘magento2’@’localhost’ IDENTIFIED BY ‘your_password’;

Grant the necessary permissions:

bash

Copy code

ALTER USER ‘magento2’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘your_password’; GRANT ALL PRIVILEGES ON *.* TO ‘magento2’@’localhost’ WITH GRANT OPTION; exit

Create a database for Magento:

bash

Copy code

mysql -u magento2 -p CREATE DATABASE magento2; exit

Step 3: Install PHP and Required Extensions

Magento 2.4.5 requires PHP 8.0. First, update the apt repositories:

bash

Copy code

sudo apt update

Then install PHP 8.1 and packages:

bash

Copy code

sudo apt install php8.1 libapache2-mod-php php-mysql

Verify the PHP version:

bash

Copy code

php -v

Edit the dir.conf file to prioritize index.php:

bash

Copy code

sudo nano /etc/apache2/mods-enabled/dir.conf

Install and enable mbstring:

bash

Copy code

sudo apt install php8.1-mbstring sudo phpenmod mbstring sudo a2enmod rewrite

Install the necessary PHP extensions for Magento 2.4.5:

bash

Copy code

sudo apt install php8.1-bcmath php8.1-intl php8.1-soap php8.1-zip php8.1-gd php8.1-curl php8.1-cli php8.1-xml php8.1-xmlrpc php8.1-gmp php8.1-common

Reload Apache:

bash

Copy code

sudo systemctl reload apache2

Edit the PHP configuration file (php.ini):

bash

Copy code

php -i | grep “Configuration File” sudo nano <path_of_php.ini_file>

Make the following changes:

ini

Copy code

max_execution_time=18000 max_input_time=1800 memory_limit=4G

Reload Apache again:

bash

Copy code

sudo systemctl reload apache2

Step 4: Install and Configure Elasticsearch

Elasticsearch is required for Magento 2.4. First, install OpenJDK 17:

bash

Copy code

sudo apt install openjdk-17-jdk

Import the GPG key for Elasticsearch packages:

bash

Copy code

sudo apt install curl sudo curl -sSfL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg –no-default-keyring –keyring=/etc/apt/trusted.gpg.d/magento.gpg –import

Add the Elasticsearch repository:

bash

Copy code

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

Update the package index and install Elasticsearch:

bash

Copy code

sudo apt update sudo apt install elasticsearch

Start and enable Elasticsearch:

bash

Copy code

sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service sudo systemctl start elasticsearch.service

Configure Elasticsearch by editing elasticsearch.yml:

bash

Copy code

sudo nano /etc/elasticsearch/elasticsearch.yml

Make the following changes:

yaml

Copy code

node.name: “Your Node Name” cluster.name: your application network.host: 127.0.0.1 http.port: 9200

If your server has only 1GB of RAM, update the JVM options:

bash

Copy code

sudo nano /etc/elasticsearch/jvm.options

Set the values:

ini

Copy code

-Xms256m -Xmx256m

Start Elasticsearch:

bash

Copy code

sudo nano /usr/lib/systemd/system/elasticsearch.service

Set TimeoutStartSec to 900 and reload the system:

bash

Copy code

sudo systemctl daemon-reload sudo systemctl start elasticsearch.service

Verify the installation:

bash

Copy code

curl -X GET ‘http://localhost:9200’

Step 5: Install Composer

Install Composer with the following commands:

bash

Copy code

cd ~ curl -sS https://getcomposer.org/installer -o composer-setup.php sudo php composer-setup.php –install-dir=/usr/bin –filename=composer

Check the Composer version:

bash

Copy code

composer

Step 6: Download and Install Magento 2.4.5

Navigate to the HTML folder:

bash

Copy code

cd /var/www/html

Create a Composer project:

bash

Copy code

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

Enter your Magento Marketplace username and password when prompted. These can be obtained from marketplace.magento.com.

Set permissions for the Magento directory:

bash

Copy code

cd /var/www/html/magento2 sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + sudo chown -R user_name:www-data . sudo chmod u+x bin/magento

Run the installation command:

bash

Copy code

php bin/magento setup:install –base-url=<your-domain> –db-host=localhost –db-name=magento2 –db-user=magento2 –db-password=<your-db-password-of-magento2-user> –admin-firstname=Admin –admin-lastname=Admin –admin-email=admin@admin.com –admin-user=admin –admin-password=<your-admin-password> –language=en_US –currency=USD –timezone=America/Chicago –backend-frontname=admin –search-engine=elasticsearch7 –elasticsearch-host=localhost –elasticsearch-port=9200

Update the Apache configuration:

bash

Copy code

sudo nano /etc/apache2/sites-available/codemastertechnology.magento.com.conf

Edit the file:

apache

Copy code

<VirtualHost *:80> ServerAdmin master@localhost DocumentRoot /var/www/html/magento2/pub ServerName codemastertechnology.magento.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory “/var/www/html”> AllowOverride all </Directory> </VirtualHost>

Restart Apache:

bash

Copy code

sudo systemctl restart apache2

If installing Magento locally, update the hosts file:

bash

Copy code

sudo nano /etc/hosts

Add:

hosts

Copy code

127.0.0.1 codemastertechnology.magento.com

Enable the site and run Magento commands:

bash

Copy code

sudo a2ensite codemastertechnology.magento.com.conf php bin/magento indexer:reindex && php bin/magento setup:upgrade && php bin/magento setup:static-content:deploy -f && php bin/magento cache:flush && php bin/magento module:disable Magento_TwoFactorAuth

Your Magento installation is now complete!