Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install Magento on Ubuntu

Set up Apache, MySQL and PHP, download Magento 2 and finish the web installer.

Online Stores3 min read4 steps15 screenshots

What you need

  1. Ubuntu. An LTS release (20.04, 22.04 or newer).
  2. A server with at least 2 GB of RAM (4 GB or more is better for Magento).
  3. A LAMP stack. Linux, Apache, MySQL and PHP.
  4. A domain name or a subdomain to open the store.
Note: Magento 2 also needs Elasticsearch or OpenSearch (version 2.4 and newer), and Composer for the usual install. The steps below follow the archive method and show the main parts. Check the Adobe Commerce system requirements for your version.

Step 1: Install Apache

sudo apt update && sudo apt install apache2 -y
Installing Apache
sudo systemctl start apache2
sudo systemctl enable apache2
Starting Apache

Step 2: Install MySQL

sudo apt install mysql-server
Installing MySQL
sudo systemctl start mysql && sudo systemctl enable mysql

Step 3: Install PHP

sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-dom php-xml
Installing PHP

Add the extra modules Magento needs:

sudo apt install php-zip php-soap php-bcmath php-intl php-mbstring php-xsl

Raise the PHP limits in php.ini (for example memory_limit = 2G, max_execution_time = 1800), then restart Apache:

sudo systemctl restart apache2
Restarting Apache

Step 4: Create the database

sudo mysql -u root -p
Opening the MySQL shell
CREATE DATABASE magento;
Creating the database

Create a user (use a strong password, and localhost unless the database is on another machine):

CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON magento.* TO 'magento_user'@'localhost';
FLUSH PRIVILEGES;
Creating the user
EXIT;
Leaving the MySQL shell

Step 5: Download and extract Magento

Download the Magento 2 archive from the Magento Open Source download page (a free Adobe account is needed).

The Magento release page

Extract it into the web folder:

sudo tar -xvf ~/Downloads/magento2-2.4.7-p1.tar.gz -C /var/www/html
Extracting Magento

Set the owner:

sudo chown -R www-data:www-data /var/www/html
Setting the owner

Step 6: Create the Apache virtual host

sudo nano /etc/apache2/sites-available/magento.conf

Add (use your own domain; pub is the web root of Magento 2.4 if you point to it):

<VirtualHost *:80>
    ServerName example.com
    ServerAdmin admin@example.com
    DocumentRoot /var/www/html
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/apache2/magento_error.log
    CustomLog /var/log/apache2/magento_access.log combined
</VirtualHost>
The virtual host file

Enable the site and the rewrite module, then reload:

sudo a2ensite magento.conf
sudo a2enmod rewrite
sudo systemctl reload apache2
Reloading Apache

Step 7: Install Magento

Open your domain in the browser. The installer asks you to:

  • Accept the terms and conditions.
  • Choose the language and currency.
  • Enter the database details (database magento, the user and password from step 4).
  • Set the admin user, password and email address.
    The Magento installer

After the install, write down the admin URL. Then secure the store with an SSL certificate and keep Magento updated.

Quick recap

  • Install the LAMP stack and the PHP modules Magento needs.
  • Create a database, extract Magento and make a virtual host.
  • Finish with the web installer, and add SSL.