Magento Open Source (the free edition of Adobe Commerce) is the most capable open-source e-commerce platform: multi-store, complex catalogs, layered navigation, B2B-friendly features and a huge extension ecosystem. It’s also demanding, with more moving parts than WordPress or PrestaShop. This guide installs Magento 2.4 on Ubuntu 24.04 with Nginx, PHP-FPM, MySQL, OpenSearch and Redis.
Requirements
| Component | Version (Magento 2.4.8) |
|---|---|
| PHP | 8.3 or 8.4, with FPM |
| Database | MySQL 8.4 or MariaDB 11.4 |
| Search | OpenSearch 2.x (required; Elasticsearch is deprecated) |
| Cache / sessions | Redis or Valkey |
| Composer | 2.x |
| Web server | Nginx (or Apache) |
Check Adobe’s system requirements page for the exact versions supported by the release you install. Plan at least 4 GB RAM (OpenSearch alone wants 1–2 GB), 8 GB for a comfortable production store, plus swap. See how much RAM a VPS needs and swap file vs partition.
1. Install the stack
sudo apt update
sudo apt install -y nginx mysql-server unzip git curl \
php8.3-fpm php8.3-cli php8.3-mysql php8.3-xml php8.3-curl php8.3-gd php8.3-intl \
php8.3-mbstring php8.3-zip php8.3-bcmath php8.3-soap php8.3-opcache php8.3-redis
sudo apt install -y redis-server
Ubuntu 24.04 ships PHP 8.3. Raise the PHP limits Magento expects, in /etc/php/8.3/fpm/php.ini and /etc/php/8.3/cli/php.ini:
memory_limit = 2G
max_execution_time = 1800
realpath_cache_size = 10M
opcache.memory_consumption = 512
opcache.max_accelerated_files = 60000
See PHP OPcache and PHP-FPM tuning.
2. Database
sudo mysql <<'SQL'
CREATE DATABASE magento CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'magento'@'localhost' IDENTIFIED BY 'StrongPassword!';
GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'localhost';
SQL
See installing MySQL on Ubuntu.
3. OpenSearch
The simplest route on a single server is Docker:
docker run -d --name opensearch --restart unless-stopped -p 127.0.0.1:9200:9200 \
-e "discovery.type=single-node" -e "DISABLE_SECURITY_PLUGIN=true" \
-e "OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g" \
-v opensearch-data:/usr/share/opensearch/data opensearchproject/opensearch:2
curl http://127.0.0.1:9200
Bound to localhost only, with the security plugin disabled, so it must never be exposed publicly. See installing Docker on Ubuntu.
4. Get Magento with Composer
Create access keys in your Adobe Commerce Marketplace account (My Profile → Access Keys). The public key is the username and the private key is the password for repo.magento.com.
sudo mkdir -p /var/www/magento && sudo chown $USER:www-data /var/www/magento
cd /var/www/magento
composer create-project --repository-url=https://repo.magento.com/ \
magento/project-community-edition .
(Mage-OS is a community distribution of Magento Open Source that installs without Adobe keys.)
5. Run the installer
bin/magento setup:install \
--base-url=https://shop.example.com/ \
--db-host=localhost --db-name=magento --db-user=magento --db-password='StrongPassword!' \
--admin-firstname=Admin --admin-lastname=User [email protected] \
--admin-user=admin --admin-password='AnotherStrongPass1!' \
--language=en_US --currency=USD --timezone=UTC --use-rewrites=1 \
--search-engine=opensearch --opensearch-host=127.0.0.1 --opensearch-port=9200 \
--session-save=redis --session-save-redis-host=127.0.0.1 \
--cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=1
It prints the admin URL (/admin_xxxxxx). Note it down. Set permissions:
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 {} +
sudo chown -R $USER:www-data .
6. Nginx
Magento ships a tested Nginx config (nginx.conf.sample). Include it:
upstream fastcgi_backend {
server unix:/run/php/php8.3-fpm.sock;
}
server {
listen 80;
server_name shop.example.com;
set $MAGE_ROOT /var/www/magento;
include /var/www/magento/nginx.conf.sample;
}
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d shop.example.com
The document root is pub/, which the sample config handles. See Let’s Encrypt with Certbot on Nginx.
7. Cron (required)
Indexers, emails, sitemaps and many other features depend on cron:
bin/magento cron:install
crontab -l
8. Production mode
bin/magento deploy:mode:set production
bin/magento indexer:set-mode schedule
bin/magento cache:status
Production mode compiles code and deploys static files. After updates or new extensions, run setup:upgrade, setup:di:compile and setup:static-content:deploy.
The admin uses two-factor authentication by default. Configure it at first login (Google Authenticator works well); it needs working outbound email for setup links.
Performance
- Full-page cache: Varnish is recommended for production (
bin/magento config:set system/full_page_cache/caching_application 2). Redis or the built-in cache work for small stores. - Redis for cache and sessions (configured above).
- A CDN for static and media files. See CDN for websites.
- MySQL tuning (InnoDB buffer pool). See MySQL InnoDB buffer pool.
Security and maintenance
- Apply Adobe’s security patches promptly. Magento stores are frequent attack targets.
- Use a non-default admin path, 2FA, and IP restrictions for the admin where practical.
- Daily database and
pub/mediabackups. See database backup automation. - Keep OpenSearch and Redis bound to localhost, and the firewall closed to everything but 80/443/SSH. See UFW firewall.
Quick reference
| Task | Command |
|---|---|
| Clear cache | bin/magento cache:flush |
| Reindex | bin/magento indexer:reindex |
| Upgrade | composer update && bin/magento setup:upgrade |
| Compile | bin/magento setup:di:compile |
| Static files | bin/magento setup:static-content:deploy -f |
| Mode | bin/magento deploy:mode:show |
Related: e-commerce platforms compared and VPS for e-commerce.