Websites & apps

Install Magento 2 (Adobe Commerce Open Source) on a VPS

Prepare a VPS for Magento 2: PHP, MySQL, OpenSearch and Composer requirements, install with bin/magento, set production mode, cron, caching and file permissions.

AdvancedLinux VPS3 min read

Magento 2 (now Magento Open Source / Adobe Commerce) is a powerful e-commerce platform with demanding requirements: a search engine service, many PHP extensions and plenty of RAM. This guide covers how to install Magento 2 on a VPS and the settings that keep it fast.

Before you start

  • A VPS with at least 4 GB RAM (8 GB recommended once OpenSearch, MySQL and PHP run together), NVMe storage and root access.
  • Check the official system requirements for your Magento version: supported PHP, MySQL/MariaDB, OpenSearch and Composer versions change between releases.
  • An Adobe Commerce Marketplace account to get Composer access keys (public and private key).
  • A domain pointing to the VPS.

Install the server stack

  • Web server: Nginx (Magento ships a sample nginx.conf.sample) with PHP-FPM, or Apache.
  • PHP extensions: bcmath, ctype, curl, dom, gd, intl, mbstring, mysql, soap, xsl, zip, sockets, sodium, plus opcache.
  • Database: MySQL 8 or a supported MariaDB, with a dedicated database and user.
  • Search: OpenSearch (required; Magento no longer works without a search engine). Give it its own memory budget, e.g. 1 GB heap.
  • Cache: Redis for cache and sessions; optionally Varnish for full-page cache.

Recommended PHP settings:

memory_limit = 2G
max_execution_time = 1800
realpath_cache_size = 10M
opcache.memory_consumption = 512
opcache.max_accelerated_files = 60000

Download Magento with Composer

As the file-system owner user (not root):

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

Enter your Marketplace public key as username and private key as password when prompted.

Set file permissions

cd /var/www/magento && 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 {} + && chmod u+x bin/magento

The owner user and the web server group (www-data) should share group ownership of the install.

Run the installer

bin/magento setup:install \
  --base-url=https://example.com/ \
  --db-host=localhost --db-name=magento --db-user=magento --db-password=strong-password \
  --admin-firstname=Admin --admin-lastname=User --admin-email=admin@example.com \
  --admin-user=storeadmin --admin-password='Strong-Admin-Pass1' \
  --language=en_US --currency=USD --timezone=Europe/Berlin --use-rewrites=1 \
  --search-engine=opensearch --opensearch-host=localhost --opensearch-port=9200

At the end it prints the admin URL (a random path such as /admin_x1y2z3). Keep it private.

Configure Nginx

Include Magento's sample config in your server block and point the root at the install:

upstream fastcgi_backend { server unix:/run/php/php8.3-fpm.sock; }
server {
    server_name example.com;
    set $MAGE_ROOT /var/www/magento;
    include /var/www/magento/nginx.conf.sample;
}

The sample serves from pub/ and protects sensitive folders. Add SSL with Certbot.

Production mode, cron and caching

  1. Install Magento's cron jobs for the owner user:
    bin/magento cron:install
  2. Use Redis for cache and sessions:
    bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0 --session-save=redis --session-save-redis-host=127.0.0.1 --session-save-redis-db=2
  3. Switch to production mode (compiles code and deploys static content):
    bin/magento deploy:mode:set production
  4. Enable two-factor authentication for admins (enabled by default) and configure email for it.

Troubleshooting

  • Could not validate a connection to OpenSearch: the service is not running or listens elsewhere; check curl localhost:9200.
  • Blank pages or missing CSS: static content not deployed or wrong permissions. Run setup:static-content:deploy and fix permissions.
  • One or more indexers are invalid: cron is not running. Check crontab -l for the owner user and run bin/magento indexer:reindex.
  • Out of memory during compile: raise PHP CLI memory or temporarily add swap.

Magento FAQ

Can Magento run on shared cPanel hosting?

Small stores sometimes do, but OpenSearch, cron and memory needs make a VPS or dedicated server the realistic choice.

Is Magento Open Source free?

Yes, the open-source edition is free; Adobe Commerce is the paid edition with extra features and support.

Do I need Varnish?

Not to start; Redis plus Magento's built-in full-page cache is fine. Varnish helps busy stores.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.