How to Install Magento on Debian 11

Magento is a free and open-source eCommerce application that allows you to host your online store. It is written in PHP and uses the Zend framework. It is versatile and scalable that makes it suitable for small, medium to big size stores. It allows you to host a fully-functional online shopping cart system without any programming knowledge. It is used by thousands of online stores due to its simplicity and user-friendliness.

In this tutorial, I will show you how to install Magento2 on Debian 11.


  • A server running Debian 11.
  • A valid domain name pointed with your server IP.
  • A root password is configured on the server.

Install Apache, PHP, and Other Required Extensions

First, you will need to install the Apache, PHP and other necessary PHP extensions to your server. You can install all of them using the following command:

apt-get install apache2 php libapache2-mod-php php-common php-gmp php-curl php-soap php-bcmath php-intl php-mbstring php-xmlrpc php-mysql php-gd php-xml php-cli php-zip -y

Once all the packages are installed, edit the php.ini file and change some default settings:

nano /etc/php/7.4/apache2/php.ini

Change the following values:

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

Save and close the file then restart the Apache service to apply the changes:

systemctl restart apache2

Install and Configure MySQL Server

Magento2 uses MariaDB or MySQL as a database backend. By default, the MariaDB version 10.5 is included in the Debian 11 default repository, which is not supported by Magento2. So you will need to install MySQL Server 8 to your server.

First, download the MySQL package file with the following command:


Next, install it using the following command:

apt install ./mysql-apt-config_0.8.18-1_all.deb -y

You will be asked to select the MySQL version that you want to install:

Install MySQL

Select MySQL Server 8 and click on the OK button.

Next, update the repository and install the MySQL server 8 with the following command:

apt-get update -y
apt-get install mysql-server -y

Once the MySQL is installed, connect to the MySQL with the following command:

mysql -u root -p

Once you are log in, create a database and user for Magento2 with the following command:

mysql> CREATE DATABASE magento2;
mysql> CREATE USER 'magento2'@'localhost' IDENTIFIED BY 'password';

Next, grant all the privileges to the Magento2 database:

mysql> GRANT ALL PRIVILEGES ON magento2.* TO 'magento2'@'localhost';

Next, flush the privileges and exit from the MySQL with the following command:

mysql> EXIT;

Once you are finished, you can proceed to the next step.

Install Composer

Composer is a dependency manager for PHP used for managing PHP dependencies required for your project.

First, install the curl command-line tool with the following command:

apt-get install curl -y

Next, install the Composer using the following command:

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

You will get the following output:

All settings correct for using Composer

Composer (version 2.1.12) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

Next, verify the Composer version using the following command:

composer --version

You should see the following output:

Composer version 2.1.12 2021-11-09 16:02:04

Install Magento2

Next, change the directory to the Apache web root directory and download the latest version of Magento2 with the following command:

cd /var/www/html
composer create-project --repository-url= magento/project-community-edition magento2

You will be asked to provide your Magento account username and password as shown below:

Creating a "magento/project-community-edition" project at "./magento2"
Warning from You haven't provided your Magento authentication keys. For instructions, visit
    Authentication required (
      Username: a6b333ad41629bac913eaabb9b8e053c

Use the Public key as your username and the Private key as your password then press the Enter key. You will get the following output:

Do you want to store credentials for in /root/.config/composer/auth.json ? [Yn] Y
Installing magento/project-community-edition (2.4.3-p1)
  - Downloading magento/project-community-edition (2.4.3-p1)
  - Installing magento/project-community-edition (2.4.3-p1): Extracting archive
Created project in /var/www/html/magento2
Loading composer repositories with package information

Next, set proper permissions and ownership of Magento2 and other directories:

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

Next, disable the Elasticsearch module with the following command:

php bin/magento module:disable {Magento_Elasticsearch,Magento_InventoryElasticsearch,Magento_Elasticsearch6,Magento_Elasticsearch7}

You will get the following output:

The following modules have been disabled:
- Magento_Elasticsearch
- Magento_Elasticsearch6
- Magento_InventoryElasticsearch
- Magento_Elasticsearch7

Cache cleared successfully.
Generated classes cleared successfully. Please run the 'setup:di:compile' command to generate classes.
Info: Some modules might require static view files to be cleared. To do this, run 'module:disable' with the --clear-static-content option to clear them.

Next, install the Magento2 with the following command:

bin/magento setup:install --base-url= --db-host=localhost --db-name=magento2 --db-user=magento2 --db-password=password --admin-firstname=admin --admin-lastname=admin [email protected] --admin-user=admin --admin-password=Secure@password123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1

Once the Magento2 has been installed, you should see the following output:

Module 'Vertex_AddressValidation':
[Progress: 1363 / 1370]
Module 'Yotpo_Yotpo':
[Progress: 1364 / 1370]
Enabling caches:
Current status:
layout: 1
block_html: 1
full_page: 1
[Progress: 1365 / 1370]
Installing admin user...
[Progress: 1366 / 1370]
Caches clearing:
Cache cleared successfully
[Progress: 1367 / 1370]
Disabling Maintenance Mode:
[Progress: 1368 / 1370]
Post installation file permissions check...
For security, remove write permissions from these directories: '/var/www/html/magento2/app/etc'
[Progress: 1369 / 1370]
Write installation date...
[Progress: 1370 / 1370]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_fgadpx
Nothing to import.

Note: Please remember the Magento2 Admin URI from the above output. You will need to use it to access the Magento web interface.

Next, disable the Magento2 two-factor authentication, clear the cache and install the Cron with the following commands:

sudo -u www-data bin/magento module:disable Magento_TwoFactorAuth
sudo -u www-data bin/magento cache:flush
sudo -u www-data bin/magento cron:install

Once you are finished, you can proceed to the next step.

Create an Apache Virtual Host Configuration File

Next, you will need to create an Apache virtual host configuration file for Magento2. You can create it with the following command:

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

Add the following lines:

<VirtualHost *:80>
     ServerAdmin [email protected]
      DocumentRoot /var/www/html/magento2/

     <Directory /var/www/html/magento2/>
          Options FollowSymlinks
          AllowOverride All
          Require all granted

     ErrorLog ${APACHE_LOG_DIR}/magento2_error.log
     CustomLog ${APACHE_LOG_DIR}/magento2_access.log combined


Save and close the file then activate the Magento virtual host and Apache rewrite module using the following command:

a2ensite magento2.conf
a2enmod rewrite

Finally, restart the Apache service to apply the changes:

systemctl restart apache2

You can also check the Apache status with the following command:

systemctl status apache2

You should see the following output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-11-20 06:00:59 UTC; 4s ago
    Process: 18394 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 18398 (apache2)
      Tasks: 6 (limit: 4679)
     Memory: 15.1M
        CPU: 99ms
     CGroup: /system.slice/apache2.service
             ??18398 /usr/sbin/apache2 -k start
             ??18399 /usr/sbin/apache2 -k start
             ??18400 /usr/sbin/apache2 -k start
             ??18401 /usr/sbin/apache2 -k start
             ??18402 /usr/sbin/apache2 -k start
             ??18403 /usr/sbin/apache2 -k start

Nov 20 06:00:59 debian11 systemd[1]: Starting The Apache HTTP Server...

Access Magento2 Web Interface

Now, open your web browser and access the Magento2 admin interface using the URL You should see the Magento2 log in page:

Magento login

Provide your admin username, password and click on the Login button. You should see the Magento2 dashboard on the following page:

Magento dashboard


Congratulations! you have successfully installed Magento2 on Debian 11. You can now host your online store easily with Magento. Feel free to ask me if you have any questions.

Share this page:

0 Comment(s)