How To Install Magento on Debian 12
In this tutorial, we will show you how to install Magento on Debian 12. Setting up an online store requires a robust and reliable platform. Magento, a leading open-source e-commerce solution, provides the flexibility and features necessary for creating a successful online business. This guide will walk you through the process of installing Magento on Debian 12, ensuring that you have a solid foundation for your e-commerce operations.
Why Choose Debian 12 for Magento?
Debian 12 is known for its stability, security, and extensive community support. These qualities make it an excellent choice for hosting Magento. With regular updates and a strong focus on security, Debian ensures that your e-commerce platform runs smoothly and securely. Additionally, Debian’s efficient resource management allows for optimal performance of your Magento store.
Pre-Installation Requirements
Before diving into the installation process, it’s essential to ensure that your server meets the necessary requirements:
- Operating System: Debian 12 or higher
- Web Server: Apache 2.4 or Nginx 1.18 or higher
- Database Server: MySQL 8.0 or MariaDB 10.4 or higher
- PHP Version: PHP 8.1 or higher with required extensions
- Memory: Minimum of 2 GB RAM (4 GB recommended)
- Disk Space: At least 2 GB of free space
Step 1: Update Your System
Start by updating your system packages to ensure you have the latest software versions:
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Packages
You will need several packages to facilitate the installation process. Run the following command to install them:
sudo apt install wget curl nano ufw software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release debian-archive-keyring unzip -y
Step 3: Installing the Web Server
You can choose either Apache or Nginx as your web server. Below are the installation commands for both:
Installing Apache
sudo apt install apache2 -y
After installation, start and enable Apache to run on boot:
sudo systemctl start apache2
sudo systemctl enable apache2
Installing Nginx
sudo apt install nginx -y
Start and enable Nginx with these commands:
sudo systemctl start nginx
sudo systemctl enable nginx
Step 4: Install PHP and Required Extensions
Magento requires PHP version 8.2 or higher along with several extensions. Install PHP and its extensions using the following command:
sudo apt install php php-fpm php-cli php-mysql php-mbstring php-xml php-gd php-bcmath php-zip php-curl php-intl php-soap php-xsl -y
Step 5: Install MariaDB (or MySQL)
You can use either MariaDB or MySQL as your database server. For this guide, we will install MariaDB:
sudo apt install mariadb-server -y
After installation, secure your MariaDB installation by running:
sudo mysql_secure_installation
Create a Database for Magento
Log into MariaDB to create a database and user for Magento:
sudo mysql -u root -p
CREATE DATABASE magento;
CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON magento.* TO 'magento_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 6: Install Composer
Composer is a dependency manager for PHP that is essential for installing Magento. To install Composer, run the following commands:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer --version
Step 7: Download Magento
Navigating to your desired directory (usually /var/www
) is next:
cd /var/www
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento
This command will download Magento into a folder named “magento”. Ensure that the ownership is set correctly:
sudo chown -R www-data:www-data /var/www/magento
sudo find /var/www/magento -type d -exec chmod 755 {} \;
sudo find /var/www/magento -type f -exec chmod 644 {} \;
Step 8: Configure Your Web Server for Magento
If you are using Apache, create a new configuration file in `/etc/apache2/sites-available/magento.conf
` with the following content:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/magento/pub
<Directory /var/www/magento/pub>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If using Nginx, create a configuration file in `/etc/nginx/sites-available/magento
` with similar content but adjusted for Nginx syntax.
Able to Enable Configuration and Restart Services
# For Apache
sudo a2ensite magento.conf
sudo systemctl restart apache2
# For Nginx
sudo ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Step 9: Run the Magento Installation Wizard
Your web server should now be configured to serve Magento. Open your browser and navigate to `http://example.com
` (replace with your domain). You should see the Magento installation wizard.
The wizard will guide you through several steps including:
- Selecting your language and currency.
- Selecting your database connection details.
- Selecting your store information.
- Caching options.
- Your admin account details.
Troubleshooting Common Installation Issues
- If you encounter memory limit errors, adjust the `
memory_limit
` setting in `php.ini
`. - If file permissions issues arise, ensure that all files are owned by the web server user.
- If database connection errors occur, double-check your database credentials.
Post-Installation Tasks
A few essential tasks should be completed after installation:
- Create Cron Jobs: This is vital for scheduled tasks like indexing and email sending.
- Caching Configuration: Use Redis or Varnish for improved performance.
- Securitization Measures: Implement SSL certificates to secure data transmission.
Cron Job Example Command:
* * * * * php /var/www/magento/bin/magento cron:run | grep -v "Ran jobs by schedule" >> var/log/magento.cron.log
Securitization with Let’s Encrypt SSL:
# For Apache
sudo apt install certbot python3-certbot-apache
# For Nginx
sudo apt install certbot python3-certbot-nginx
# Obtain SSL certificate
sudo certbot --apache -d example.com
# or
sudo certbot --nginx -d example.com
Congratulations! You have successfully installed Magento. Thanks for using this tutorial for installing the latest version of the Magento eCommerce platforms on Debian 12 “Bookworm”. For additional help or useful information, we recommend you check the official Magento website.