How to Install Magento 2 on Debian 11 (Open Source Tutorial)

How to Install Magento 2 on Debian 11 (Open Source Tutorial). This article will introduce what Magento is with it’s features, then Magento 2 new features and then we will start installing it on Debian 11. Let’s start!

What is Magento

Magento is one of the most popular eCommerce platforms written in PHP which helps programmers create eCommerce websites. Magento offers powerful marketing, search engine optimization, and catalog management tools as well as control over the look, content and functionality of their online store. Magento allows you to host an online store with only a few products and easily expand to tens of thousands of products without changing platforms. It offers a user friendly control panel and a variety of plug-ins and themes to enhance a customer’s experience.

Magento Features

  • Easy to install, configure and add additional plugins and themes.
  • Supports more than 50 payment gateways.
  • Built with open source technology that offers flexible, scalable eCommerce solutions.
  • Scalable, secure and cost sensitive.
  • Offers powerful marketing, search engine optimization tools.
  • Catalog Management.
  • Order Management.
  • SEO Optimized. 
  • Marketing and advertisement. 
  • Internationalization ( approach for SMEs looking to boost their international sales and marketing).
  • Extremely large community.
  • Easy Checkout.
  • Enhanced Security (2FA, ReCaptcha).
  • Marketplace and third party integration.
  • Unlimited customization.
  • GraphQL Support.
  • Asynchronous and Bulk Web API.

Magento 2 features

Some of the features introduced in Magento 2 are:

 

  • Gift Cards.
  • More advanced Catalog Search.
  • Page Hierarchy.
  • Email Reminders
  • Private Sales & Events
  • Loyalty and rewards.
  • Visual Merchandiser
  • More Payment Methods.
  • Shopping Assistance
  • Scheduled Import and Export.

Follow this post to show you how to install Magento 2 on Debian 11.

Install Magento 2 on Debian 11 (Open Source Tutorial)

Install Apache, MariaDB, and PHP

Magento 2 requires an Apache web server, MariaDB database and PHP to be installed on your server. If not installed, you can install all of them by running the following command:

				
					apt-get install apache2 mysql-server php libapache2-mod-php php-fpm 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 unzip curl -y

				
			

Once all the packages are installed, edit the PHP configuration file change some recommended settings:

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

Change the following settings:

				
					file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 512M
upload_max_filesize = 128M
max_execution_time = 3600
date.timezone = America/Chicago

				
			

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

				
					systemctl restart apache2
				
			

Configure MySQL Database

Magento uses a MariaDB or MySQL as a database backend. So you will need to create a database and user for Magento. First, connect to the MySQL shell with the following command:

				
					mysql
				
			

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

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

Next, grant all the privileges to the Magento with the following command:

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

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

				
					mysql> FLUSH PRIVILEGES;
mysql> EXIT;
				
			

Download Magento 2 on Your Server

First, you will need to install Composer on your system. You can install it by running the following command:

				
					curl -sS https://getcomposer.org/installer | php
				
			

You should see the following output:

				
					All settings correct for using Composer
Downloading...

Composer (version 2.3.5) successfully installed to: /root/composer.phar
Use it: php composer.phar
				
			

Next, move the Composer binary to the system location with the following command:

				
					mv composer.phar /usr/local/bin/composer
				
			

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

				
					cd /var/www/html/
wget https://github.com/magento/magento2/archive/refs/tags/2.4.2.zip
				
			

Once Magento 2 is downloaded, unzip the downloaded file with the following command:

				
					unzip 2.4.2.zip
				
			

Move the extracted directory to the Apache web root directory:

				
					mv magento2-2.4.2 /var/www/html/magento2
				
			

Next, change the directory to magento2 then update the composer and install all required dependencies with the following command:

				
					cd magento2
composer update
composer install
				
			

Once all the dependencies are installed, set proper permission and ownership to magento2 directory:

				
					chown -R www-data:www-data /var/www/html/magento2
chmod -R 755 /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 {} +
chmod u+x bin/magento

				
			

Configure Apache for Magento 2

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

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

Add the following lines:

				
					<VirtualHost *:80>
     ServerAdmin admin@example.com
      DocumentRoot /var/www/html/magento2/
     ServerName magento.example.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 the file then activate the Apache virtual host and rewrite module with the following command:

				
					a2ensite magento2.conf
a2enmod rewrite
				
			

Finally, restart the Apache service to apply the configuration changes:

				
					systemctl restart apache2
				
			

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

				
					systemctl status apache2
				
			

You will get the following output:

				
					● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-15 07:45:42 UTC; 5min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 30339 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 30355 (apache2)
      Tasks: 11 (limit: 4686)
     Memory: 219.0M
     CGroup: /system.slice/apache2.service
             ├─30355 /usr/sbin/apache2 -k start
             ├─30356 /usr/sbin/apache2 -k start
             ├─30358 /usr/sbin/apache2 -k start
             ├─30359 /usr/sbin/apache2 -k start
             ├─30360 /usr/sbin/apache2 -k start
             ├─30375 /usr/sbin/apache2 -k start
             ├─30376 /usr/sbin/apache2 -k start
             ├─30377 /usr/sbin/apache2 -k start
             ├─30379 /usr/sbin/apache2 -k start
             ├─30386 /usr/sbin/apache2 -k start
             └─30436 /usr/sbin/apache2 -k start

Apr 15 07:45:42 debian11 systemd[1]: Starting The Apache HTTP Server...

				
			

Install Magento 2 Using CLI

Magento web installation wizard has been removed since version 2.3.7 so you will need to perform the Magento 2 installation from the command line interface.

First, change the directory to Magento2 with the following command:

				
					cd /var/www/html/magento2/
				
			

Now, run the following command to start the installation:

				
					sudo -u www-data bin/magento setup:install --base-url=http://magento.example.com --db-host=localhost --db-name=magentodb --db-user=magentouser --db-password=password --admin-firstname=Hitesh --admin-lastname=Jethva --admin-email=admin@example.com --admin-user=hiteshj --admin-password=YourSecure@password123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1
				
			

You will get the ElasticSearch related error because ElasticSearch is not installed on this server. To fix this error, run the following command:

				
					sudo -u www-data bin/magento module:disable {Magento_Elasticsearch,Magento_Elasticsearch6,Magento_Elasticsearch7}
				
			

Now, run the Magento 2 installation command again as shown below:

				
					sudo -u www-data bin/magento setup:install --base-url=http://magento.example.com --db-host=localhost --db-name=magentodb --db-user=magentouser --db-password=password --admin-firstname=Hitesh --admin-lastname=Jethva --admin-email=admin@example.com --admin-user=hiteshj --admin-password=YourSecure@password123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1
				
			

Once the Magento has been installed, you will get the following output:

				
					
[Progress: 822 / 830]
Module 'Magento_WishlistAnalytics':
[Progress: 823 / 830]
Module 'Magento_WishlistGraphQl':
[Progress: 824 / 830]
Enabling caches:
Current status:
layout: 1
block_html: 1
full_page: 1
[Progress: 825 / 830]
Installing admin user...
[Progress: 826 / 830]
Caches clearing:
Cache cleared successfully
[Progress: 827 / 830]
Disabling Maintenance Mode:
[Progress: 828 / 830]
Post installation file permissions check...
For security, remove write permissions from these directories: '/var/www/html/magento2/app/etc'
[Progress: 829 / 830]
Write installation date...
[Progress: 830 / 830]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_9lxo7k
Nothing to import.
				
			

Next, install the Magento 2 cron job with the following command:

				
					sudo -u www-data bin/magento cron:install
				
			

Access Magento 2 Web Interface

Now, open your web browser and access the Magento 2 admin interface using the URL http://magento.example.com/admin_9lxo7k. You should see the Magento 2 login page:

Provide your Magento 2 admin username, password and click on the Sign in button. Once you are logged in, you should see the Magento 2 dashboard on the following page:

How to Install Magento 2 on Debian 11 (Open Source Tutorial) Conclusion

In this post, we explained how to install Magento 2 on Debian 11. You can now host your own eCommerce store using the Magento platform. For more information, visit the Magento 2 official documentation.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x