Are you looking to set up Magento 2 on your Hostinger account using Debian 11? This guide will walk you through the process step-by-step, ensuring a smooth installation of Magento 2 on your Linux-based hosting environment.
Prerequisites
Before we begin the Magento 2 installation on Debian, make sure you have:
- A Hostinger account with Debian 11
- Root access to your server
- Basic knowledge of Linux commands
Step 1: Update and Upgrade Your System
First, let’s update and upgrade your Debian system:
sudo apt-get update
sudo apt-get upgrade
Step 2: Install and Configure Apache Web Server
Install Apache and enable the rewrite module:
sudo apt-get -y install apache2
a2enmod rewrite
Configure Apache to allow .htaccess overrides:
sudo nano /etc/apache2/sites-available/000-default.conf
Add the following lines within the <VirtualHost>
block:
<Directory "/var/www/html">
AllowOverride All
</Directory>
Restart Apache to apply changes:
service apache2 restart
Step 3: Install MariaDB
Install MariaDB server:
sudo apt -y install mariadb-server
Step 4: Install PHP and Required Extensions
Add the Sury PHP repository and install PHP 8.1 with necessary extensions:
apt update && apt install -y wget gnupg2 lsb-release
wget https://packages.sury.org/php/apt.gpg && apt-key add apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
apt update && apt install -y php8.1
sudo apt -y install php8.1-bcmath php8.1-common php8.1-curl php8.1-fpm php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-soap php8.1-xml php8.1-xsl php8.1-zip php8.1-cli
Configure PHP settings:
nano /etc/php/8.1/cli/php.ini
Step 5: Install OpenSearch
Download and install OpenSearch:
wget https://artifacts.opensearch.org/releases/bundle/opensearch/2.5.0/opensearch-2.5.0-linux-x64.deb
sudo dpkg -i opensearch-2.5.0-linux-x64.deb
Configure OpenSearch:
nano /etc/opensearch/opensearch.yml
Remove security settings and add:
plugins.security.disabled: true
Enable and start OpenSearch:
sudo systemctl enable opensearch
sudo systemctl start opensearch
Step 6: Install Composer
Install Composer globally:
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Step 7: Install Magento 2
Create a new Magento 2 project:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .
Set correct permissions:
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
Step 8: Configure and Install Magento 2
Run the Magento 2 installation command:
I’m using default variables, please edit this as you wish.
bin/magento setup:install --base-url=http://mywebsite.com.com/ --db-host=mydbhost --db-name=mydbname --db-user=mydbuser --db-password=mydbpassword --admin-firstname=admin --admin-lastname=admin --admin-email=admin@admin.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --opensearch-host=localhost --opensearch-port=9200 --search-engine=opensearch
(Optional)
Disable two-factor authentication modules:
bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth && bin/magento module:disable Magento_TwoFactorAuth
Step 9: Secure Your Installation with SSL
Install Certbot and obtain an SSL certificate:
sudo apt-get install certbot python3-certbot-apache apache2
sudo certbot --apache
Congratulations! You have successfully installed Magento 2 on your Hostinger account using Debian 11. Remember to keep your Magento installation up-to-date and secure by regularly applying patches and updates.
Would you like me to explain or break down any part of this guide?
Please add your comment below !