How to Install Magento with LAMP Stack on Debian 11

Magento is an e-commerce platform built on open source technology that provides online merchants with a flexible shopping cart system, as well as control over the look, content, and functionality of their online store. Magento offers powerful marketing, search engine optimization, and catalog-management tools.

Check Magento Latest Versions Here.

Pre-requisites :

  • A system with Debian 11 installed and running.

  • root access to the system.

  • Adobe Magento account. For creating an account Click here.

  • MySQL 8 installed and running, for this, you can refer to one of our guides for installing MySQL 8 on Debian 11.

Once you're all set, we'll proceed with Magento installation and configuration.

Install Apache & PHP

Now , install Apache and PHP using below commads:

apt install -y apache2 apache2-utils php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath

Reload apache

a2enmod php7.4

systemctl reload apache2

systemctl enable apache2

Update firewall

ufw allow 80/tcp

ufw allow 443/tcp

Create Database

Let us begin with creating a Database and a user. We will then grant the required privileges to the user so it can interact with the Database.

You should create a database with the name magento2 for all.

mysql -u root


CREATE USER 'magento2'@'localhost' IDENTIFIED BY 'password_crowncloud';

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



The above commands will give complete access to the user magento2. We would suggest using a strong and long password.

Configure PHP Settings for Magento

Configure PHP Memory Limit, Post max size, and Upload max filesize. You can change the limit as per your need.

sed -i 's/memory_limit = .*/memory_limit = 512M/' /etc/php/7.4/apache2/php.ini

sed -i 's/post_max_size = .*/post_max_size = 256M/' /etc/php/7.4/apache2/php.ini

sed -i 's/upload_max_filesize = .*/upload_max_filesize = 512M/' /etc/php/7.4/apache2/php.ini

Enable Apache module if not already enabled then restart the Web Server.

a2enmod php7.4

systemctl restart apache2

Configuring Apache vHost

Now, create a new Apache configuration file for Magento with the following command.

Replace with the domain name of your own for all the below code examples:

vi /etc/apache2/sites-available/

Now, press i to go to INSERT mode and type in the following lines of codes in the file.

<VirtualHost *:80>

DocumentRoot /var/www/magento

ErrorLog ${APACHE_LOG_DIR}/dev.domainhere.info_error.log
CustomLog ${APACHE_LOG_DIR}/dev.domainhere.info_access.log combined

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


Enable SSL and Rewrite:


a2enmod rewrite ssl

Restart Apache:

systemctl restart apache2

Download Magento

Let's install composer first:

cd /var/www

apt install curl git

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

Now go to Adobe website and create access keys. For creating access keys : Click here.

The below commands will create a new folder Magento with the required files.

When prompted, enter your authentication keys. Your public key is your username & your private key is your password.

composer create-project --repository= magento/project-community-edition magento

Let's make the folder readable.

chown -R www-data:www-data /var/www/html/magento/

cd /var/www/html/magento

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

Disable Elasticsearch module.

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

Install Magento

Let's install Magento using the below command.

bin/magento setup:install

Yo can access the admin dashboard using the URL displayed after installation with username and password shown.

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

-u www-data bin/magento module:disable Magento_TwoFactorAuth

-u www-data bin/magento cache:flush

-u www-data bin/magento cron:install

Restart apache:

systemctl restart apache2

Accessing the website

Now open the Domain name from your browser, this will load the Magento installed website.

Replace the with the actual IP or domain configured on the server.

Now you have successfully installed Magento with LAMP Stack on Debian 11.