How to Install Magento on Debian 11

Install Magento on Debian 11

In this article, we will have explained the necessary steps to install Magento on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Magento is a free and open-source eCommerce platform based on PHP and MySQL that is used by millions of small businesses to sell and manage their products online. 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.

Install Magento on Debian 11

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgradesudoapt install software-properties-common wget

Step 2. Install LAMP stack.

You’re going to need to set Debian up as either a LAMP server. If you haven’t done so already, use our traditional LAMP guide to set up Debian to serve before you continue.

Step 3. Install Composer.

Run the following command to install the Composer:

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

Verify the Composer version:

composer --version

Step 4. Creating a MySQL database for Magento.

Magento uses the MySQL database to store all its data. Log in to your MySQL server with the following command and enter your MySQL root password:

mysql -u root -p

Once you’re in the MySQL console, create a new database:

MariaDB [(none)]> CREATE DATABASE magento2;
MariaDB [(none)]> CREATE USER 'magento2'@'localhost' IDENTIFIED BY 'your-password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON magento2.* TO 'magento2'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Step 5. Install Magento on Debian Bullseye system.

Next steps, change the directory to the Apache web root directory and download the latest version of Magento:

cd /var/www/html
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2

Copy and paste the authentication key:

Authentication required (repo.magento.com):
      Username: a6b3bmwe4629bac913ee368e053c
      Password:

After that, set proper permissions and ownership of Magento 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

Then, disable the Elasticsearch module with the following command:

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

Finally, install the Magento2 with the following command below:

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

Now disable the Magento2 two-factor authentication, clear the cache and install the Cron:

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

Step 5. Configuring Apache.

Now create a new virtual host configuration file for your Magento website, named magento.conf:

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

And add the following content to the file:

<VirtualHost *:80>
     ServerAdmin [email protected]
      DocumentRoot /var/www/html/magento2/
     ServerName magento.your-domain.com

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

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

</VirtualHost>

Save and close, then enable the new site with the following command:

sudo a2ensite magento.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

Step 6. Accessing Magento2 Web Interface.

Open your browser and browse to the server domain name or use the URLhttp://magento.your-domain.com/admin_fgadpx You should see the Magento homepage.

Install Magento on Debian 11

That’s all you need to do to install Magento on Debian (Bullseye). I hope you find this quick tip helpful. For further reading Magento eCommerce on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.