How to Create a Simple Hello World Module for Magento 2



Introduction to Installing Magento 2

Magento 2 continues to be one of the most powerful and flexible open‑source eCommerce platforms available in 2025. With extensive customization options, scalability, and support for complex product catalogs, Magento 2 enables businesses of all sizes to build professional online stores. However, installing Magento 2 properly — whether on a local development environment or a live Linux server — requires careful attention to system requirements, dependencies, and platform configuration.

In this comprehensive step‑by‑step Magento 2 installation guide, we walk you through everything from preparing your environment and meeting prerequisites to running the installation via Composer and verifying your deployment. By following this guide, you’ll learn not only how to install Magento 2 but also best practices that reduce setup errors and improve your store’s stability and performance.

This article covers Magento 2 Core Platform setup using Composer, explains system requirements for Magento 2 Open Source in 2025, and highlights common installation challenges and how to resolve them.

Magento 2 System Requirements

Before beginning the installation process, ensure your environment meets Magento 2’s system requirements. Magento’s platform is resource‑intensive and will not install or run correctly on unsupported software stacks.

  • Operating System — Linux x86‑64 is recommended for production servers. macOS or Linux can be used for local development. Windows environments are supported primarily through local stacks like XAMPP or WSL2.
  • Web Server — Apache 2.4 or later and NGINX 1.18+ are supported web servers. Ensure modules such as mod_rewrite (for URL rewrites) are available if using Apache.
  • Database — MySQL 8.0 or later or MariaDB 10.4+ is required. These databases handle Magento’s data storage and must be correctly secured and configured.
  • PHP Version — Magento 2.4.x versions in 2025 require PHP 8.1 or PHP 8.2. Specific PHP extensions must be installed, including ext‑bcmath, ext‑ctype, ext‑curl, ext‑gd, ext‑intl, ext‑mbstring, ext‑soap, ext‑xml, ext‑zip, and others.
  • Search Engine — From Magento 2.4 onwards, a search engine like Elasticsearch or OpenSearch is required. It powers internal search and catalog indexing.
  • Composer — Composer is a PHP dependency manager. Magento uses it to install and manage core platform components. Install Composer 2.x before proceeding.

Meeting these requirements ensures a smooth installation and avoids many common setup errors.

Preparing Your Environment

Proper preparation prevents errors during the Magento 2 installation. Whether you are installing on a hosted VPS or as a local development environment, the following steps should be completed first.

1. Update Your System Packages

On a Linux server such as Ubuntu or Debian, updating your package index and upgrading existing packages is essential. This ensures that you install the latest security patches and dependencies required by Magento.

Run:

sudo apt update && sudo apt upgrade -y

This command fetches and installs updates for all installed software packages.

2. Install the Web Server

Install Apache or NGINX depending on your preference. Apache is often easier for beginners due to built‑in modules, while NGINX can offer performance advantages in high‑traffic environments.

For Apache:

sudo apt install apache2

Enable rewrite modules for SEO‑friendly URLs:

sudo a2enmod rewrite

Restart Apache for the settings to take effect:

sudo systemctl restart apache2

3. Install PHP and Required Extensions

Magento requires a specific set of PHP modules. Install them along with PHP itself:

sudo apt install php8.1 php8.1-cli php8.1-fpm php8.1-mbstring php8.1-intl php8.1-xml php8.1-gd php8.1-curl php8.1-zip php8.1-soap php8.1-bcmath php8.1-mysql

Verify PHP version:

php -v

If additional modules are missing, install them as needed.

4. Install and Configure the Database Server

Install MariaDB or MySQL and secure the installation:

sudo apt install mariadb-server

Then run the secure installation tool:

sudo mysql_secure_installation

Create a database and user for Magento:

sudo mysql -u root -p

Within the MySQL prompt:

CREATE DATABASE magento2;

CREATE USER 'magento2user'@'localhost' IDENTIFIED BY 'strong_password';

GRANT ALL PRIVILEGES ON magento2.* TO 'magento2user'@'localhost';

FLUSH PRIVILEGES;

EXIT;

5. Install Elasticsearch

Magento requires a search engine for catalog search and index management.

Install Elasticsearch on Ubuntu via packages or as a service. Ensure it is running before proceeding.

6. Install Composer

Download Composer and make it globally available:

php -r "copy('https://getcomposer.org/installer', 'composer‑setup.php');"

php composer‑setup.php --install‑dir=/usr/local/bin --filename=composer

Verify:

composer --version

Magento 2 Installation via Composer

Composer is the recommended and most flexible way to install Magento 2. It manages dependencies and retrieves official packages from Magento’s repositories. Before installing, you’ll need Magento Marketplace authentication keys — these function as credentials that permit Composer to access Adobe Commerce packages.

Step 1: Create Project Directory

Create a directory where Magento will be installed and navigate to it:

mkdir /var/www/magento2

cd /var/www/magento2

Step 2: Retrieve Magento with Composer

Run the Composer command with your marketplace keys to download Magento 2:

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

Composer will fetch all required packages and place them in your project directory.

Step 3: Set Permissions

Magento requires specific permissions for file access. Adjust them accordingly:

sudo chown -R www‑data:www‑data /var/www/magento2

sudo find . -type d -exec chmod 755 {} \;

sudo find . -type f -exec chmod 644 {} \;

Step 4: Run Setup Installer

Execute the Magento setup installer from the command line. Replace placeholder values with your database and admin info:

php bin/magento setup:install --base-url=http://yourdomain.com --db-host=localhost --db-name=magento2 --db-user=magento2user --db-password=strong_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/New_York --use-rewrites=1

This command installs Magento and configures the storefront and admin panel. Once complete, you’ll see success messages with the admin panel URL.

Post‑Installation Configuration

With Magento installed, additional setup configurations improve performance and usability.

  • Configure Cron Jobs — Magento requires cron jobs for tasks like indexing, email queue handling, and cache cleanup. Set up a cron for your Magento directory.
  • Enable Production Mode — For live environments, switch Magento to production mode to improve performance.
  • Configure HTTPS — Secure your site with SSL/TLS certificates and update your base URLs to HTTPS.
  • Install Caching Services — Services like Redis enhance session storage and cache performance.
  • Set Up Backups — Implement regular backups of your database and Magento files to avoid data loss.

Pro Tips for Magento 2 Installation

  • Use Latest Supported Software — Always check Magento’s official documentation to confirm the supported versions of PHP, databases, and servers before installing.
  • Test Locally First — Develop and test your installation on a localhost environment before deploying to production.
  • Monitor Logs — Magento log files provide valuable insights if errors occur during setup or operation.
  • Use Composer Auth Keys — Maintain secure storage of Magento Marketplace keys to manage upgrades and dependency updates smoothly.
  • Optimize Server Resources — Allocate sufficient memory and CPU resources to handle Magento’s processing and indexing operations.

Frequently Asked Questions (FAQs)

  • What version of PHP should I use? — For Magento 2.4.x in 2025, use PHP 8.1 or PHP 8.2 and ensure all required extensions are installed.
  • Is Elasticsearch mandatory? — Yes. Versions of Magento 2.4 and above depend on Elasticsearch (or OpenSearch) for catalog search services.
  • Can I install Magento on Windows? — Yes, using stacks like XAMPP but this is mostly suitable for development and local testing.
  • How do I fix permission errors? — Ensure file and directory permissions are correctly set, and ownership is assigned to the web server user.
  • Do I need a license for Magento Open Source? — No. Magento Open Source is free, but you must provide your own hosting and maintenance.

Troubleshooting Common Installation Issues

  • Dependency Errors — If Composer fails due to missing packages, re‑run the composer install command or update composer itself.
  • Memory Limit Issues — Increase PHP’s memory_limit in php.ini to at least 2G for smoother installation.
  • Database Connection Failures — Double‑check your database host, username, and password settings.
  • Search Engine Errors — Ensure Elasticsearch is installed, running, and reachable before Magento setup begins.
  • Incorrect Permissions — Reset permissions and ownership for Magento files and directories if errors are reported during setup.

Conclusion

Installing Magento 2 in 2025 involves careful preparation of your server environment, understanding system requirements, and using Composer to carry out a reliable setup. This guide walked you through every essential step — from updating your server and installing prerequisites like PHP, database servers, and Elasticsearch to configuring Magento with correct permissions and post‑installation best practices. By following these steps and referring to community best practices, you can successfully deploy a robust Magento 2 store ready to support complex product catalogs and high traffic. Regular maintenance, monitoring logs, and keeping your Magento platform up to date will further enhance performance and stability.