Magento is a popular open-source e-commerce platform written in PHP. It is used by thousands of online merchants to power their online stores. In this article, we will show you how to install Magento on Debian 11, a stable and secure Linux distribution.

Before you start, make sure you have a fresh installation of Debian 11 on your server. You can follow our guide on how to install Debian 11 if you need help with this. You will also need a domain name and a valid SSL certificate for your Magento store.

 Apache2 instructions for installing Magento on Debian 11:
  • Install Apache2 and enable the rewrite module:

sudo apt-get install apache2
sudo a2enmod rewrite
  • Create a new virtual host configuration file for Magento in the /etc/apache2/sites-available directory:
    sudo nano /etc/apache2/sites-available/magento.conf
    
    • Paste the following configuration in the file, replacing example.com with your own domain name:
    <VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com
    
        DocumentRoot /var/www/html
    
        <Directory /var/www/html>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    
    • Enable the virtual host and restart Apache2:
    sudo a2ensite magento.conf
    sudo systemctl restart apache2
    

    Now you can access your Magento store (after install) using the domain name you specified in the virtual host configuration file. Make sure to point your domain’s DNS records to the server’s IP address.

    If you have an SSL certificate for your domain, you can also enable HTTPS by adding the following lines to your virtual host configuration file:

    <VirtualHost *:443>
        ServerName example.com
        ServerAlias www.example.com
    
        DocumentRoot /var/www/html
    
        <Directory /var/www/html>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        SSLEngine on
        SSLCertificateFile /path/to/your/certificate.crt
        SSLCertificateKeyFile /path/to/your/private.key
        SSLCACertificateFile /path/to/your/intermediate.crt
    </VirtualHost>
    
    

    Don’t forget to replace the paths to the SSL certificate files with the actual paths on your server. Then, enable the HTTPS virtual host and restart Apache2:

    sudo a2ensite magento-ssl.conf
    sudo systemctl restart apache2
    

    Your Magento store is now accessible over HTTPS using your domain name (after full install).

    In conclusion, Apache2 is an essential component for serving Magento on Debian 11. By following the instructions in this section, you can configure Apache2 to host your Magento store securely over HTTPS.

    In case you already have the Apache2 installed and configured you can continue from this step, with PHP extensions.

    • Update the package list and install the required dependencies:
    sudo apt-get update
    sudo apt-get install unzip curl libcurl3 php-curl php-zip php-gd php-xml php-mbstring php-intl
    
    • Create a new user for Magento and give it the necessary permissions:
    sudo adduser magento
    sudo usermod -aG www-data magento
    
    • Download the latest version of Magento and unzip it in the /var/www/html directory:
    cd /var/www/html
    sudo wget <https://github.com/magento/magento2/archive/2.4.1.zip>
    sudo unzip 2.4.1.zip
    sudo mv magento2-2.4.1/* .
    sudo mv magento2-2.4.1/.htaccess .
    
    • Change the ownership of the Magento files to the magento user and give them the correct permissions:
    sudo chown -R magento:magento /var/www/html
    sudo chmod -R 755 /var/www/html
    
    • Create a new MySQL database and user for Magento:
    mysql -u root -p
    
    CREATE DATABASE magento;
    CREATE USER 'magento'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'localhost';
    FLUSH PRIVILEGES;
    
    • Install Magento using the bin/magento command:
    cd /var/www/html
    bin/magento setup:install --base-url=https://example.com/ \\
    --db-host=localhost --db-name=magento --db-user=magento --db-password=password \\
    --admin-firstname=Admin --admin-lastname=User --admin-email=admin@example.com \\
    --admin-user=admin --admin-password=password --language=en_US \\
    --currency=USD --timezone=America/Chicago --use-rewrites=1
    

    Replace the values in the command above with your own domain name, database name, and admin user details.

    That’s it! Magento is now installed on your Debian 11 server. You can access the admin panel by going to https://example.com/admin in your web browser, using the admin username and password you set in the previous step.

    In conclusion, installing Magento on Debian 11 is a straightforward process. By following the steps outlined in this article, you can have your own online store up and running in no time.