On this page
- How large should the server be for Magento?
- How do you install PHP and the database?
- How do you install OpenSearch for the catalogue search?
- How do you download Magento with Composer?
- How do you run the Magento installer?
- How do you configure Nginx for Magento?
- What must you do before taking orders?
- How do you upgrade and troubleshoot Magento?
- Questions
How large should the server be for Magento?
Plan for 8 GB of RAM as a practical floor, because OpenSearch, PHP-FPM, the database and the cache all share the same machine. Compiling dependency injection code and deploying static content also spike memory for several minutes. A A4-8 fits a new store with a modest catalogue, while F4-16 or A8-16 give OpenSearch and PHP enough room for larger catalogues and traffic peaks.
This guide targets Ubuntu 24.04 (PHP 8.3) and Debian 13 (PHP 8.4), both inside the PHP range of current 2.4.8 and later releases. Debian 12 ships PHP 8.2, which current Magento no longer accepts, so use Debian 13 there. Always check the system requirements page for your exact Magento release before you install, since supported versions of PHP, OpenSearch and the database move with each patch line.
You also need Magento Marketplace access keys (a public and a private key from your Marketplace account) for the Composer repository, a domain such as shop.example.net, and a sudo user like deploy.
How do you install PHP and the database?
Install PHP-FPM with the extensions Magento checks for, then MariaDB.
sudo apt update
sudo apt install -y nginx php-fpm php-cli php-mysql php-bcmath php-curl php-gd php-intl php-mbstring php-soap php-xml php-zip php-opcache unzip git
php -v
sudo apt install -y mariadb-server
mariadb --versionMagento lists specific database versions per release (recent lines name MariaDB 11.4 and MySQL 8.4). If your distribution package is older than the version listed for your release, install it from the MariaDB foundation repository with its mariadb_repo_setup script and the --mariadb-server-version flag. Then create the store database:
sudo mariadb -e "CREATE DATABASE magento;"
sudo mariadb -e "CREATE USER 'magento'@'localhost' IDENTIFIED BY 'db-secret-here';"
sudo mariadb -e "GRANT ALL ON magento.* TO 'magento'@'localhost';"Raise PHP limits in both /etc/php/8.3/fpm/php.ini and /etc/php/8.3/cli/php.ini (use 8.4 on Debian 13): memory_limit = 2G, max_execution_time = 1800, realpath_cache_size = 10M and opcache.memory_consumption = 512.
How do you install OpenSearch for the catalogue search?
Magento requires a search engine, and OpenSearch from the project apt repository is the supported choice. Keep it bound to localhost so it is never exposed.
sudo apt install -y gnupg curl
curl -fsSL https://artifacts.opensearch.org/publickeys/opensearch-release.pgp | sudo gpg --dearmor -o /usr/share/keyrings/opensearch-release-keyring
echo "deb [signed-by=/usr/share/keyrings/opensearch-release-keyring] 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
apt policy opensearch
sudo OPENSEARCH_INITIAL_ADMIN_PASSWORD='Str0ng-Initial-Pass!' apt install -y opensearchInstall the 2.x minor version that your Magento release lists (pin it with opensearch=2.19.x when needed). Edit /etc/opensearch/opensearch.yml for a single private node:
network.host: 127.0.0.1
discovery.type: single-node
plugins.security.disabled: trueLimit the Java heap by creating /etc/opensearch/jvm.options.d/heap.options with -Xms1g and -Xmx1g on an 8 GB server (2g on 16 GB). Then start it and test:
sudo sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" | sudo tee /etc/sysctl.d/99-opensearch.conf
sudo systemctl enable --now opensearch
curl -s http://127.0.0.1:9200The JSON reply with a version number proves the node is up. Disabling the security plugin is acceptable only because the port is bound to 127.0.0.1.
How do you download Magento with Composer?
Install Composer, create the project from the Magento repository and give ownership to a dedicated user that PHP-FPM also runs as.
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer --version
sudo mkdir -p /var/www/magento
sudo chown deploy:www-data /var/www/magento
cd /var/www/magento
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .Composer asks for a username and password: paste the public key as the username and the private key as the password, and allow it to save them in auth.json. To pin a release, append it to the package name, for example magento/project-community-edition=2.4.8. More on Composer itself is in the Composer guide.
How do you run the Magento installer?
Run bin/magento setup:install once with the database, OpenSearch and admin details on the command line.
cd /var/www/magento
bin/magento setup:install --base-url=https://shop.example.net/ --db-host=localhost --db-name=magento --db-user=magento --db-password=db-secret-here --admin-firstname=Store --admin-lastname=Owner --admin-email=owner@example.net --admin-user=storeadmin --admin-password=Admin-pass-2026 --language=en_US --currency=USD --timezone=UTC --use-rewrites=1 --search-engine=opensearch --opensearch-host=127.0.0.1 --opensearch-port=9200At the end the installer prints the admin path, a random URL such as /admin_1x9k2q. Write it down; it is your back office address. Then set permissions so the web server group can write the generated folders:
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/magentoConfigure the PHP-FPM pool to run as deploy with group www-data (edit user and group in the pool file) so CLI and web requests create files with the same owner.
How do you configure Nginx for Magento?
Magento ships a complete Nginx configuration as nginx.conf.sample; include it from a small server block instead of writing your own.
upstream fastcgi_backend {
server unix:/run/php/php8.3-fpm.sock;
}
server {
listen 80;
listen [::]:80;
server_name shop.example.net;
set $MAGE_ROOT /var/www/magento;
include /var/www/magento/nginx.conf.sample;
}Save it as /etc/nginx/sites-available/magento, enable it, test with sudo nginx -t and reload. The sample serves from pub/, blocks access to internal folders and sets long cache lifetimes for static assets. Open the firewall with sudo ufw allow 'Nginx Full' and request a certificate following Certbot and Let's Encrypt; Certbot adds the TLS lines to the server block without touching the included file.
What must you do before taking orders?
Install cron, switch to production mode and add a cache backend. Magento depends on cron for indexing, emails and scheduled prices.
bin/magento cron:install
bin/magento deploy:mode:set production
bin/magento indexer:status
bin/magento cache:statusProduction mode compiles code and deploys static files, which takes a few minutes and a lot of memory. For sessions and page cache install a local key value store with sudo apt install valkey-server (or redis-server on Ubuntu 24.04) and point Magento at it with bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --session-save=redis --session-save-redis-host=127.0.0.1.
Order confirmations and the admin two factor setup email depend on outgoing mail. Send through an authenticated relay on port 587 as shown in SMTP relay for apps, and ask support by ticket before you count on port 25.
How do you upgrade and troubleshoot Magento?
Upgrade through Composer in maintenance mode, then rerun the setup commands.
bin/magento maintenance:enable
composer require-commerce magento/product-community-edition 2.4.8-p3 --no-update
composer update
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento maintenance:disableUse the patch number you actually target. When a page shows an error number, look it up under var/report/; general errors land in var/log/exception.log and var/log/system.log. A search page that returns nothing usually means OpenSearch is down or the index is stale: check systemctl status opensearch and run bin/magento indexer:reindex. If compilation is killed, the server ran out of RAM; add swap temporarily or move to a bigger plan as described in moving to a larger plan.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
| Plan | Fits because | Size | Monthly | Order from |
|---|---|---|---|---|
| A4-8 | a new store with a small catalogue | 4 vCPU, 8 GB RAM, 180 GB NVMe | $28.80/mo | $86.40 for 3 months |
| F4-16 | more RAM for OpenSearch and PHP workers | 4 vCPU, 16 GB RAM, 384 GB NVMe | $57.60/mo | $57.60 for 1 month |
| A8-16 | larger catalogues and busier sales | 8 vCPU, 16 GB RAM, 350 GB NVMe | $57.60/mo | $57.60 for 1 month |
Questions about Magento Open Source with OpenSearch
Can Magento run on 4 GB of RAM?
It can start, but OpenSearch, PHP and compilation compete for memory and builds often fail. 8 GB is the realistic starting point for a live store.
Do I have to use OpenSearch?
Current Magento releases require a supported search engine for the catalogue. OpenSearch is the documented option; check the requirements page of your release for supported versions.
Where do I find the admin URL again?
Run bin/magento info:adminuri in the Magento folder. It prints the back office path that the installer generated.
Why are CSS and images missing after install?
Static content has not been deployed or permissions block it. In production mode run bin/magento setup:static-content:deploy -f and recheck group write access on pub/static.
Can I get Marketplace keys without paying?
Yes. Access keys come with a free Marketplace account and are only used by Composer to download Magento Open Source and extensions.
How do I take the store offline for work?
Run bin/magento maintenance:enable. Add --ip=198.51.100.24 to keep your own address able to browse while customers see the maintenance page.
More in Websites, CMS and shops
- WordPress on Nginx, PHP-FPM, MariaDB
- Fix common WordPress errors
- Back up WordPress (3-2-1 rule)
- WordPress caching with Redis
- WooCommerce shop setup
- Ghost publishing platform
- Moodle learning platform
- phpBB forum
- Flarum forum
- Discourse community forum
- MediaWiki on Nginx and MariaDB
- PrestaShop store on Nginx
- OpenCart shop on Nginx
- Matomo web analytics
- Static site with Nginx and rsync
- Joomla on Nginx and PHP-FPM
- Drupal with Composer and Drush
- Vanilla Forums open source