Installation and Configuration of Magento 2 / Adobe Commerce
Correct initial installation of Magento 2 determines the stability of all subsequent work. There is no room for compromise on the stack: incorrect PHP version, missing Elasticsearch or Redis for sessions — these are problems that will surface on production at the worst moment.
Server Preparation
Minimum requirements for dev/staging:
- 4 vCPU, 8 GB RAM, 50 GB SSD
- Ubuntu 22.04 LTS or RHEL 9
Recommended for prod (up to 50k SKU, average load):
- 8 vCPU, 16 GB RAM, 100 GB SSD
- Separate server for MySQL, separate for Elasticsearch
Stack installation on Ubuntu 22.04:
# Nginx
apt install nginx -y
systemctl enable nginx
# PHP 8.2 + extensions
add-apt-repository ppa:ondrej/php -y && apt update
apt install php8.2-fpm php8.2-bcmath php8.2-ctype php8.2-curl \
php8.2-dom php8.2-fileinfo php8.2-gd php8.2-intl php8.2-mbstring \
php8.2-mysqlnd php8.2-opcache php8.2-pdo php8.2-simplexml \
php8.2-soap php8.2-xsl php8.2-zip php8.2-sockets -y
# MySQL 8.0
apt install mysql-server -y
mysql_secure_installation
# Redis
apt install redis-server -y
# Composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
PHP-FPM configuration (/etc/php/8.2/fpm/pool.d/magento.conf):
[magento]
user = www-data
group = www-data
listen = /run/php/php8.2-fpm-magento.sock
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 500
php.ini settings:
memory_limit = 2G
max_execution_time = 1800
zlib.output_compression = On
opcache.enable = 1
opcache.memory_consumption = 512
opcache.max_accelerated_files = 60000
opcache.consistency_checks = 0
opcache.validate_timestamps = 0 ; only in prod (= 1 in dev)
OpenSearch / Elasticsearch
Magento 2.4 requires Elasticsearch or OpenSearch — standard MySQL search is removed:
# OpenSearch 2.x
wget https://artifacts.opensearch.org/releases/bundle/opensearch/2.11.0/opensearch-2.11.0-linux-x64.tar.gz
tar -xzf opensearch-2.11.0-linux-x64.tar.gz
# Configuration /etc/opensearch/opensearch.yml
cluster.name: magento
node.name: node-1
network.host: 127.0.0.1
http.port: 9200
discovery.type: single-node
plugins.security.disabled: true # only for localhost dev
Magento Installation via Composer
# Create project (requires keys from account.magento.com)
composer create-project \
--repository-url=https://repo.magento.com/ \
magento/project-community-edition=2.4.7-p3 \
/var/www/magento
cd /var/www/magento
chown -R www-data:www-data .
chmod -R 775 var generated pub/static pub/media
# Create database
mysql -u root -e "
CREATE DATABASE magento CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'magento'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL ON magento.* TO 'magento'@'localhost';
FLUSH PRIVILEGES;
"
# Installation
bin/magento setup:install \
--base-url="https://myshop.example.com/" \
--db-host="localhost" \
--db-name="magento" \
--db-user="magento" \
--db-password="StrongPassword123!" \
--admin-firstname="Admin" \
--admin-lastname="User" \
--admin-email="[email protected]" \
--admin-user="admin_secure_name" \
--admin-password="Admin@Secure123!" \
--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" \
--session-save-redis-db=1 \
--cache-backend="redis" \
--cache-backend-redis-server="127.0.0.1" \
--cache-backend-redis-db=2 \
--page-cache="redis" \
--page-cache-redis-server="127.0.0.1" \
--page-cache-redis-db=3 \
--backend-frontname="admin_$(openssl rand -hex 4)"
Nginx Configuration
upstream fastcgi_backend {
server unix:/run/php/php8.2-fpm-magento.sock;
}
server {
listen 443 ssl http2;
server_name myshop.example.com;
root /var/www/magento/pub;
ssl_certificate /etc/letsencrypt/live/myshop.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myshop.example.com/privkey.pem;
index index.php;
autoindex off;
charset UTF-8;
location /setup {
root /var/www/magento;
location ~ ^/setup/index.php {
fastcgi_pass fastcgi_backend;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ ^/index\.php {
fastcgi_pass fastcgi_backend;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_TYPE store;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
expires max;
log_not_found off;
add_header Cache-Control "public";
}
location ~ /\. { deny all; }
location ~ /app/ { deny all; }
location ~ /lib/ { deny all; }
location ~ /var/ { deny all; }
location ~ /setup/ { deny all; }
}
Basic Configuration After Installation
Operation mode (prod vs developer):
# Production mode — compiled DI, minified JS/CSS
bin/magento deploy:mode:set production
# Developer mode — for development (no cache, recompiles on the fly)
bin/magento deploy:mode:set developer
Indexers — should be in Update on Schedule mode for prod:
bin/magento indexer:set-mode schedule
bin/magento indexer:reindex # initial indexing
Cron — required for Magento operation:
bin/magento cron:install
# Adds to www-data crontab:
# * * * * * /usr/bin/php /var/www/magento/bin/magento cron:run
Two-Factor Authentication for Admin (mandatory in 2.4+):
# Configuration through Google Authenticator on first login
# Or disable on dev environment:
bin/magento module:disable Magento_TwoFactorAuth
bin/magento cache:flush
Localization Configuration
Admin > Stores > Configuration > General > General > Locale Options
Locale: English (United States)
Timezone: UTC
Default Currency: US Dollar
Admin > Stores > Configuration > General > Currency Setup
Base Currency: US Dollar
Default Display Currency: US Dollar
Language pack installation:
composer require magento/language-en_us
bin/magento setup:upgrade
bin/magento setup:static-content:deploy en_US
Performance Monitoring
Diagnostic tools:
# Indexer status
bin/magento indexer:status
# Redis cache check
redis-cli -n 2 INFO keyspace
# Table sizes — when performance issues occur
mysql -u magento -p magento -e "
SELECT table_name, ROUND(data_length/1024/1024, 2) AS 'MB'
FROM information_schema.tables
WHERE table_schema = 'magento'
ORDER BY data_length DESC LIMIT 20;
"
# Message queue
bin/magento queue:consumers:list
bin/magento queue:consumers:start async.operations.all
Timeline
Installation on a prepared server with basic configuration and translation: 1–2 days. If includes server setup from scratch, SSL, Nginx, Redis, OpenSearch, monitoring and backups: 3–5 days. Migration from Magento 1 or another platform: separate project, 2–8 weeks.







