How to Install Magento 2 (2026): Complete Setup Guide for Beginners

On This Page: [hide]

Magento is one of the most powerful ecommerce platforms available. But installing it? That’s where most people get stuck. Unlike simpler platforms, Magento needs specific server configurations, search engines, and careful setup. Skip a step, and you’ll spend hours troubleshooting.

This guide walks you through the entire Magento 2 installation process. You’ll learn what your server needs, how to install using Composer (the recommended method), and how to configure everything properly. Whether you’re setting up a development environment or a production store, these steps apply.

A quick note on versions: Magento Open Source 2.4.8 is the current release. Adobe rebranded Magento Commerce to Adobe Commerce, but the open-source version remains free. This guide covers both, though the installation process is nearly identical.


Last updated: February 2026. All requirements and commands verified against current documentation.


install magento image

Magento System Requirements

Magento is resource-hungry. It won’t run on cheap shared hosting. Before you start, confirm your server meets these requirements.

Operating System

Magento requires Linux x86-64. Ubuntu 22.04 or 24.04 LTS, RHEL, CentOS, and Debian all work. Windows and macOS aren’t supported for production. You can use macOS for local development, but don’t deploy on it.

Web Server

You need either Apache 2.4 or Nginx 1.18 (or later). Apache requires mod_rewrite enabled. Nginx is often preferred for performance, but both work fine. Choose based on your familiarity.

PHP Requirements

Magento 2.4.7 and 2.4.8 require PHP 8.1 or 8.2. Earlier versions won’t work. You’ll also need specific PHP extensions installed:

  • ext-bcmath
  • ext-ctype
  • ext-curl
  • ext-dom
  • ext-gd
  • ext-intl
  • ext-mbstring
  • ext-openssl
  • ext-pdo_mysql
  • ext-soap
  • ext-xsl
  • ext-zip
  • ext-sockets

PHP configuration matters too. Set memory_limit to at least 2GB. Increase max_execution_time to 18000 for installation. Enable OPcache (a PHP performance booster) for faster execution.

Database

Magento 2.4.7 and later require MySQL 8.0 or MariaDB 10.4 (or higher). Earlier MySQL versions won’t work. The database needs InnoDB storage engine support and proper UTF-8 encoding.

Search Engine (Required)

Here’s what trips up many people: Magento 2.4+ requires a search engine. MySQL no longer handles catalog searches. You must install either:

  • Elasticsearch 7.17 or 8.x
  • OpenSearch 1.2 or 2.x (a fork of Elasticsearch, fully compatible)

OpenSearch is recommended for new installations. It’s open-source and receives regular updates. We’ll cover its installation later.

Additional Requirements

  • Composer 2.2+ – PHP dependency manager (required for installation)
  • RAM – Minimum 2GB, 4GB recommended
  • Storage – At least 10GB SSD (NVMe preferred)
  • SSL Certificate – Required for HTTPS (self-signed won’t work)
  • TLS 1.2 – Required for PayPal and Magento repository access

Shared hosting won’t work for Magento. You need a VPS or dedicated server with full root access. Expect to spend at least $20-50/month for adequate resources. For high-traffic stores, dedicated servers or cloud hosting provide better scalability.

Pre-Installation: Server Preparation

Before installing Magento, your server needs proper configuration. These steps assume Ubuntu 22.04, but commands are similar for other distributions.

Step 1: Update Your System

Start with a fresh system update:

sudo apt update && sudo apt upgrade -y

Step 2: Install PHP and Required Extensions

Add the PHP repository and install PHP 8.2 with all required extensions:

sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php8.2 php8.2-fpm php8.2-mysql php8.2-xml php8.2-curl php8.2-gd php8.2-intl php8.2-mbstring php8.2-soap php8.2-xsl php8.2-zip php8.2-bcmath php8.2-sockets -y

Step 3: Configure PHP Settings

Edit your PHP configuration file:

sudo nano /etc/php/8.2/fpm/php.ini

Find and modify these values:

memory_limit = 2G
max_execution_time = 18000
zlib.output_compression = On

Restart PHP-FPM (PHP FastCGI Process Manager) to apply changes:

sudo systemctl restart php8.2-fpm

Step 4: Install MySQL 8.0

sudo apt install mysql-server -y
sudo mysql_secure_installation

Create a database and user for Magento:

sudo mysql -u root -p

CREATE DATABASE magento2;
CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON magento2.* TO 'magento_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 5: Install Nginx

sudo apt install nginx -y
sudo systemctl enable nginx

Step 6: Install Composer

Composer handles Magento’s dependencies. Install it globally:

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

Verify Composer 2.2+ is installed. Older versions cause dependency problems.

Step 7: Install OpenSearch

OpenSearch requires Java. Install OpenJDK first:

sudo apt install openjdk-11-jdk -y

Add the OpenSearch repository and install:

curl -o- https://artifacts.opensearch.org/publickeys/opensearch.pgp | sudo apt-key add -
echo "deb https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch-2.x.list
sudo apt update
sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=YourSecurePassword123! apt install opensearch -y

Configure OpenSearch by editing /etc/opensearch/opensearch.yml:

cluster.name: magento2
network.host: localhost
http.port: 9200
discovery.type: single-node
plugins.security.disabled: true

Start and enable the service:

sudo systemctl enable opensearch
sudo systemctl start opensearch

Verify it’s running:

curl -X GET "localhost:9200"

You should see a JSON response with cluster information.

Installing Magento via Composer

The Composer method is the only recommended installation approach. It handles dependencies properly and makes updates straightforward. Avoid archive downloads or Git clones for production sites.

Step 1: Get Magento Authentication Keys

You need authentication keys to download Magento. Create a free account at marketplace.magento.com, then:

  1. Go to My Profile > Access Keys
  2. Click “Create A New Access Key”
  3. Name it (e.g., “Server Installation”)
  4. Copy the Public Key (username) and Private Key (password)

Store these keys in Composer’s global auth file:

composer global config http-basic.repo.magento.com <public_key> <private_key>

Step 2: Create the Web Directory

Create and navigate to your web root:

sudo mkdir -p /var/www/magento2
cd /var/www/magento2

Step 3: Download Magento

Run the Composer create-project command. For Magento Open Source:

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

For Adobe Commerce (paid version):

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

This downloads 300MB+ of files. Be patient.

Step 4: Set File Permissions

Proper permissions prevent “Access Denied” errors and security issues:

sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod 644 {} \;
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod 755 {} \;
sudo chown -R www-data:www-data /var/www/magento2
sudo chmod u+x bin/magento

Step 5: Run the Installation Command

Now run the actual installation. Customize these parameters for your setup:

bin/magento setup:install \
  --base-url="https://yourdomain.com/" \
  --db-host="localhost" \
  --db-name="magento2" \
  --db-user="magento_user" \
  --db-password="your_strong_password" \
  --admin-firstname="Admin" \
  --admin-lastname="User" \
  --admin-email="[email protected]" \
  --admin-user="admin" \
  --admin-password="Admin123!" \
  --language="en_US" \
  --currency="USD" \
  --timezone="America/New_York" \
  --use-rewrites=1 \
  --search-engine="opensearch" \
  --opensearch-host="localhost" \
  --opensearch-port="9200"

The installation takes 5-15 minutes depending on server speed. Watch for any errors.

When complete, you’ll see a message with your admin URL. It’s randomized for security (e.g., /admin_abc123). Write this down.

Step 6: Run Post-Installation Commands

Complete the setup with these essential commands:

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

The static-content:deploy command generates CSS and JavaScript files. The -f flag forces deployment in developer mode.

Configuring Nginx for Magento

Magento needs specific Nginx configuration. Create a new server block:

sudo nano /etc/nginx/sites-available/magento2

Add this configuration (adjust domain and paths):

upstream fastcgi_backend {
    server unix:/var/run/php/php8.2-fpm.sock;
}

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;

    set $MAGE_ROOT /var/www/magento2;
    set $MAGE_MODE production;

    include /var/www/magento2/nginx.conf.sample;
}

Enable the site and test the configuration:

sudo ln -s /etc/nginx/sites-available/magento2 /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Magento provides a sample Nginx configuration at nginx.conf.sample. The include directive above uses it directly.

Setting Up Cron Jobs

Magento relies heavily on cron jobs (scheduled tasks) for indexing, emails, sitemaps, and more. Without cron, your store won’t function properly.

Run this command to generate the crontab entries:

bin/magento cron:install

This adds three cron jobs. Verify they exist:

crontab -l

You should see entries running every minute for Magento’s scheduled tasks.

Performance Optimization: Redis and Varnish

A production Magento store needs caching for acceptable performance. Redis handles sessions and backend cache. Varnish (an HTTP accelerator) handles full-page caching.

Installing Redis

sudo apt install redis-server -y
sudo systemctl enable redis-server

Verify Redis is working:

redis-cli ping

It should respond with “PONG”.

Configure Magento to use Redis for caching:

bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0
bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1
bin/magento setup:config:set --session-save=redis --session-save-redis-host=127.0.0.1 --session-save-redis-db=2

Using separate databases (0, 1, 2) keeps different cache types isolated.

Installing Varnish

Varnish sits in front of your web server and caches pages:

sudo apt install varnish -y

Magento generates the Varnish configuration file:

bin/magento varnish:vcl:generate --backend-host=localhost --backend-port=8080 --output-file=/etc/varnish/default.vcl

You’ll need to adjust Nginx to listen on port 8080 internally while Varnish handles port 80. This setup requires additional configuration beyond this guide’s scope, but the Magento documentation covers it thoroughly.

Security Configuration

Securing Magento requires multiple steps. Don’t skip these.

Admin Panel Security

Log into the Magento admin panel and navigate to Stores > Configuration > Advanced > Admin.

Under Security, configure these settings:

  • Admin Account Sharing: Set to “No” (prevents multiple people using one login)
  • Password Lifetime: Set to 90 days
  • Maximum Login Failures: Set to 5
  • Lockout Time: Set to 30 minutes

Two-Factor Authentication

Magento 2.4+ enables two-factor authentication (2FA) by default. This adds a second verification step beyond passwords. You can’t disable it, so configure it properly:

  1. Go to Stores > Configuration > Security > 2FA
  2. Enable Google Authenticator (or another supported provider)
  3. On first login, scan the QR code with your authenticator app

File Permissions

After installation, tighten permissions:

sudo find /var/www/magento2 -type d -exec chmod 755 {} \;
sudo find /var/www/magento2 -type f -exec chmod 644 {} \;
sudo chmod -R 770 /var/www/magento2/var
sudo chmod -R 770 /var/www/magento2/pub/static
sudo chmod -R 770 /var/www/magento2/pub/media
sudo chmod -R 770 /var/www/magento2/generated

Admin URL

Magento generates a random admin URL during installation. Keep it that way. Don’t change it to something predictable like /admin. If you need to find it later:

bin/magento info:adminuri

SSL/HTTPS Configuration

Always use HTTPS in production. After installing an SSL certificate (Let’s Encrypt is free), configure Magento:

bin/magento setup:store-config:set --base-url="https://yourdomain.com/"
bin/magento setup:store-config:set --base-url-secure="https://yourdomain.com/"
bin/magento setup:store-config:set --use-secure=1
bin/magento setup:store-config:set --use-secure-admin=1
bin/magento cache:flush

Troubleshooting Common Installation Issues

Even with careful setup, problems happen. Here are the most common issues and solutions.

Installation Stuck at 70%

This usually means PHP’s max_execution_time is too low. Edit php.ini and set it to 18000, then restart PHP-FPM. Alternatively, run the installation via command line instead of the web installer.

“Class Does Not Exist” Errors

These ReflectionException errors indicate corrupted generated files. Clear them:

rm -rf var/cache var/page_cache var/generation generated/code
bin/magento setup:di:compile
bin/magento cache:flush

Permission Denied Errors

File permissions cause about 38% of installation failures. Ensure the web server user (www-data on Ubuntu) owns all files:

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

Missing PHP Extension

Error messages like “The requested PHP extension ext-mbstring is missing” mean you need to install that extension:

sudo apt install php8.2-mbstring -y
sudo systemctl restart php8.2-fpm

Elasticsearch/OpenSearch Connection Failed

If Magento can’t connect to your search engine:

  1. Check if the service is running: sudo systemctl status opensearch
  2. Test connectivity: curl localhost:9200
  3. Check firewall rules aren’t blocking port 9200
  4. Verify the hostname and port in your installation command match your configuration

Memory Exhausted

PHP memory errors during compilation mean you need more RAM or swap space:

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

Blank Pages or 500 Errors

Enable developer mode to see actual errors:

bin/magento deploy:mode:set developer

Check the log files at var/log/exception.log and var/log/system.log for details.

Post-Installation Checklist

After successful installation, complete these steps:

  • Log into admin panel and configure store settings (name, timezone, currency)
  • Set up shipping methods
  • Configure payment gateways
  • Create customer groups and tax rules
  • Set up email templates and SMTP
  • Configure robots.txt and sitemaps
  • Install essential extensions via Composer
  • Set up automated backups
  • Switch to production mode: bin/magento deploy:mode:set production

Frequently Asked Questions

Can I install Magento on shared hosting?

Technically yes, but it’s not recommended. Magento requires specific PHP configurations, SSH access, and Composer. Most shared hosts don’t provide these. You’ll also hit memory limits quickly. VPS hosting is the minimum practical option.

How long does Magento installation take?

Server preparation takes 30-60 minutes if you’re familiar with Linux. The actual Magento installation takes 10-20 minutes. First-time users should budget 2-4 hours for the complete process including troubleshooting.

Do I need Elasticsearch or OpenSearch?

Yes, one of them is mandatory for Magento 2.4+. MySQL no longer handles catalog searches. OpenSearch is the recommended choice for new installations since it’s fully open-source and actively maintained.

What’s the difference between Magento Open Source and Adobe Commerce?

Magento Open Source is free and community-supported. Adobe Commerce (formerly Magento Commerce) is the paid version with additional features like B2B functionality, advanced marketing tools, and cloud hosting options. Adobe Commerce starts at $22,000/year. Both share the same installation process.

Can I migrate from WooCommerce to Magento?

Yes, but it requires careful planning. You’ll need to export products, customers, and orders from WooCommerce and import them into Magento. Several migration extensions exist, though complex stores may need custom development. Consider hiring a Magento specialist for large catalogs.

How do I update Magento after installation?

Use Composer to update: composer update magento/product-community-edition --with-all-dependencies. Always back up your database and files first. Test updates on a staging environment before production. Run bin/magento setup:upgrade after updating.

Why is my Magento store slow?

Uncached Magento is slow by design. It generates pages dynamically. Enable Redis for backend caching and Varnish for full-page caching. Enable production mode, which pre-compiles code. Use a CDN for static assets. Consider upgrading your server resources if traffic is high.

Researched and written by:
HowToHosting Editors
HowToHosting.guide provides expertise and insight into the process of creating blogs and websites, finding the right hosting provider, and everything that comes in-between. Read more...

Leave a Comment

Your email address will not be published. Required fields are marked *

This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.
I Agree
At HowToHosting.Guide, we offer transparent web hosting reviews, ensuring independence from external influences. Our evaluations are unbiased as we apply strict and consistent standards to all reviews.
While we may earn affiliate commissions from some of the companies featured, these commissions do not compromise the integrity of our reviews or influence our rankings.
The affiliate earnings contribute to covering account acquisition, testing expenses, maintenance, and development of our website and internal systems.
Trust howtohosting.guide for reliable hosting insights and sincerity.