How To Install Magento on AlmaLinux 9
Magento is one of the most popular e-commerce platforms available today, offering a robust and scalable solution for businesses looking to establish a strong online presence. AlmaLinux, on the other hand, is a free and open-source Linux distribution that is binary-compatible with Red Hat Enterprise Linux (RHEL), making it an ideal choice for hosting web applications like Magento. In this article, we will walk through the process of installing Magento on AlmaLinux 9, covering all the necessary steps and troubleshooting tips to ensure a successful setup.
Introduction to Magento and AlmaLinux
Magento is renowned for its flexibility and customization capabilities, allowing users to create and manage online stores efficiently. It supports a wide range of extensions and themes, making it highly adaptable to different business needs. AlmaLinux, with its stability and compatibility, provides a reliable foundation for running Magento smoothly.
AlmaLinux is a community-driven project that offers a stable and secure environment for web servers. Its compatibility with RHEL ensures that users can leverage the extensive ecosystem of RHEL-compatible software, including Magento.
Prerequisites for Installing Magento on AlmaLinux 9
Before proceeding with the installation, ensure that your system meets the necessary requirements for running Magento. Here are the key prerequisites:
- System Requirements: Magento requires a server with at least 2 GB of RAM, though 4 GB or more is recommended for better performance. Ensure your AlmaLinux 9 server has sufficient disk space and a compatible processor.
- Software Requirements: You will need PHP 7.4 or later, MySQL or MariaDB, and Composer for managing PHP dependencies.
- AlmaLinux 9 Setup: Ensure AlmaLinux 9 is installed and updated. You should have SSH access and root privileges to perform the installation.
Step-by-Step Installation Guide
A. Update AlmaLinux 9 and Install Required Packages
To start, update your AlmaLinux 9 system to ensure you have the latest packages:
sudo dnf update -y
Next, install the necessary packages for running Magento:
- Install Apache:
sudo dnf install httpd httpd-tools -y
Apache is a popular web server that supports Magento.
- Install PHP and Extensions:
Magento requires PHP 8.2 or later. Install PHP along with the necessary extensions:sudo dnf install php php-fpm php-mysqlnd php-opcache php-gd php-curl php-soap php-intl php-mbstring php-zip php-bcmath -y
These extensions are crucial for Magento’s functionality.
- Start and Enable Apache and PHP-FPM Services:
sudo systemctl start httpd sudo systemctl enable httpd sudo systemctl start php-fpm sudo systemctl enable php-fpm
B. Install MariaDB or MySQL
For the database, you can use either MariaDB or MySQL. Here, we’ll use MariaDB:
- Install MariaDB:
sudo dnf install mariadb-server mariadb -y
- Start and Enable MariaDB Service:
sudo systemctl start mariadb sudo systemctl enable mariadb
- Secure MariaDB:
Run the following command to secure your MariaDB installation:sudo mysql_secure_installation - Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y
Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, remove the test database, and reload privilege tables. Once you are logged in to your database server you need to create a database for Magento installation:
MariaDB [(none)]> CREATE DATABASE magentodb; MariaDB [(none)]> CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'your-str0nge-password'; MariaDB [(none)]> GRANT ALL ON magentodb.* TO 'magentouser'@'localhost' IDENTIFIED BY 'your-str0nge-password' WITH GRANT OPTION; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;
C. Install Composer
Composer is a dependency manager for PHP. It’s essential for installing Magento:
- Download Composer:
curl -sS https://getcomposer.org/installer | php
- Move Composer to a Global Path:
sudo mv composer.phar /usr/local/bin/composer sudo chmod +x /usr/local/bin/composer
D. Download and Extract Magento
1. Download Magento:
You can download the latest version of Magento from GitHub or the official Magento website. Here’s how to download it using `wget`:
wget https://github.com/magento/magento2/archive/refs/heads/2.4-develop.zip
Replace the URL with the latest version available.
2. Extract Magento:
unzip 2.4-develop.zip -d /var/www/html/magento2
E. Install Magento Dependencies with Composer
1. Change to Magento Directory:
cd /var/www/html/magento2
2. Install Dependencies:
composer install
F. Set Proper Permissions and Ownership
1. Change Ownership:
sudo chown -R apache:apache /var/www/html/magento2
2. Set Permissions:
sudo chmod -R 755 /var/www/html/magento2
G. Install Magento via Command Line
1. Run Installation Command:
Use the following command to install Magento. Replace placeholders with your actual database credentials and admin information:
sudo bin/magento setup:install \ --base-url=http://yourdomain.com \ --db-host=localhost \ --db-name=magento \ --db-user=magento \ --db-password=magento \ --admin-firstname=Admin \ --admin-lastname=User \ --admin-email=admin@example.com \ --admin-user=admin \ --admin-password=admin123 \ --language=en_US \ --currency=USD \ --timezone=America/New_York \ --use-rewrites=1
Configure Apache for Magento
To ensure Magento works correctly, you need to configure Apache:
- Create Apache Configuration File:
sudo nano /etc/httpd/conf.d/magento.conf
Add the following content:
<VirtualHost *:80> ServerName yourdomain.com DocumentRoot /var/www/html/magento2 <Directory /var/www/html/magento2> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> ErrorLog /var/log/httpd/magento-error.log CustomLog /var/log/httpd/magento-access.log combined </VirtualHost>
- Enable Apache Configuration:
Restart Apache to apply the changes:sudo systemctl restart httpd
Accessing Magento Admin Interface
Once installed, you can access the Magento admin interface by visiting:
http://yourdomain.com/admin
Log in using the admin credentials you set during installation.
Common Installation Issues and Solutions
Permission Issues
Solution: Ensure that the Apache user has proper ownership and permissions over the Magento directory. Use `chown
` and `chmod
` commands as shown earlier.
Database Connection Failures
Solution: Check your database credentials and ensure that the database server is running. You can verify this by connecting to the database using the `mysql` command.
Composer Installation Errors
Solution: Check if Composer is installed correctly and if it has the necessary permissions. Ensure that your PHP version is compatible with Composer.
Congratulations! You have successfully installed Magento. Thanks for using this tutorial for installing Magento eCommerce software on your AlmaLinux 9 system. For additional help or useful information, we recommend you check the official Magento website.