itsmeit.bizitsmeit.biz
  • Home
  • Windows
    • Windows Software
  • Ubuntu & Linux
    Ubuntu & Linux
    The top blog articles on Ubuntu and Linux, featuring valuable tips and tricks, empower you to master these operating systems and enhance your experience.
    Show More
    Top News
    How to Remove Ubuntu Dual boot Windows 11 UEFI and Legacy
    How to Remove Ubuntu Dual boot Windows 11 UEFI and Legacy
    November 10, 2023
    How to install php7.4 on Ubuntu & Config php7.4-fpm - itsmeit.biz
    How to install php7.4 on Ubuntu 22.04 | 20.04 LTS
    November 10, 2023
    Install Ubuntu dual boot Windows 11 | 10 UEFI And Legacy
    Install Ubuntu dual boot Windows 11 | 10 UEFI & Legacy
    November 10, 2023
    Latest News
    How to install Composer on Ubuntu 20.04 | 22.04 & Linux
    November 13, 2023
    How to Configure Redis Cache to Speed ​​Up WordPress Site
    November 15, 2023
    Install Ibus-bamboo or Ibus-unikey for Accented Letters on Ubuntu 22.04
    November 11, 2023
    How to install MariaDB on Ubuntu 22.04, 20.04 and Debian
    November 11, 2023
  • Web developer
    • Wordpress Theme
      • Blog News
      • Fashion Theme
      • Theme Elementor
      • WooCommerce Theme
    • Wordpress Plugin
    • Magento Developer
Reading: How to install Magento 2.4 on Ubuntu 22.04 with Composer
Share
Font ResizerAa
itsmeit.bizitsmeit.biz
Font ResizerAa
  • Linux & Ubuntu
  • Windows
    • Tips & Trick
    • Windows Software
  • Web developer
    • Magento Developer
    • Wordpress Plugin
    • WP Blog Theme
    • WP Fashion Theme
    • WooCommerce Theme
  • Log Out
Have an existing account? Sign In
Follow US
Copyright © 2022. All Rights Reserved.
Web developerMagento Developer

How to install Magento 2.4 on Ubuntu 22.04 with Composer

duyanh
Last updated: November 17, 2023
By duyanh Published November 13, 2023
Share
SHARE

Table of contents

  1. How to install Magento 2.4 on Ubuntu 22.04 or 20.04 Composer
    1. Step 1. Magento 2 installation Requirements on Ubuntu 22.04 or 20.04 LTS
    2. Step 2. Install Magento 2.4 Ubuntu Using Composer
    3. Step 3. Create a database and username in MYSQL
    4. Step 4. How to set permissions folders and files in Magento 2
    5. Step 5. Install Magento 2.4 with CLI on Ubuntu 22.04 or 20.04
    6. Step 6. Setting Up Nginx Configuration File for Magento 2
    7. Step 7. How to Configure Magento 2 Domain on Localhost
    8. Step 8. Fix login backend error and switch Magento to dev mode.
    9. Step 9. How to install Magento 2 sample data (Full demo)
    10. Step 10. How to delete/remove sample data Magento 2.4

How to install Magento 2.4 on Ubuntu 20.04 or 22.04 and Linux using composer and config with Nginx server or Localhost (Full demo data). Previously in versions older than 2.4, it was possible to install Magento 2.x through a web browser but with version Magento 2.4.x, you can only install it using Command Line Utility (CLI).

How to install Magento 2.4 on Ubuntu 22.04 or 20.04 Composer

Step 1. Magento 2 installation Requirements on Ubuntu 22.04 or 20.04 LTS

  • Installed php7.4 successfully.
  • Successfully installed MySQL 8
  • Nginx has been installed successfully.
  • Successfully installed Elasticsearch 7.x

Since Magento version 2.4 and above will use Elasticsearch instead of Mysql search, so you need to have a relative system configuration. (refer to system requirements )

Step 2. Install Magento 2.4 Ubuntu Using Composer

Since Magento became a part of Adobe, the old methods of install Magento 2.4 on Ubuntu or Debian by directly downloading the source code file are no longer in use. Therefore, you will need to download the source code to your computer through the composer.

  • Reference link: Guide for install Composer on Ubuntu and Linux Debian

To be able to download the Magento 2 source, you also need to create authentication keys, log in to marketplace.magento.com, in the right corner of the screen click My Profile -> Access Keys

Click “Create A New Access Key“ to create your own Public Key, or Private Key, or get it here.

Public Key: e545ff23ec1afdd58dc63fe033da0305
Private Key: a8fc48a73b9b1ab6f92cf2e50418b6a1

Next, select Magento version, there will be 2 versions of Open Source and Adobe Commerce, here ItsmeIT will install Magento 2.4 Ubuntu Open Source via composer with the following command:

sudo mkdir -p /var/www/vhosts/magento2.4
sudo chown -R itsmeit:www-data /var/www/vhosts/
cd /var/www/vhosts/magento2.4
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.1

Enter the Public, and Private Key when asked, type the Y key, and Enter.

Download source and install Magento 2.4 on Ubuntu 20.04 or 22.04 (illustration)
Download source and install Magento 2.4 on Ubuntu 20.04 or 22.04 (illustration)

As you are using Nginx server, projects are usually located in the /var/www directory. In this step, ItsmeIT will create the /var/www/vhosts/magento2.4 directory and download the source code here. The path of this directory will be in the Nginx configuration file in step 6 below. Of course, you can change the directory path according to your project.

Note: Magento 2 is a very massive Framework, so please be patient and wait for the composer to download the source.

Step 3. Create a database and username in MYSQL

While waiting for a composer to download the source to install Magento 2.4 on Ubuntu 22.04 and 20.04 login to MYSQL and create a username, and database for the project.

sudo mysql

Or:

sudo mysql -u root -p

Then create a new database

CREATE DATABASE magento2 CHARACTER SET utf8 COLLATE utf8_general_ci;

Next, create a new MySQL user to manage the above database.

CREATE USER 'magento2'@'localhost' IDENTIFIED BY 'magento2@#$';
GRANT ALL PRIVILEGES ON magento2.* TO 'magento2'@'localhost';
FLUSH PRIVILEGES;

Step 4. How to set permissions folders and files in Magento 2

Magento 2 is a tightly secured framework developed with a robust security system. Therefore, while installing and using it, you need to ensure that the folder permissions for the Magento files and source are correctly set. This step is crucial to prevent minor errors that can occur during the setup process when install Magento on Ubuntu.

sudo find /var/www/vhosts/magento2.4/* -type f -exec chmod 644 {} +
sudo find /var/www/vhosts/magento2.4/* -type d -exec chmod 755 {} +
sudo chown -R $USER:www-data /var/www/vhosts/magento2.4/*

Step 5. Install Magento 2.4 with CLI on Ubuntu 22.04 or 20.04

After completing the change permissions step, now you run the commands below one by one to install Magento 2.4 on ubuntu 20.04 or 22.04. Please check the user, database… in the command below to see if it is correct or not, and then start running the command on the terminal at the directory Magento.

cd /var/www/vhosts/magento2.4/project-community-edition
bin/magento setup:install \
--base-url=http://dev.magento2.com/ \
--db-host=localhost \
--db-name=magento2 \
--db-user=magento2 \
--db-password=magento2@#$ \
--admin-firstname=admin \
--admin-lastname=admin \
--admin-email=itsmeit.biz@gmail.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=Asia/Ho_Chi_Minh \
--use-rewrites=1 \
--search-engine=elasticsearch7 \
--elasticsearch-host=localhost \
--elasticsearch-port=9200 \
--elasticsearch-index-prefix=magento2 \
--elasticsearch-timeout=15

Explain:

  • –base-url: On localhost, you can create any name as long as it is in the correct format, see the configuration in steps 6, 7.
  • –db-host: the usual MySQL server is localhost.
  • –db-name: the name of the database created in step 4.
  • –backend-frontname: admin access key
  • –db-user: username created in step 4.
  • –db-password: password created in step 4.
  • –admin-user: Username used to log in to the backend of the website.
  • –admin-password: Password to login to the website backend.
  • – Elasticsearch connects on port 9200

If there are no errors, the output will look like this:

Install Magento 2.4 with CLI on Ubuntu 22.04 or 20.04 (illustration)
Install Magento 2.4 with CLI on Ubuntu 22.04 or 20.04 (illustration)
How to installl Magento 2.4 on Ubuntu 22.04 |  20.04 with Composer + Nginx - itsmeit.biz

Backend frontName (http://dev.magento2.com/admin_fry53j), you can also review and change in app/etc/env.php

Step 6. Setting Up Nginx Configuration File for Magento 2

To set up Magento 2.4 on Ubuntu 22.04, 20.04, or Linux with Nginx, you can create a configuration file named dev.magento.com.conf in the /etc/nginx/sites-available directory, where “dev.magento.com” is the domain name of your website. Then, add the following content to the file.

sudo nano /etc/nginx/sites-available/dev.magento.com.conf
upstream fastcgi_backend {
  server  unix:/run/php/php7.4-fpm.sock;
}
server {
  listen 80;
  server_name dev.magento2.com www.dev.magento2.com;
  set $MAGE_ROOT /var/www/vhosts/magento2.4/project-community-edition;
  include /var/www/vhosts/magento2.4/project-community-edition/nginx.conf.sample;
}
Setting Up Nginx Configuration File for Magento 2 (illustration)
Setting Up Nginx Configuration File for Magento 2 (illustration)
  • upstream “unix”: Path to file php7.4-fpm
  • server_name: your domain
  • $MAGE_ROOT: Path to the directory containing the source Magento created in step 2, when you run composer it will automatically create a directory “project-community-edition”.
  • include The exact path to the nginx.conf.sample file in the source directory Magento 2.

Press Ctrl + X select Y to save the file and run the command below to reset Nginx

sudo service nginx restart

Note: While install magento 2.4 on Ubuntu 22.04 and 20.04 with Nginx:

  • If there is an error when working with Nginx, run the command: sudo nginx -t to display the error and check the configuration again.
  • To run the above config, you need to configure Nginx according to step 3 in this article.

Step 7. How to Configure Magento 2 Domain on Localhost

If you are install Magento 2.4 localhost Ubuntu, as you can see in the above steps, the domain “dev.magento2.com” is created during the installation process. Therefore, you need to configure this domain in the /etc/hosts file. Open this file and add the following content at the end to complete the install.

sudo nano /etc/hosts
127.0.0.1 dev.magento2.com

Done, you can run the dev.magento2.com website URL in your browser, and here are the results.

How to Configure Magento 2 Domain on Localhost (illustration)
How to Configure Magento 2 Domain on Localhost (illustration)

Step 8. Fix login backend error and switch Magento to dev mode.

Fix login backend error and switch Magento to dev mode (illustration)
Fix login backend error and switch Magento to dev mode (illustration)

Here is the solution to the issue of being unable to log in to the admin page after successfully install Magento 2.4 on Ubuntu 22.04, 20.04 or debian. By default, the Magento_TwoFactorAuth module in Magento is enabled for two-factor security. You can temporarily disable this module to access the admin page. After that, you can re-enable it and configure it to enable the two-factor authentication if necessary. (reference)

To do this open terminal, cd to the directory Magento source and run the command disable the Magento_TwoFactorAuth module, and switch to dev mode. Magento 2 has 3 modes: default, developer, and production, if you are building a website switch to the developer, and if the site is ready to go live, switch to production.

cd /var/www/vhosts/magento2.4/project-community-edition
php bin/magento module:disable Magento_TwoFactorAuth
php bin/magento deploy:mode:set developer
php bin/magento cache:clean

You can also open the file /app/etc/config.php find the Magento_TwoFactorAuth module and change the value to 0 then run the cache:clean command to clear the cache.

Step 9. How to install Magento 2 sample data (Full demo)

To install Magento 2.4 on Ubuntu or Linux with FULL demo data, include pages, products, and categories, you can execute the command below from the Magento directory. Please note that the demo installation may take some time, so please be patient.

php bin/magento sampledata:deploy
Install Magento 2 sample data demo CLI (illustration)
Install Magento 2 with Sample data demo on Ubuntu using CLI (Illustration)

Wait for sample data of magento 2.4 to be installed successfully, then run the upgrade command to update the source and database.

php bin/magento setup:upgrade
Demo magento 2.4.x frontend - itsmeit.biz

Step 10. How to delete/remove sample data Magento 2.4

You can also run the command below to remove demo data. (reference link)

php bin/magento sampledata:remove
php bin/magento setup:upgrade

Above are the steps on how to install Magento 2.4 on Ubuntu 20.04 or 22.04 using composer and configure Magento 2 with Nginx. Hope it helps you.

Reference: https://devdocs.magento.com/guides/v2.4/install-gde/prereq/nginx.html

– Advertising –

Share this Article
Facebook Twitter Pinterest LinkedIn Reddit Telegram
Leave a comment Leave a comment
Subscribe
Connect with
Login
Notify of
guest
Connect with
guest
0 Comments
Inline Feedbacks
View all comments
Previous Article How to Fix Errors & Change All WordPress Links to a New Domain How to fix errors & change all WordPress links to a new domain
Next Article How to Disable and Secure WP JSON API in WordPress How to Disable and Secure WP JSON API in WordPress

You Might Also Like

Prevent Spam Register Plugin – Block WordPress Spam Accounts

How to Disable and Secure WP JSON API in WordPress

How to fix errors & change all WordPress links to a new domain

Newsprk v6.1.0 – WordPress theme Magazine and Blogs

Maxshop v3.6.6 – Electronics Store Elementor WooCommerce

Stay Connected

Facebook Like
Twitter Follow
Pinterest Pin
Telegram Follow

Popular Posts

Download IDM FULL Crack v6.42.2 + Repack (Fix fake serial)
Download IDM FULL Crack v6.42.2 + Repack (Fix fake serial)
December 8, 2023 669 Views
Download WPBakery v7.2 Drag and Drop WordPress Page Builder Plugins
WPBakery v7.2 Drag and Drop WordPress Page Builder Plugins
December 4, 2023 21 Views
Download Plugin Product Video Gallery for Woocommerce v1.5.0
Plugin Product Video Gallery for Woocommerce v1.5.0
November 17, 2023 10 Views
Download Prevent Spam Register Plugin - Block WordPress Spam Accounts
Prevent Spam Register Plugin – Block WordPress Spam Accounts
November 17, 2023 14 Views
Elementor PRO v3.17.0 Plugin (Full Templates Pack + Demo)
Download Plugin Elementor PRO 3.17.0 (+Full Templates Pack)
November 17, 2023 37 Views
Download Newspaper v12.6.1 - WordPress theme News Magazine
Download Newspaper v12.6.1 – WordPress theme News Magazine
November 17, 2023 17 Views
We provide tips and tricks on Internet technology, computers, servers as well as share experiences for developers and website designers.

DMCA.com Protection Status

Quick Link

  • Linux | Ubuntu
  • Windows & Software
  • Magento Developer
  • Wordpress Plugin
  • Wordpress Theme

General Policy

  • About US
  • Contact US
  • Disclaimer
  • Privacy Policy
  • Terms of Service

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

itsmeit.bizitsmeit.biz
Follow US
Copyright © 2023. All Rights Reserved.
  • WP Blog Theme
  • WP Fashion Theme
  • WooCommerce Theme
  • Wordpress Plugin
Welcome Back!

Sign in to your account

Continue with Google
Continue with TikTok
Continue with GitHub
Register Lost your password?