UbuntuUbuntu Based

How To Install Magento on Ubuntu 24.04 LTS

Install Magento on Ubuntu 24.04

Magento stands out as one of the most popular and powerful eCommerce platforms available. It offers unparalleled flexibility for building and managing online stores of virtually any size. With its vast library of extensions, robust catalog management features, and an active developer community, Magento has earned its reputation as a top choice for businesses seeking a scalable solution.

Ubuntu 24.04 LTS provides a secure, stable, and regularly updated environment ideal for hosting a Magento installation. As a Long-Term Support release, Ubuntu 24.04 receives extended maintenance and security updates. Combining these strengths with Magento’s advanced capabilities enables users to build performant online marketplaces.

Below is a comprehensive guide that covers everything necessary to install and configure Magento on Ubuntu 24.04 LTS. It includes step-by-step instructions, from system preparation to final optimizations. These instructions assume a certain level of comfort with Linux commands, but they also break down important concepts in a straightforward way. The sections detail prerequisites, server setup, database configuration, Magento’s installation process, security measures, testing, troubleshooting, and suggestions for long-term maintenance. Distribute relevant keywords, such as Magento installation, Ubuntu server, eCommerce environment, and Linux hosting, to ensure better search visibility for those seeking to set up Magento on Ubuntu 24.04 LTS.

Prerequisites

Before starting the installation process, confirm that you have the following components and configurations in place:

System Requirements

1. Ubuntu 24.04 LTS Installation: A fresh install of Ubuntu 24.04 LTS on a local or virtual machine.
2. Hardware Specifications: At least 2 GB of RAM, though 4 GB or more is recommended for running Magento.
3. Processor: Multi-core CPUs are ideal for Magento as they handle multiple PHP and MySQL processes efficiently.
4. Storage: SSDs improve speed dramatically. Ensure at least 10 GB of free disk space for Magento and related dependencies.
5. Root or Sudo Privileges: Proper permissions are essential for installing packages and configuring services.

Required Software Components

1. Web Server: Apache or Nginx (Apache is often used for Magento due to its robust documentation).
2. PHP 8.3: Magento requires several PHP extensions, such as curl, gd, mysqli, and xml. Confirm they are enabled.
3. MySQL 8.0 or MariaDB: This will house your Magento database.
4. Composer: Magento leverages Composer for dependency management.
5. OpenSSL or Let’s Encrypt: SSL certificates are highly recommended for a production store. SSL secures data transmission and fosters trust with customers.

To ensure a seamless experience, plan out the system requirements and check that your machine meets the minimum criteria before beginning. These details set the foundation for installing Magento on Ubuntu 24.04 LTS properly.

Preparation Steps

A solid preparation phase can simplify the Magento installation process immensely. By updating packages and configuring your web server environment first, errors are less likely to occur down the line.

System Updates

1. Update Package Repositories: Start by refreshing the existing repositories:

sudo apt update

2. Upgrade Existing Packages: Ensure you have the latest versions of all installed packages:

sudo apt upgrade -y

3. Install Essential Tools: Tools such as curl, git, zip, and unzip are commonly used. To add them:

sudo apt install curl git zip unzip -y

Performing these steps guarantees that the system is current, which helps prevent version conflicts later. Many Linux tutorials advocate for updating and upgrading before installing new software to maintain optimal stability.

Server Stack Installation

1. Apache/Nginx Setup: For this guide, Apache will be used. To install Apache, run:

sudo apt install apache2 -y

Enable Apache to start on boot and verify its status:

sudo systemctl enable apache2
sudo systemctl status apache2

2. PHP 8.3 Installation: Because Magento requires specific PHP extensions, install them all together:

sudo apt install php8.3 \
php8.3-common \
php8.3-gd \
php8.3-mysql \
php8.3-xml \
php8.3-mbstring \
libapache2-mod-php8.3 \
-y

3. MySQL or MariaDB Database Setup: Magento relies on a database. A typical command to install MySQL:

sudo apt install mysql-server -y

Then enable and verify:

sudo systemctl enable mysql
sudo systemctl status mysql

Using MariaDB is also possible; the process is similar.

4. Composer Installation: Magento uses Composer for package dependency management. Install it with:

sudo apt install composer -y

Double-check Composer’s version with:

composer --version

These steps complete the core environment setup. With Apache, PHP 8.3, a database server, and Composer installed, you’re well-positioned to configure your database for Magento.

Database Configuration

Magento requires a dedicated database and user with the necessary privileges. This approach separates your Magento environment from other services and helps enhance security.

  1. Log into MySQL:
    sudo mysql
    
  2. Create a Database: Example:
    CREATE DATABASE magento_db;
    
  3. Create a User for Magento: Use a secure username and password:
    CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
    
  4. Grant the Necessary Permissions:
    GRANT ALL PRIVILEGES ON magento_db.* TO 'magento_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
    

In many production setups, storing database credentials in a password manager or a secure file is advisable. Tightly controlling user permissions reduces the risk of unauthorized access. Additionally, consider fortifying database security by limiting remote access and monitoring logs. These tactics help maintain a robust foundation for a Magento eCommerce environment.

Magento Installation Process

The core Magento installation is the most extensive part of this guide. It begins with preparing Magento access keys and ends with verifying that all essential files have been properly installed. Paying close attention to permissions is vital for a trouble-free setup.

Authentication Setup

1. Create a Magento Marketplace Account: Visit the Magento Marketplace to sign up. This account provides access keys used to pull Magento modules and resources.
2. Generate Access Keys: After creating an account, navigate to “Access Keys” and create keys specifically for your project. Make note of both the Public and Private keys.

Core Installation Steps

1. Navigate to the Web Root: Typically, Apache’s default root is /var/www/html/. Enter:

cd /var/www/html/

2. Download Magento Files: Use Composer to create a new Magento project. Replace the placeholder with your Magento authentication keys:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento

When prompted, enter your Magento credentials (Public as username, Private as password).

3. Set Directory Permissions: Ensure the magento directory is accessible by Apache:

sudo chown -R www-data:www-data /var/www/html/magento
sudo find /var/www/html/magento -type d -exec chmod 755 {} \;
sudo find /var/www/html/magento -type f -exec chmod 644 {} \;

4. Install Dependencies: Composer automatically handles this, but you can run an update if necessary:

cd /var/www/html/magento
composer update

5. Initiate Magento Setup: Execute the Magento setup script:

bin/magento setup:install \
--base-url=http://your-server-ip/magento \
--db-host=localhost \
--db-name=magento_db \
--db-user=magento_user \
--db-password=StrongPassword123! \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@example.com \
--admin-user=admin \
--admin-password=AdminPass123! \
--backend-frontname=admin

6. Enable Magento Modules:

bin/magento module:enable --all
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f

Everything from module management to static content deployment happens within these commands. Monitor the terminal output for any warnings or errors. Once the process completes, the Magento software should be fully installed. The next step is configuring the platform for production-readiness, including performance tweaks and SSL implementation.

Post-Installation Configuration

A post-installation process is essential to ensure effective operation. It involves configuring virtual hosts or server blocks, enhancing performance settings, enabling SSL, and fine-tuning your Magento store to meet user needs.

Web Server Setup

1. Configure an Apache Virtual Host: Create or edit a magento.conf file in /etc/apache2/sites-available/:

<VirtualHost *:80>
    ServerName your-domain.com
    DocumentRoot /var/www/html/magento
    <Directory /var/www/html/magento>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

2. Enable the Site and Rewrite Module:

sudo a2enmod rewrite
sudo a2ensite magento.conf
sudo systemctl restart apache2

3. SSL Certificates: Acquire SSL certificates from recognized sources, such as Let’s Encrypt or a commercial provider. An SSL certificate ensures encrypted connections, which is vital for eCommerce operations.

Magento Configuration

1. Basic Store Setup: Access the Magento admin panel by visiting http://your-server-ip/magento/admin or https://your-domain.com/admin. Follow the on-screen prompts to customize store details such as default currency, language, and tax settings.
2. Cache Configuration: Magento uses caches extensively. By default, these caches optimize performance. Clear or flush caches if changes don’t immediately appear:

bin/magento cache:clean
bin/magento cache:flush

3. URL Rewrites: Enable or disable URL rewrites to improve SEO. In many cases, they’re enabled by default.
4. Performance Optimization: Magento permits multiple performance-related settings, like enabling production mode, utilizing Varnish, or enabling Redis for caching. These steps can boost page load speeds.

Applying these changes ensures your storefront accurately reflects your brand identity. The next step is implementing additional security measures crucial for a professional eCommerce platform.

Security Measures

Protecting your Magento store requires multiple layers. Below are some recommended practices geared toward reinforcing overall security:

  1. File Permissions: Restrict file permissions to the recommended Magento settings for preventing unauthorized modification.
  2. SSL Implementation: Secure all traffic with HTTPS. Encryption ensures that sensitive information—like customer login details—remains private.
  3. Secure Admin Access: Update default admin path by using the --backend-frontname parameter. Restrict access to the admin panel based on trusted IP addresses if possible.
  4. Database Security: Regularly change passwords and monitor logs for unusual activity.
  5. Firewall Configuration: Use ufw or other firewall tools. For instance:
    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
    sudo ufw enable
    

These steps significantly reduce vulnerability while ensuring compliance with common security standards. Magento’s architecture is secure by default, yet consistent maintenance and monitoring are paramount to safeguarding an eCommerce business.

Testing and Verification

Once Magento is installed, test the following items to confirm everything is functioning correctly:

  1. Frontend Access: Visit http://your-server-ip/magento to see if the default Magento theme appears.
  2. Admin Panel: Go to http://your-server-ip/magento/admin and log in with your configured admin credentials.
  3. Database Connectivity: If the storefront or admin area loads correctly, MySQL is likely configured properly.
  4. Cache Status: Confirm that Magento caches are enabled to maximize performance.
  5. Security Checks: Access the site using HTTPS to confirm your SSL certificate is working correctly.

Proper testing ensures the store is ready to go live or move into further development stages. It also helps pinpoint any immediate issues that need resolving before customer traffic arrives.

Install Magento on Ubuntu 24.04

Troubleshooting Guide

Despite thorough preparation, errors can appear during or after installation. Here are common pitfalls and resolutions:

  1. Permission Issues: If Apache cannot read or write necessary files, double-check file ownership and permission settings. Running sudo chown -R www-data:www-data /var/www/html/magento often fixes this.
  2. Database Errors: If Magento cannot connect to the database, verify the db-host, db-user, and db-password in your install command or env.php file. Make sure privileges are properly granted.
  3. Web Server Not Responding: Ensure that Apache or Nginx is running. Use sudo systemctl status apache2 or sudo systemctl status nginx to confirm.
  4. Performance Bottlenecks: If pages load slowly, consider enabling production mode:
    bin/magento deploy:mode:set production
    

    Also, check if you can integrate Varnish or Redis for better caching.

  5. Extension Compatibility: Some third-party modules can conflict with core files. Temporarily disable them to isolate the source of errors.

System logs in /var/log/apache2 or var/log under your Magento folder often reveal the root cause of issues. Resolving these problems quickly improves store uptime and user satisfaction.

Congratulations! You have successfully installed Magento. Thanks for using this tutorial for installing Magento on Ubuntu 24.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the Magento website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button