How To Install Magento On Ubuntu 18.04

How To Install Magento On Ubuntu 18.04


Magento is a robust e-commerce platform that enables developers and online entrepreneurs to create and customize online stores in minutes. The platform is written in PHP, and it requires database and web servers to run successfully. On the other hand, Ubuntu is an open source platform that delivers technical and economic scalability to meet enterprise-level server needs.

This tutorial will help you install the latest version of Magento on Ubuntu 18.04 LTS. We’ll use the LAMP (Linux, Apache2, MySQL, and PHP) stack to install Magento 2 on your Linux distribution. To accomplish this, let’s follow the steps below.


First, you should ensure your system is up-to-date. Run the commands below to update and upgrade your system:

$ sudo apt-get update -y
$ sudo apt-get upgrade -y

Step 1 –
Installing Apache2

As aforementioned, Magento requires a web server to run commendably. For this reason, we’ll first install Apache2 which is one of the most popular web servers in the modern tech world. Run the command below to install Apache2:

$ sudo apt-get install apache2

Next, run the command below to deactivate the directory listing:

$ sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/apache2/apache2.conf

Once Apache2 is installed run the command below to start and enable the service:

$ sudo systemctl start apache2.service
$ sudo systemctl enable apache2.service

Step 2 –
Installing MariaDB

By now the web server is set. Next, we install the database server, and MariaDB is always a great platform to start with. Run the commands below to install MariaDB.

$ sudo apt-get install mariadb-server mariadb-client

Use the commands below to start and enable the database server:

$ sudo systemctl start mariadb.service
$ sudo systemctl enable mariadb.service

Next, run the command below to secure the database server:

$ sudo mysql_secure_installation

Here, you will be prompted to answer the following questions:

  • Enter current password for root (enter for none): since you have just installed MariaDB and have not set the root password yet, the password value is blank. Press Enter to continue.
  • Set root password? [Y/n]: Type Y and press Enter to continue
  • New password: Enter your preferred password
  • Re-enter new password: Re-type the password and press enter to continue
  • Remove anonymous users? [Y/n]: Type Y, then press enter
  • Disallow root login remotely? [Y/n]: Type Y and press enter
  • Remove test database and access to it? [Y/n]: Type Y, then press enter
  • Reload privilege table now? [Y/n]: Type Y and press enter.

Restart the database server:

$ sudo systemctl restart mariadb.service

Step 3 –
Installing PHP 7.1 And Its Related Modules

Ubuntu default repositories don’t provide PHP 7.1, and that means you have to install the application from third-party repositories.

The commands below will help you add 3rd party repository for PHP 7.1:

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:ondrej/php

To update and upgrade to the required PHP version (7.1), run the command below:

$ sudo apt update

Next, run the following command to install PHP 7.1 together with its related modules:

$ sudo apt-get install php7.1 php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-gd php7.1-xml php7.1-intl php7.1-mysql php7.1-cli php7.1-mcrypt php7.1-ldap php7.1-zip php7.1-curl

Step 4 –
Creating Magento Database

By now, all the packages required to support Magento 2 installation are ready. Next, we’ll create a blank database for Magento. To accomplish this, first, login to the MariaDB server:

$ sudo mysql -u root -p

You will be prompted for your MariaDB Server password. Enter the password and click Enter to continue.

Run the following commands to create a new database titled Magento.


Next, create a user called magentouser and assign the user a new password, using the commands below:


Then grant, the user you’ve created unlimited access to the new database:

GRANT ALL ON magento.* TO'magentouser'@'localhost'IDENTIFIEDBY'user_password_here'WITHGRANTOPTION;

Save the changes and exit:


Step 5 –
Downloading The Latest Magento Release

Create an account on Magento website to get the right to download a copy of the application. Download the community edition of Magento.

Next, run the following commands to extract the file into your Apache2 root directory:

$ sudo mkdir /var/www/html/magento/
$ sudo tar -zxvf ~/Downloads/Magento-CE*.tar.gz -C /var/www/html/magento/

You will need to alter the directory permission to suite the Apache2 configuration:

$ sudo chown -R www-data:www-data /var/www/html/magento
$ sudo chmod -R 755/var/www/html/magento

Step 6 –
Configuring Apache2

By now the installation is almost complete, but we need to configure Apache2 website configuration file for your Magento store. This configuration file dictates how your site visitors access the Magento content.

First, we create the configuration file and name it magento.conf:

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

Next, paste the following content into the configuration file and save.

Note: Replace and with your own credentials.

<VirtualHost *:80>
     DocumentRoot /var/www/html/magento/

     <Directory /var/www/html/magento/>
        Options Indexes FollowSymLinks MultiViews
        Order allow,deny
        allow from all

     CustomLog${APACHE_LOG_DIR}/access.log combined

Save and exit

Step 7 –
Enabling The Rewrite Module and Magento

Once the virtual host is configured, run the commands below to enable it:

$ sudo a2ensite magento.conf
$ sudo a2enmod rewrite

Step 8 –
Restarting Apache2

Run the command below to restart the service:

$ sudo systemctl restart apache2.service

Restarting Apache2 allows all the settings changes to take effect.

Step 9 –
Setting Up The Magento Store

Open a web browser and search your server domain name ( This will present the Magento setup wizard. Follow the instructions in the wizard to complete the setup.

How To Install Magento On Ubuntu 18.04

  • Readiness Check

Click Start Readiness Check to initiate the process:

How To Install Magento On Ubuntu 18.04

How To Install Magento On Ubuntu 18.04

  • Adding Database Information

Next, enter your database credentials

How To Install Magento On Ubuntu 18.04

Click Next to move to the next step, Follow the instructions carefully and continue until you get to Create Admin Account.

  • Creating Admin Account

Enter all the required details

How To Install Magento On Ubuntu 18.04

Continue until the setup is complete:

How To Install Magento On Ubuntu 18.04

That is it!


You have successfully installed Magento on your Ubuntu 18.04 server. Thank you for using this tutorial to install one of the most popular, open source eCommerce platforms. All the best as you embark on a mission to trade online.

Check out these top 3 Magento hosting services:

$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
$1.79 /mo
Starting price
Visit FastComet
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing

How to Install the LEMP (Linux, Nginx, MySQL, PHP) Stack on an Ubuntu 18.04 VPS or Dedicated Server

This tutorial walks you through the process of installing Nginx, MySQL, and PHP
4 min read
Mark Armistead
Mark Armistead

How To Install Apache, MySQL & PHP on an Ubuntu 18.04 VPS or Dedicated Server

This article shows users how to setup PHP, Apache web server and MySQL database
4 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install AMPPS on Ubuntu 18.04

AMPPS is a solution stack for Apache, MYSQL, MongoDB, PHP, Perl and Python that
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Install OpenCart on an Ubuntu 18.04 Server or VPS with Apache, MariaDB and PHP 7

In this how-to, you'll learn how to install OpenCart, an open source shopping ca
3 min read
Angela Olaru
Angela Olaru
Senior Writer & Hosting Expert provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top