How To Install Magento on CentOS Stream 10
In this tutorial, we will show you how to install Magento on CentOS Stream 10. Magento stands as one of the most powerful and flexible e-commerce platforms available today, powering thousands of online stores worldwide. Setting up Magento on CentOS Stream 10 provides a robust and stable foundation for your e-commerce business. This comprehensive guide walks you through the complete installation process, from preparing your server environment to post-installation configuration and troubleshooting.
Whether you’re a developer, system administrator, or store owner looking to set up your own Magento instance, this step-by-step tutorial will guide you through every aspect of the installation process on CentOS Stream 10. By following these instructions carefully, you’ll have a fully functional Magento store ready for customization and business use.
System Requirements for Magento
Before beginning the installation process, it’s essential to understand the hardware and software requirements for running Magento 2.4.6 effectively on CentOS Stream 10.
Hardware Recommendations
For optimal performance, your server should meet or exceed these specifications:
- CPU: Minimum 2-4 cores for development, 4-8 cores recommended for production
- RAM: At least 4GB for development, 8GB or more recommended for production environments
- Storage: Minimum 20GB SSD storage, with additional space for product data, media, and backups
Software Prerequisites
Magento 2.4.6 requires the following software components:
- Apache 2.4 or higher with mod_rewrite and mod_version enabled
- PHP 8.1 or 8.2 (we’ll use 8.2 in this guide)
- MySQL 8.0 or MariaDB 10.4+
- Elasticsearch 7.17 or OpenSearch 1.2+ for catalog search functionality
- Composer 2.x for dependency management
Preparing CentOS Stream 10 Environment
The first step is to prepare your CentOS Stream 10 system for Magento installation. We’ll update the system, install essential utilities, and configure proper user permissions.
Updating System Packages
Begin by updating all system packages to the latest versions:
sudo dnf update -y
Installing Essential Tools
Install the required utilities that will be needed throughout the installation process:
sudo dnf install -y wget unzip git nano epel-release
Setting Up User and Permissions
For security purposes, it’s recommended to create a dedicated user for running Magento rather than using the root account:
sudo useradd -m -U -r -d /opt/magento magento
sudo usermod -aG wheel magento
Configuring SELinux
CentOS Stream 10 comes with SELinux enabled by default. To ensure Magento functions properly, configure SELinux appropriately:
sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1
sudo setsebool -P httpd_execmem 1
sudo setsebool -P httpd_use_nfs 1
For a development environment, you might consider setting SELinux to permissive mode:
sudo setenforce 0
To make this change permanent, edit the SELinux configuration file:
sudo nano /etc/selinux/config
Change SELINUX=enforcing
to SELINUX=permissive
Firewall Configuration
Configure the firewall to allow web traffic:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Installing and Configuring Apache Web Server
Apache is the recommended web server for Magento installations. Let’s install and configure it properly for optimal performance.
Installing Apache
sudo dnf install -y httpd
Enabling Required Modules
Ensure that essential Apache modules are enabled:
sudo dnf install -y mod_ssl
The rewrite module should be enabled by default. Verify with:
apachectl -M | grep rewrite
Configuring Virtual Host
Create a virtual host configuration for your Magento site:
sudo nano /etc/httpd/conf.d/magento.conf
Add the following configuration, replacing yourdomain.com
with your actual domain name:
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/magento_error.log
CustomLog /var/log/httpd/magento_access.log combined
</VirtualHost>
Setting Up Document Root
Create the document root directory and set appropriate permissions:
sudo mkdir -p /var/www/html/magento
sudo chown -R magento:apache /var/www/html/magento
sudo chmod -R 755 /var/www/html/magento
Starting and Enabling Apache
Start the Apache service and enable it to run at startup:
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
Installing and Configuring PHP 8.2
Magento 2.4.6 requires PHP 8.1 or 8.2. Let’s install PHP 8.2 and all required extensions.
Adding PHP Repository
CentOS Stream 10 may not have PHP 8.2 in its default repositories. Add the Remi repository:
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-10.rpm
Installing PHP and Extensions
Enable the PHP 8.2 module and install PHP with all required extensions:
sudo dnf module reset php
sudo dnf module enable php:remi-8.2
sudo dnf install -y php php-cli php-common php-fpm php-mysqlnd php-zip php-gd php-mcrypt php-mbstring php-xml php-json php-bcmath php-soap php-intl php-sockets php-curl php-opcache php-sodium
Configuring PHP Settings
Adjust PHP settings for optimal Magento performance:
sudo nano /etc/php.ini
Modify the following settings:
memory_limit = 2G
max_execution_time = 1800
zlib.output_compression = On
max_input_vars = 10000
upload_max_filesize = 64M
post_max_size = 64M
date.timezone = America/New_York
Be sure to replace the timezone with your correct region
Configuring PHP-FPM
If you’re using PHP-FPM, configure it appropriately:
sudo nano /etc/php-fpm.d/www.conf
Ensure these settings are properly configured:
user = apache
group = apache
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = apache
listen.group = apache
listen.mode = 0660
Start and enable PHP-FPM:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
Configuring OPcache
For improved performance, configure PHP OPcache:
sudo nano /etc/php.d/10-opcache.ini
Add or modify these settings:
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 256
opcache.max_accelerated_files = 32531
opcache.interned_strings_buffer = 32
opcache.validate_timestamps = 0
opcache.save_comments = 1
opcache.enable_file_override = 1
Restart PHP-FPM to apply changes:
sudo systemctl restart php-fpm
Setting Up MySQL 8.0 Database
Magento requires a properly configured MySQL database. Let’s install and set it up.
Installing MySQL
sudo dnf install -y mysql-server
Starting and Securing MySQL
Start MySQL and enable it to run at startup:
sudo systemctl start mysqld
sudo systemctl enable mysqld
Secure the MySQL installation:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, remove test database, and reload privilege tables
Creating Database and User for Magento
Log in to MySQL:
sudo mysql -u root -p
Create a database and user for Magento:
CREATE DATABASE magento;
CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON magento.* TO 'magentouser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace ‘StrongPassword’ with a secure password of your choice.
Optimizing MySQL for Magento
Edit the MySQL configuration:
sudo nano /etc/my.cnf
Add these settings under the [mysqld]
section:
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
max_allowed_packet = 64M
wait_timeout = 28800
interactive_timeout = 28800
Restart MySQL to apply changes:
sudo systemctl restart mysqld
Installing Composer for Magento
Composer is required to install Magento and manage its dependencies.
Installing Composer
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Verify the installation:
composer --version
Configuring Memory Limits
To prevent memory limit issues during Magento installation, increase Composer’s memory limit:
sudo nano /etc/php.ini
Ensure this setting is present:
memory_limit = 2G
Setting Up Magento Authentication
To download Magento, you’ll need authentication keys from the Magento Marketplace. Create an account at marketplace.magento.com and generate access keys from your account section
Add your authentication keys to Composer’s global configuration:
composer global config http-basic.repo.magento.com <public_key> <private_key>
Replace <public_key>
and <private_key>
with your actual Magento Marketplace keys.
Installing and Configuring Elasticsearch 7.17
Elasticsearch is required for Magento’s catalog search functionality.
Installing Java
Elasticsearch requires Java:
sudo dnf install -y java-11-openjdk
Installing Elasticsearch
Add the Elasticsearch repository:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
Create the repository file:
sudo nano /etc/yum.repos.d/elasticsearch.repo
Add these lines:
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
Install Elasticsearch:
sudo dnf install -y elasticsearch
Configuring Elasticsearch
Edit the Elasticsearch configuration:
sudo nano /etc/elasticsearch/elasticsearch.yml
Update these settings:
cluster.name: magento
node.name: magento-node1
network.host: 127.0.0.1
http.port: 9200
discovery.type: single-node
Setting Memory Limits
Configure JVM heap size:
sudo nano /etc/elasticsearch/jvm.options
Set appropriate values based on your server’s available memory:
-Xms512m
-Xmx512m
Starting and Enabling Elasticsearch
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
Verify Elasticsearch is running:
curl -X GET "localhost:9200/"
Securing Your Server Environment
Before installing Magento, let’s implement some basic security measures.
Creating Self-Signed SSL Certificate
For development purposes, you can use a self-signed SSL certificate:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/magento.key -out /etc/pki/tls/certs/magento.crt
Configuring Apache for HTTPS
Update your virtual host configuration to support HTTPS:
sudo nano /etc/httpd/conf.d/magento.conf
Add this configuration:
<VirtualHost *:443>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html/magento
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/magento.crt
SSLCertificateKeyFile /etc/pki/tls/private/magento.key
<Directory /var/www/html/magento>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/magento_error.log
CustomLog /var/log/httpd/magento_access.log combined
</VirtualHost>
Restart Apache:
sudo systemctl restart httpd
Setting Proper File Permissions
Ensure secure file permissions for your Magento installation:
cd /var/www/html/magento
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 magento:apache .
chmod u+x bin/magento
Downloading and Installing Magento 2.4.6
Now we’re ready to download and install Magento.
Downloading Magento via Composer
Switch to the magento user:
sudo su - magento
Navigate to the document root:
cd /var/www/html/magento
Download Magento using Composer:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.6 .
When prompted, enter your Magento Marketplace authentication keys
Setting File Permissions
Apply proper file 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 {} \;
chmod u+x bin/magento
Running the Installation Command
Install Magento with the command-line installer:
bin/magento setup:install \
--base-url=https://yourdomain.com \
--db-host=localhost \
--db-name=magento \
--db-user=magentouser \
--db-password=StrongPassword \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@yourdomain.com \
--admin-user=admin \
--admin-password=AdminPassword123 \
--language=en_US \
--currency=USD \
--timezone=America/New_York \
--use-rewrites=1 \
--search-engine=elasticsearch7 \
--elasticsearch-host=localhost \
--elasticsearch-port=9200
Replace the placeholder values with your actual configuration details
Verifying Installation
After the installation completes, verify that Magento is working by accessing your domain in a web browser. You should see the Magento storefront.
Access the admin panel by navigating to the admin URL specified during installation (default is /admin
).
Post-Installation Configuration
After successfully installing Magento, perform these essential configuration tasks.
Accessing the Admin Panel
Navigate to your admin URL (e.g., https://yourdomain.com/admin
) and log in with the credentials you set during installation.
Setting Up Cron Jobs
Magento requires several cron jobs for proper operation:
sudo su - magento
crontab -e
Add these lines:
* * * * * /usr/bin/php /var/www/html/magento/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/magento/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/magento/update/cron.php >> /var/www/html/magento/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/magento/bin/magento setup:cron:run >> /var/www/html/magento/var/log/setup.cron.log
Configuring Cache Management
In the Magento admin panel, navigate to System > Cache Management and refresh all cache types.
For improved performance, consider enabling Redis for cache storage:
sudo dnf install -y redis
sudo systemctl start redis
sudo systemctl enable redis
Edit the Magento environment configuration:
sudo nano /var/www/html/magento/app/etc/env.php
Add Redis cache configuration according to Magento documentation.
Setting Up Indexers
Run the indexer:
bin/magento indexer:reindex
Configure indexers to update on schedule:
bin/magento indexer:set-mode schedule
Configuring Email Settings
In the admin panel, navigate to Stores > Configuration > Advanced > System > Mail Sending Settings to configure your email settings.
Setting Up Backup Procedures
Configure regular backups of your database and file system:
sudo nano /etc/cron.d/magento-backup
Add a weekly backup schedule:
0 2 * * 0 magento /usr/bin/php /var/www/html/magento/bin/magento setup:backup --db --media --code
Troubleshooting Common Installation Issues
Even with careful preparation, you might encounter issues during the installation. Here are solutions to common problems.
Permission-Related Problems
If you encounter permission errors, verify and fix permissions:
sudo chown -R magento:apache /var/www/html/magento
sudo find /var/www/html/magento -type f -exec chmod 644 {} \;
sudo find /var/www/html/magento -type d -exec chmod 755 {} \;
sudo chmod -R g+w /var/www/html/magento/var
sudo chmod -R g+w /var/www/html/magento/pub
sudo chmod -R g+w /var/www/html/magento/app/etc
sudo chmod -R g+w /var/www/html/magento/generated
Database Connection Issues
If you experience database connection problems:
- Verify database credentials in app/etc/env.php
- Ensure the MySQL service is running
- Check that the database user has proper permissions
Web Server Configuration Errors
For Apache issues:
- Verify that mod_rewrite is enabled
- Check that the virtual host configuration is correct
- Ensure .htaccess files are properly configured
PHP Extension Problems
If PHP extensions are missing:
sudo dnf install -y php-bcmath php-intl php-soap php-xml php-xsl php-gd php-curl php-mbstring php-zip
sudo systemctl restart php-fpm
Memory Limit Issues
For memory-related errors, increase PHP memory limits:
sudo nano /etc/php.ini
Adjust these settings:
memory_limit = 2G
max_execution_time = 1800
Elasticsearch Connection Problems
If Magento can’t connect to Elasticsearch:
- Verify Elasticsearch is running:
sudo systemctl status elasticsearch
- Check connectivity:
curl -X GET "localhost:9200/"
- Ensure Magento is configured to use the correct Elasticsearch host and port
Congratulations! You have successfully installed Magento. Thanks for using this tutorial for installing Magento e-commerce on your CentOS Stream 10 system. For additional help or useful information, we recommend you check the official Magento website.