How to Install Magento 2 With Composer

How to Install Magento 2 With Composer

[Updated: March 11, 2026]

One wrong PHP version or database mismatch turns a 30-minute Magento install into hours of debugging. Most guides skip the details that prevent these failures.

This guide covers the complete Magento 2.4.8 installation via Composer with verified 2026 system requirements, step-by-step commands, and fixes for the errors you will encounter.

Key Takeaways

  • To install Magento 2.4.8, your server needs PHP 8.3 or 8.4, MySQL 8.4, and OpenSearch 2.19
  • Composer is the official installation method recommended by Adobe
  • Elasticsearch is removed in 2.4.8 and replaced by OpenSearch
  • You need Adobe Marketplace authentication keys before installation
  • Production stores require Redis (or Valkey 8.x) for caching and Varnish for full-page cache
  • Always install the latest patch version (2.4.8-p4 as of March 2026) for security fixes

TL;DR

Installing Magento 2 with Composer = Run composer create-project on a server that meets the 2.4.8 stack requirements. The process takes about 30 minutes on a prepared server.

Stack (2.4.8): PHP 8.3/8.4, MySQL 8.4 or MariaDB 11.4, OpenSearch 2.19, Composer 2.2+, NGINX 1.22+

Perfect for: Developers building staging or production environments, agencies deploying client stores, DevOps teams scripting infrastructure.

Why Use Composer to Install Magento 2?

Composer is a PHP dependency manager and the official method Adobe recommends for installing Magento 2. It handles all package downloads, version conflicts, and dependency trees in a single command.

Three reasons Composer beats other installation methods:

1. Automatic Dependency Resolution

Magento 2 pulls in hundreds of third-party packages. Composer maps every dependency, downloads the correct versions, and prevents conflicts. Manual downloads cannot match this precision.

2. Clean Version Management

Upgrading from 2.4.7 to 2.4.8? Composer handles the entire transition. It compares your current packages against the new release, updates what changed, and preserves your customizations. No manual file replacements.

3. Reproducible Builds

The composer.lock file pins every package to an exact version. Your staging server runs the same code as production. No "works on my machine" surprises.

Want to skip the installation process? Managed Magento hosting handles server setup, Magento installation, and ongoing updates for you.

Magento 2.4.8 System Requirements (2026)

Running the wrong stack version is the number one installation failure. These are the verified requirements for Magento 2.4.8, released April 8, 2025 (latest security patch: 2.4.8-p4, March 10, 2026).

Always install the latest patch version to get all security and compatibility fixes.

Component Required Version Notes
PHP 8.3 or 8.4 8.4 recommended for best performance. PHP 8.2 allowed only during upgrades. PHP 8.1 removed.
MySQL 8.4 LTS Supported until 2032. MySQL 8.0 reaches EOL in 2026. Default collation: utf8mb4.
MariaDB 11.4 LTS Supported until 2029. Adobe recommends upgrading from 10.6 (EOL 2026).
OpenSearch 2.19 Elasticsearch is removed in 2.4.8. Migration to OpenSearch required.
Composer 2.2+ (LTS) Compatible up to 2.9.x since 2.4.8 patches. Composer 1.x not supported.
NGINX 1.22 to 1.28 Or Apache 2.4
Redis 6.2 to 7.2 Required for caching in production. Valkey 8.x supported as alternative.
Varnish 7.0 to 7.7 Full-page cache for production
RabbitMQ 3.9 to 4.1 Message queue (optional)

Source: Adobe Experience League — System Requirements

For a complete breakdown of hardware sizing and performance tuning, see our Magento system requirements guide.

Required PHP Extensions

Magento 2.4.8 needs these PHP extensions enabled:

bcmath, ctype, curl, dom, gd, hash, iconv, intl, mbstring, openssl, pdo_mysql, simplexml, soap, spl, xsl, zip, sodium

PHP Configuration

Set these values in your php.ini:

memory_limit = 1G
realpath_cache_size = 10M
realpath_cache_ttl = 7200
opcache.save_comments = 1

Use memory_limit = 2G for debugging and code compilation on development servers.

Prerequisites Before Installation

1. Adobe Marketplace Authentication Keys

You need a public and private key pair from the Adobe Marketplace to access the Composer repository.

  1. Create an account at marketplace.magento.com
  2. Navigate to My Profile > Access Keys
  3. Generate a new key pair
  4. Save both keys. The public key is your Composer username, the private key is your password

2. File System Owner

Create a dedicated user for Magento file ownership:

# Create magento user and add to web server group
sudo useradd -m -g www-data magento
# Or for NGINX:
sudo useradd -m -g nginx magento

The web server and the Magento file system owner must share a group. This prevents permission errors during installation and runtime.

3. Database Setup

Create an empty database before running the installer:

mysql -u root -p
CREATE DATABASE magento2;
CREATE USER 'magento'@'localhost' IDENTIFIED BY 'YOUR_SECURE_PASSWORD';
GRANT ALL ON magento2.* TO 'magento'@'localhost';
FLUSH PRIVILEGES;
EXIT;

If upgrading from MySQL 8.0 to 8.4, set restrict_fk_on_non_standard_key=OFF temporarily during migration to avoid foreign key errors.

If you prefer to install Magento without Composer, follow our manual installation on a VPS guide instead.

How to Install Magento 2 With Composer (Step-by-Step)

Step 1: Install Composer

Download and install Composer 2.x:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer --version

Verify the version is 2.2 or higher. Magento 2.4.8 patches support up to Composer 2.9.x.

Step 2: Create the Magento Project

Run the Composer create-project command:

composer create-project \
  --repository-url=https://repo.magento.com/ \
  magento/project-community-edition=2.4.8 \
  /var/www/magento2

Composer prompts for your Adobe Marketplace credentials. Enter the public key as username and private key as password.

For Adobe Commerce (paid edition), replace project-community-edition with project-enterprise-edition.

Step 3: Set File Permissions

cd /var/www/magento2
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:www-data .
chmod u+x bin/magento

Step 4: Run the Installation Command

bin/magento setup:install \
  --base-url="https://your-domain.com/" \
  --db-host="localhost" \
  --db-name="magento2" \
  --db-user="magento" \
  --db-password="YOUR_DB_PASSWORD" \
  --admin-firstname="Admin" \
  --admin-lastname="User" \
  --admin-email="admin@your-domain.com" \
  --admin-user="admin" \
  --admin-password="YOUR_ADMIN_PASSWORD" \
  --language="en_US" \
  --currency="USD" \
  --timezone="America/New_York" \
  --search-engine="opensearch" \
  --opensearch-host="localhost" \
  --opensearch-port="9200" \
  --use-rewrites=1

Note the --search-engine="opensearch" flag. Previous versions used elasticsearch7 here. Magento 2.4.8 defaults to OpenSearch.

Step 5: Verify the Installation

bin/magento info:adminuri

This outputs your admin panel URL. Open it in a browser to confirm the installation succeeded.

Run the post-installation checks:

bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:flush

Step 6: Switch to Production Mode

bin/magento deploy:mode:set production

Production mode disables error reporting, enables full-page cache, and serves pre-compiled static files. Never run a live store in developer mode.

Magento Open Source vs Adobe Commerce

Both editions install through Composer. The difference is the package name and licensing.

Feature Magento Open Source Adobe Commerce
Cost Free License fee (contact Adobe)
Composer Package project-community-edition project-enterprise-edition
B2B Features Not included Built-in
Page Builder Basic Advanced
Customer Segmentation Not included Built-in
Cloud Hosting Self-managed Available via Adobe Commerce Cloud

Magento Open Source works for most small to mid-sized stores. Choose Adobe Commerce Cloud when you need B2B features, advanced marketing tools, or managed cloud infrastructure from Adobe.

Post-Installation Configuration

Enable Redis for Caching

bin/magento setup:config:set \
  --cache-backend=redis \
  --cache-backend-redis-server=127.0.0.1 \
  --cache-backend-redis-port=6379 \
  --cache-backend-redis-db=0

Redis replaces the default file-based cache. It reduces page generation time and handles concurrent traffic better than filesystem caching. Valkey 8.x works as a drop-in replacement for Redis if your infrastructure supports it.

Install Sample Data (Optional)

bin/magento sampledata:deploy
bin/magento setup:upgrade
bin/magento cache:flush

Switch to developer mode before deploying sample data. Run setup:upgrade after deployment to apply the database changes.

Configure SSL

Every production Magento store needs HTTPS. Update the base URLs:

bin/magento setup:store-config:set \
  --base-url="https://your-domain.com/"
bin/magento setup:store-config:set \
  --base-url-secure="https://your-domain.com/"
bin/magento setup:store-config:set --use-secure=1
bin/magento setup:store-config:set --use-secure-admin=1

Troubleshooting Common Installation Errors

"Killed" or Out of Memory

The most common Composer error during Magento installation:

The following exception is caused by a lack of memory...
mmap() failed: [12] Cannot allocate memory

Fix: Increase PHP memory limit to 2G or add swap space:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Quick workaround for Composer memory issues: run COMPOSER_MEMORY_LIMIT=-1 composer create-project ... to remove the memory cap for Composer itself.

OpenSearch Connection Failed

Could not validate a connection to OpenSearch

Fix: Verify OpenSearch is running and accessible:

curl -X GET "localhost:9200"
systemctl status opensearch

Check that the --opensearch-host and --opensearch-port values match your OpenSearch configuration.

Permission Denied Errors

The directory "/var/www/magento2/var" is not writable

Fix: Reset ownership and permissions:

sudo chown -R magento:www-data /var/www/magento2
find /var/www/magento2 -type d -exec chmod 775 {} +
find /var/www/magento2 -type f -exec chmod 664 {} +
chmod u+x bin/magento

Composer Dependency Conflicts

Your requirements could not be resolved to an installable set of packages

Fix: Clear the Composer cache and retry:

composer clear-cache
composer update --with-all-dependencies

If the conflict persists, check that all PHP extensions required by Magento 2.4.8 are installed and enabled.

FAQ

What is the fastest way to install Magento 2?

The fastest method is composer create-project on a server with all prerequisites installed. The download and installation take about 10 to 15 minutes. Managed hosting providers offer pre-installed Magento environments that eliminate setup time.

Can I install Magento 2 without Composer?

Yes. You can download the archive from the Adobe Marketplace and extract it to your server. This method lacks dependency management and makes updates harder. Adobe recommends Composer for all production installations.

What PHP version does Magento 2.4.8 need?

Magento 2.4.8 requires PHP 8.3 or 8.4 (recommended for best performance). PHP 8.2 is allowed only during the upgrade process. PHP 8.1 and earlier are not compatible. Check your version with php -v before starting the installation.

Does Magento 2 still use Elasticsearch?

Elasticsearch is removed in Magento 2.4.8. The admin panel shows a deprecation warning if Elasticsearch is still selected. Adobe requires OpenSearch 2.19 for both on-premises and cloud deployments. Existing Elasticsearch installations must migrate before upgrading.

How much server RAM does Magento 2 need?

Development environments need 4 GB RAM minimum. Production stores with moderate traffic require 8 to 16 GB (Adobe recommends at least 8 GB). High-traffic stores with multiple concurrent users need 32 GB or more. PHP memory_limit should be set to at least 1 GB.

Can I install Magento 2 on shared hosting?

Magento 2 requires command-line access, Composer, and specific PHP extensions that most shared hosts do not provide. Use a VPS, dedicated server, or managed Magento hosting for reliable performance.

How do I install Magento 2 on localhost for development?

Set up a local stack with PHP 8.3+, MySQL 8.4, OpenSearch 2.19, and Composer. Tools like DDEV or Warden automate this setup with Docker containers. Run the same composer create-project command pointing to localhost as the base URL.

What is the difference between Magento Open Source and Adobe Commerce installation?

The Composer command uses project-community-edition for Open Source and project-enterprise-edition for Adobe Commerce. The installation process is identical. Adobe Commerce requires a valid license key in addition to the Marketplace authentication keys.

How do I update Magento 2 after installation?

Run composer require magento/product-community-edition=2.4.8-p4 --no-update followed by composer update and bin/magento setup:upgrade. Back up your database and files before every update.

How long does a Magento 2 installation take?

On a prepared server with all prerequisites, the Composer download takes 5 to 10 minutes and the setup command takes another 5 minutes. First-time server preparation (installing PHP, MySQL, OpenSearch, NGINX) adds 1 to 2 hours.

Summary

Installing Magento 2.4.8 with Composer is straightforward when your server meets the current requirements. The critical stack for 2026: PHP 8.3 or 8.4, MySQL 8.4, OpenSearch 2.19, and Composer 2.2+.

Follow the six steps in this guide. Verify each prerequisite before running the installer. Use OpenSearch instead of the removed Elasticsearch. Configure Redis and Varnish for production performance.

Need a Magento store without the server setup? Explore managed Magento hosting to get a production-ready environment with automated updates and 24/7 infrastructure support.

Magento Hosting Free Demo on AWS

CEO & Co-Founder

Raphael Thiel co-founded MGT-Commerce in 2011 together with Stefan Wieczorek and has built it into a leading Magento hosting provider serving 5,000+ customers on AWS. With 25+ years in e-commerce and cloud infrastructure, he oversees hosting architecture for enterprise clients. He also co-founded CloudPanel, an open-source server management platform.


Get the fastest Magento Hosting! Get Started