How To Install Magento on Linux Mint 22
Installing Magento on Linux Mint 22 provides businesses with a powerful, open-source eCommerce platform that offers complete control over their online store infrastructure. This comprehensive guide walks you through every step of the installation process, from system preparation to post-installation optimization.
Magento stands as one of the most robust eCommerce solutions available today, powering thousands of online stores worldwide. Linux Mint 22, based on Ubuntu’s long-term support release, offers exceptional stability and performance for hosting Magento installations. The combination delivers enterprise-grade eCommerce capabilities while maintaining cost-effectiveness and flexibility.
Self-hosting Magento on Linux Mint 22 provides numerous advantages over managed hosting solutions. You gain complete control over server configurations, security implementations, and performance optimizations. Additionally, you can customize the server environment to meet specific business requirements while avoiding recurring hosting fees associated with managed services.
This tutorial covers the installation of Magento 2.4.7, the latest stable version, ensuring you benefit from the most recent security patches and feature enhancements. You’ll learn to configure all necessary components, including Apache web server, MySQL database, PHP runtime environment, and essential security measures.
Before proceeding, ensure you have administrative access to your Linux Mint 22 system, basic familiarity with command-line operations, and sufficient hardware resources to support a Magento installation. The entire process typically takes 2-3 hours, depending on your system’s specifications and internet connection speed.
Understanding Magento System Requirements
Hardware Requirements
Magento demands substantial system resources to operate efficiently. The minimum RAM requirement is 2GB, though 4GB or more is strongly recommended for optimal performance. Production environments should ideally have 8GB or more RAM to handle concurrent user sessions and background processes effectively.
Processor specifications play a crucial role in Magento’s performance. A modern multi-core processor with at least 2.4GHz clock speed ensures smooth operation. For high-traffic stores, consider processors with 4 or more cores to handle concurrent requests efficiently.
Storage considerations include allocating at least 2GB for the Magento installation itself, plus additional space for media files, database storage, and system logs. Solid-state drives (SSDs) significantly improve performance compared to traditional hard drives, particularly for database operations and file I/O intensive tasks.
Network requirements include stable internet connectivity for downloading packages, updates, and handling customer traffic. Production environments should have redundant network connections to ensure continuous availability.
Software Dependencies
Linux Mint 22 provides excellent compatibility with Magento’s software requirements. The system supports all necessary components while maintaining stability and security through regular updates.
PHP version compatibility is critical for Magento installations. Magento 2.4.7 requires PHP 8.1, 8.2, or 8.3. These versions offer improved performance and security features compared to earlier releases. Essential PHP extensions include BCMath, ctype, curl, dom, fileinfo, gd, hash, iconv, intl, json, libxml, mbstring, openssl, pcre, PDO_MySQL, simplexml, soap, sockets, sodium, SPL, xsl, zip, and zlib.
Database requirements specify MySQL 8.0 or MariaDB 10.6 or later versions. These database systems provide the necessary features for Magento’s complex data structures and relationships. Proper database configuration ensures optimal query performance and data integrity.
Web server options include Apache 2.4 with mod_rewrite enabled or Nginx 1.x with appropriate PHP-FPM configuration. Apache offers straightforward configuration for most users, while Nginx provides superior performance for high-traffic scenarios.
Composer 2.7 or later is mandatory for managing Magento’s dependencies and installation process. This dependency management tool simplifies package installation and updates while ensuring compatibility between different components.
SSL certificates are essential for production environments to secure customer data and payment transactions. Modern browsers require HTTPS connections for full functionality, making SSL implementation crucial for any live eCommerce store.
Preparing Linux Mint 22 Environment
System Update and Basic Setup
Begin by updating your Linux Mint 22 system to ensure all packages are current and security patches are applied. Open the terminal and execute the following commands:
sudo apt update && sudo apt upgrade -y
This command refreshes the package repository information and upgrades all installed packages to their latest versions. The process may take several minutes depending on your system’s current state and internet connection speed.
Install essential build tools and utilities required for compiling and installing various components:
sudo apt install -y curl wget git unzip software-properties-common apt-transport-https ca-certificates gnupg lsb-release
These tools enable secure package downloads, version control operations, and repository management. They form the foundation for subsequent installation steps.
Configure sudo privileges if your user account lacks administrative access. Add your username to the sudo group:
sudo usermod -aG sudo $USER
Log out and log back in for the changes to take effect. Verify sudo access by running sudo whoami
, which should return “root”.
Basic firewall configuration protects your system from unauthorized network access. Enable UFW (Uncomplicated Firewall) and configure basic rules:
sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Installing and Configuring Apache Web Server
Install Apache web server using the apt package manager:
sudo apt install -y apache2
Start and enable the Apache service to ensure it runs automatically on system boot:
sudo systemctl start apache2
sudo systemctl enable apache2
Verify Apache installation by accessing http://localhost
in your browser. You should see the Apache2 default page confirming successful installation.
Configure Apache modules required for Magento:
sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod ssl
sudo systemctl restart apache2
Create a virtual host configuration for your Magento installation. Create a new configuration file:
sudo nano /etc/apache2/sites-available/magento.conf
Add the following configuration, replacing yourdomain.com
with your actual domain:
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/magento_error.log
CustomLog ${APACHE_LOG_DIR}/magento_access.log combined
</VirtualHost>
Enable the virtual host and disable the default site:
sudo a2ensite magento.conf
sudo a2dissite 000-default.conf
sudo systemctl reload apache2
MySQL/MariaDB Database Installation
Install MariaDB server, which provides excellent MySQL compatibility:
sudo apt install -y mariadb-server mariadb-client
Start and enable the MariaDB service:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure the database installation by running the security script:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disable remote root login, and remove test databases. These steps significantly improve your database security.
Create a dedicated database and user for Magento:
sudo mysql -u root -p
Execute the following SQL commands within the MySQL prompt:
CREATE DATABASE magento_db;
CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON magento_db.* TO 'magento_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace secure_password
with a strong, unique password. Store these credentials securely as you’ll need them during Magento installation.
PHP Installation and Configuration
Install PHP 8.3 and required extensions:
sudo apt install -y php8.3 php8.3-cli php8.3-common php8.3-mysql php8.3-xml php8.3-curl php8.3-gd php8.3-intl php8.3-mbstring php8.3-soap php8.3-zip php8.3-bcmath php8.3-fpm libapache2-mod-php8.3
Configure PHP settings for Magento requirements. Edit the PHP configuration file:
sudo nano /etc/php/8.3/apache2/php.ini
Modify the following settings:
memory_limit = 2G
max_execution_time = 1800
max_input_time = 1800
upload_max_filesize = 10M
post_max_size = 10M
date.timezone = "UTC"
Restart Apache to apply PHP configuration changes:
sudo systemctl restart apache2
Verify PHP installation by creating a test file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Access http://localhost/info.php
to confirm PHP is working correctly. Remove the test file after verification for security reasons.
Installing Composer and Obtaining Magento
Composer Installation
Download and install Composer globally on your system:
cd /tmp
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
Verify Composer installation:
composer --version
The output should display the Composer version, confirming successful installation.
Magento Authentication Setup
Create an Adobe Commerce account at https://marketplace.magento.com/
to obtain access keys required for downloading Magento. Navigate to your account dashboard and generate public and private keys.
Configure Composer authentication for Magento repository access:
composer config -g http-basic.repo.magento.com <public_key> <private_key>
Replace <public_key>
and <private_key>
with your actual credentials from the Adobe Commerce account.
Understanding Magento licensing is crucial for compliance. Magento Open Source is free to use, while Adobe Commerce requires a commercial license. This guide focuses on Magento Open Source installation.
Store your authentication credentials securely and avoid sharing them with unauthorized personnel. These keys provide access to your Magento account and should be treated as sensitive information.
Downloading Magento via Composer
Navigate to your web server’s document root and create the Magento project:
cd /var/www/html
sudo composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento
This command downloads the latest Magento Community Edition (Open Source) to the magento
directory. The download process may take several minutes depending on your internet connection speed.
Set proper ownership for the Magento files:
sudo chown -R www-data:www-data /var/www/html/magento
Verify the download by checking the directory structure:
ls -la /var/www/html/magento
You should see typical Magento directories including app
, bin
, dev
, lib
, pub
, setup
, and var
.
Database Configuration and Setup
Database Creation
Access your MariaDB server using the credentials created earlier:
mysql -u magento_user -p magento_db
Verify database access and check available tables (should be empty for a new database):
SHOW TABLES;
Test database connectivity from the web directory:
cd /var/www/html/magento
php -r "
try {
\$pdo = new PDO('mysql:host=localhost;dbname=magento_db', 'magento_user', 'secure_password');
echo 'Database connection successful\n';
} catch (PDOException \$e) {
echo 'Connection failed: ' . \$e->getMessage() . '\n';
}
"
Replace secure_password
with your actual database password. Successful connection confirms proper database setup.
Database Optimization
Configure MariaDB for optimal Magento performance by editing the configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Add or modify the following settings under the [mysqld]
section:
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
max_connections = 500
query_cache_size = 64M
query_cache_type = 1
tmp_table_size = 64M
max_heap_table_size = 64M
Restart MariaDB to apply changes:
sudo systemctl restart mariadb
Enable query cache and other performance optimizations to improve database response times for frequently accessed data.
Create a comprehensive database backup strategy before proceeding with installation:
mysqldump -u magento_user -p magento_db > magento_backup_$(date +%Y%m%d).sql
Database Security
Implement additional security measures to protect your Magento database. Create a dedicated database user with limited privileges for routine operations:
mysql -u root -p
CREATE USER 'magento_readonly'@'localhost' IDENTIFIED BY 'readonly_password';
GRANT SELECT ON magento_db.* TO 'magento_readonly'@'localhost';
FLUSH PRIVILEGES;
Configure SSL connections between Magento and the database by generating SSL certificates:
sudo mysql_ssl_rsa_setup --uid=mysql
Update database connection parameters to use SSL encryption for enhanced security.
File Permissions and Ownership Configuration
Setting Proper File Permissions
Magento requires specific file permissions to function correctly. Navigate to the Magento root directory and set appropriate permissions:
cd /var/www/html/magento
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
These commands set files to 644 (read/write for owner, read-only for group and others) and directories to 755 (read/write/execute for owner, read/execute for group and others).
Configure special permissions for critical directories:
chmod -R 777 var/ pub/media/ pub/static/ app/etc/
The var
directory stores cache and session files, pub/media
contains uploaded images and files, pub/static
holds generated CSS and JavaScript files, and app/etc
contains configuration files.
Use find commands for bulk permission changes when needed:
find . -type f -name "*.php" -exec chmod 644 {} \;
find . -type f -name "*.sh" -exec chmod 755 {} \;
Web Server Ownership
Set proper file ownership to ensure the web server can access Magento files:
sudo chown -R www-data:www-data /var/www/html/magento
The www-data
user and group are standard for Apache on Ubuntu and Linux Mint systems. This ownership allows the web server to read files and write to designated directories.
For shared hosting environments, adjust ownership to match your hosting provider’s requirements. Contact your hosting provider for specific user and group names.
Troubleshoot permission-related issues by checking file ownership and permissions:
ls -la /var/www/html/magento
Verify that all files and directories are owned by the web server user and have appropriate permissions.
Running Magento Installation Script
Command Line Installation
Navigate to the Magento root directory and run the installation script:
cd /var/www/html/magento
php bin/magento setup:install \
--base-url=http://yourdomain.com \
--db-host=localhost \
--db-name=magento_db \
--db-user=magento_user \
--db-password=secure_password \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@yourdomain.com \
--admin-user=admin \
--admin-password=Admin123! \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 \
--search-engine=opensearch \
--opensearch-host=localhost \
--opensearch-port=9200
Replace the placeholder values with your actual configuration:
yourdomain.com
: Your domain name or IP addresssecure_password
: Your database passwordadmin@yourdomain.com
: Your admin email addressAdmin123!
: A strong admin password- Adjust timezone and currency as needed
The installation process takes 10-15 minutes to complete. Monitor the output for any error messages or warnings.
Understanding installation parameters helps customize your Magento setup. The --use-rewrites=1
parameter enables URL rewriting for SEO-friendly URLs. The --search-engine
parameter configures the search functionality.
Web-Based Installation Alternative
Access the Magento setup wizard through your web browser by navigating to http://yourdomain.com/setup
. This graphical interface provides a user-friendly alternative to command-line installation.
The web-based installer performs a readiness check to verify system requirements and dependencies. Address any issues identified before proceeding with installation.
Walk through the installation steps, providing database credentials, admin user information, and store configuration details. The web interface validates input and provides helpful error messages for incorrect configurations.
Complete the installation process by clicking the “Install Now” button. The system will create database tables, configure initial settings, and prepare your Magento store for use.
Verifying Installation Success
Check for installation completion messages in the terminal output. Successful installation displays the admin URL and important next steps.
Access the Magento frontend by navigating to your domain in a web browser. You should see the default Magento storefront with sample data (if selected during installation).
Log into the admin panel using the credentials specified during installation. The admin interface provides access to store configuration, product management, and system settings.
Verify database table creation by checking the database:
mysql -u magento_user -p magento_db -e "SHOW TABLES;"
A successful installation creates numerous tables with the magento_
prefix (or your specified prefix).
Post-Installation Configuration
Admin Panel Setup
Access the Magento admin interface using the URL provided during installation, typically http://yourdomain.com/admin
. Log in with the administrator credentials you created.
Complete the initial store configuration by navigating to Stores > Configuration > General > Store Information. Set your store name, phone number, and address information.
Configure payment methods under Stores > Configuration > Sales > Payment Methods. Enable and configure payment processors like PayPal, Stripe, or other preferred options.
Set up shipping methods by navigating to Stores > Configuration > Sales > Shipping Methods. Configure shipping carriers and rates based on your business requirements.
Create additional admin user accounts with appropriate role-based permissions. Navigate to System > User Roles to define custom roles, then create users under System > All Users.
Performance Optimization
Enable production mode for optimal performance:
cd /var/www/html/magento
php bin/magento deploy:mode:set production
Production mode disables debugging, enables caching, and optimizes JavaScript and CSS files for better performance.
Configure caching mechanisms to improve page load times:
php bin/magento cache:enable
php bin/magento cache:flush
Enable all available cache types for maximum performance benefits.
Set up Redis for session storage and page caching:
sudo apt install -y redis-server
sudo systemctl start redis-server
sudo systemctl enable redis-server
Configure Magento to use Redis by editing app/etc/env.php
and adding Redis configuration parameters.
Optimize PHP-FPM settings for better resource utilization:
sudo nano /etc/php/8.1/fpm/pool.d/www.conf
Adjust pm.max_children
, pm.start_servers
, and pm.min_spare_servers
based on your server specifications.
Essential Extensions and Modules
Install critical security patches using Composer:
composer require magento/quality-patches
php bin/magento module:enable Magento_Quality_Patches
php bin/magento setup:upgrade
Enable necessary modules for your store functionality:
php bin/magento module:enable Magento_Catalog Magento_Customer Magento_Checkout
php bin/magento setup:upgrade
Configure cron jobs for Magento background tasks:
crontab -e
Add the following cron entries:
* * * * * php /var/www/html/magento/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule"
Set up automated backups using a simple script:
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
mysqldump -u magento_user -p magento_db > /backup/magento_db_$DATE.sql
tar -czf /backup/magento_files_$DATE.tar.gz /var/www/html/magento
Security Hardening and Best Practices
Server Security
Configure advanced firewall rules to restrict access to sensitive ports:
sudo ufw deny 3306/tcp
sudo ufw allow from 127.0.0.1 to any port 3306
These rules block external access to MySQL while allowing local connections.
Disable unnecessary services to reduce attack surface:
sudo systemctl disable bluetooth
sudo systemctl disable cups
sudo systemctl disable avahi-daemon
Install and configure Fail2ban for brute force protection:
sudo apt install -y fail2ban
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
Create a custom Fail2ban configuration for Apache:
sudo nano /etc/fail2ban/jail.local
Add the following configuration:
[apache-auth]
enabled = true
port = http,https
logpath = /var/log/apache2/error.log
maxretry = 3
findtime = 600
bantime = 3600
Implement SSL certificates using Let’s Encrypt:
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d yourdomain.com
Magento-Specific Security
Secure the admin URL by changing it from the default /admin
:
php bin/magento setup:config:set --backend-frontname=custom_admin_url
Replace custom_admin_url
with a unique, hard-to-guess path.
Configure two-factor authentication for admin users:
php bin/magento module:enable Magento_TwoFactorAuth
php bin/magento setup:upgrade
Navigate to Stores > Configuration > Security > 2FA to configure authentication methods.
Implement regular security patches and updates:
composer require magento/security-package
php bin/magento setup:upgrade
Create a comprehensive backup strategy including:
- Daily database backups
- Weekly full file system backups
- Monthly off-site backup storage
- Automated backup verification
Troubleshooting Common Issues
Installation Errors
PHP Extension Missing Errors:
Verify all required PHP extensions are installed:
php -m | grep -E 'curl|dom|gd|intl|mbstring|mysql|soap|xsl|zip'
Install missing extensions:
sudo apt install -y php8.1-extension_name
Database Connection Issues:
Test database connectivity manually:
mysql -u magento_user -p -h localhost magento_db
Check database credentials in app/etc/env.php
and verify they match your database configuration.
File Permission Problems:
Reset file permissions using the provided commands:
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod -R 777 var/ pub/media/ pub/static/ app/etc/
Memory Limit and Timeout Issues:
Increase PHP memory limits and execution times:
sudo nano /etc/php/8.1/apache2/php.ini
Set memory_limit = 2G
and max_execution_time = 1800
.
Performance Issues
Slow Page Load Times:
Enable all caching mechanisms:
php bin/magento cache:enable
php bin/magento cache:flush
Configure Redis for improved caching performance.
Cache-Related Problems:
Clear all caches when experiencing issues:
php bin/magento cache:clean
php bin/magento cache:flush
Database Performance Issues:
Optimize database queries by enabling slow query logging:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Add:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
Server Resource Optimization:
Monitor system resources using:
top
htop
iostat
Adjust PHP-FPM and Apache settings based on resource usage patterns.
Maintenance and Updates
Regular Maintenance Tasks
Implement automated backup procedures using cron jobs:
#!/bin/bash
# Daily backup script
DATE=$(date +%Y%m%d)
mysqldump -u magento_user -p magento_db > /backup/magento_db_$DATE.sql
tar -czf /backup/magento_files_$DATE.tar.gz /var/www/html/magento
find /backup -type f -mtime +30 -delete
Schedule the script to run daily at 2 AM:
0 2 * * * /path/to/backup_script.sh
Monitor system resources regularly:
df -h
free -h
systemctl status apache2 mariadb
Perform security updates monthly:
sudo apt update && sudo apt upgrade -y
composer update
Manage log files to prevent disk space issues:
sudo logrotate -f /etc/logrotate.d/apache2
find /var/log -type f -name "*.log" -mtime +30 -delete
Magento Updates
Plan Magento version upgrades carefully by:
- Creating full system backups
- Testing updates in staging environments
- Reviewing release notes for breaking changes
- Scheduling updates during low-traffic periods
Create a staging environment for testing:
cp -r /var/www/html/magento /var/www/html/magento-staging
Test updates in staging before applying to production:
cd /var/www/html/magento-staging
composer update
php bin/magento setup:upgrade
Backup before major updates:
mysqldump -u magento_user -p magento_db > magento_pre_update_backup.sql
tar -czf magento_files_pre_update.tar.gz /var/www/html/magento
Manage extension compatibility by reviewing update requirements and testing third-party modules in staging environments.
Congratulations! You have successfully installed Magento. Thanks for using this tutorial for installing the latest version of the Magento eCommerce platforms on Linux Mint 22. For additional help or useful information, we recommend you check the official Magento website.