7 étapes pour installer Magento 2 sur Ubuntu

2022-02-02

Êtes-vous à la recherche d'un guide étape par étape pour installer la dernière version de Magento 2 sur Ubuntu/Debian à partir du référentiel Magento ou Github avec Apache/NginX, MySQL/MariaDB et PHP7.x ?

Ressource

Step 1: Install Apache2 PHP and Required Extensions

Step 1.1 Install Apache2 Server

The Apache HTTP Server, called Apache, it is free and open-source cross-platform web server software. Apache is the most popular HTTP Server now. It runs on Linux, Windows, OpenVMS, NetWare and other operating systems.

To install Apache, you should update packages before running install Apache install command:

sudo apt update
sudo apt install apache2

To run apache automatically during startup, run the following command line:

sudo systemctl enable apache2.service

Step 1.2 Configure Apache2 Virtual Host

To declare Apache2 site configuration for Magento 2 store, you have to create a new configuration file magento2.conf:

sudo nano /etc/apache2/sites-available/magento2.conf

Copy and paste the following content to the above file. Remember, you should change domain.com to your domain.


     ServerAdmin admin@domain.com
     DocumentRoot /var/www/html/magento2/
     ServerName domain.com
     ServerAlias www.domain.com

     
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

If you are installing Magento locally, you can change domain.com to localhost.com, dev.com or m2.com. Then you have to update hosts file at /etc/hosts with

127.0.0.1 localhost.com
127.0.0.1 dev.com
127.0.0.1 m2.com

IMPORTANT:

In this tutorial, I use localhost.com.

Enable Rewrite mod

Make sure you enable rewrite mod to use site friendly URLs:

sudo a2ensite magento2.conf
sudo a2enmod rewrite

Step 1.3: Install PHP 7.2 and extensions

On Ubuntu 18.04, you can install PHP 7.2 easily with the following command line:

sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-gmp php7.2-curl php7.2-soap php7.2-bcmath php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-mcrypt php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip

Step 1.4: Update php.ini file

Now it’s time to increase values in the php.ini file. Open php.ini file:

sudo nano /etc/php/7.2/apache2/php.ini

Change the following data:

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 512M
upload_max_filesize = 128M
max_execution_time = 3600

Then save this php.ini file.

After that, you should restart apache2. Run this command:

sudo systemctl restart apache2.service

Step 2: Install Database Server

Magento prefered MariaDB Database Server to default MySQL Database Server, because of faster and better performance. To install MariaDB Server and Client, run this command line:

sudo apt-get install mariadb-server mariadb-client

Make sure it start and startup every time you reboot server:

sudo systemctl restart mariadb.service
sudo systemctl enable mariadb.service

You’ve just installed MariaDB server, now you have to initially setup this database server.

sudo mysql_secure_installation

It prompte and you choose the following option:

Enter current password for root (enter for none): Enter
Set root password? [Y/n]: Y
New password: Type your password
Re-enter new password: Type your password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y

Step 3: Create MySQL User (Required)

From Magento 2.3.x, Magento requires a unique user for Magento installation, it cannot default user: root.

First of all, you have to login to MariaDB:

sudo mysql -u root -p

Create a new database for Magento 2:

CREATE DATABASE magento2

Then create a new user name call: mageplaza

CREATE USER 'mageplaza'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD';

Grant mageplaza user to magento2 database:

GRANT ALL ON magento2.* TO 'mageplaza'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD' WITH GRANT OPTION;

Ok, time to flush privileges and exit.

FLUSH PRIVILEGES;
EXIT;

Step 5: Install Composer

Download Composer and install or you can use command line to install Composer

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Check Composer installed or not just type:

composer -v

Ouput:

   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.8.5 2019-04-09

Step 6: Download Magento 2 Pack

You can download from one of the folling resources:

After donwload, you should extract the pack to /var/www/html/. E.g you have a folder call: magento2 in /var/www/html/

Set permissions: Run this command

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

Step 7: Install Magento 2

Access to this address http://localhost.com/magento2, you will get this Magento Setup Wizard as the following:

Running the Magento Setup Wizard

Step 7.3: Start Installing

  • Click Start Readiness Check. If any errors are displayed, you must resolve them before you continue. Click More detail if available to see more information about each check. Readiness Check error
  • Click Next

Step 7.2 Add a Database

Fill database information then click Next

Step 7.3 Web Configuration

  • Enter the following information:
    • Your Store Address: http://localhost.com
    • Magento Admin Address: Enter the relative URL by which to access the Magento Admin. e.g: secret, backend
  • Then click Next

Step 7.4. Customize Your Store

  • From the Store Default Time Zone list, click the name of your store’s time zone.
  • From the Store Default Currency list, click the default currency to use in your store.
  • From the Store Default Language list, click the default language to use in your store.
  • Expand Advanced Modules Configuration to optionally enable or disable modules before you install the Magento software.

How to install Magento 2 Magento modules configuration

You can choose to install Sample Data or not in this step.

Click Next

Important!: Use Skip dependency check for individual modules with caution. We recommend against it because a typical reason for this error is you manually edited the deployment configuration. Editing the deployment configuration is not recommended because future Magento software updates can undo your changes.

Step 7.5. Create Admin Account

Now enter admin information such as

  • New Username
  • New E-Mail
  • New Password
  • Confirm Password
  • Then click Next

Step 7.6. Install

mageplaza

After completing all previous steps in the Setup Wizard, click Install Now.

Installation Success The message Success will be displayed to indicate a successful installation.

Step 7.7: Check the result

Now go to the frontend and backend to see the result

Frontend

How to install Magento 2 Frontend

Backend

How to install Magento 2 Frontend

Nous nous assurons que le processus de création de votre site internet suit les plus hauts standards de l’industrie.

Whatsapp