logo

How to Install Magento 2 on Ubuntu 16.04 in Localhost

In this guide we will learn how to install Magento 2 on an Ubuntu operating system (16.04 LTS) in Localhost.

According to the official website of Magento 2 the requirements for installing Magento over a LAMP environment (Apache, MySQL, PHP) are:

  • Apache 2.2 o 2.4
  • MySQL 5.6
  • PHP 5.6.5, 7.0.2, 7.0.4, 7.0.6-7.0.x

Apart from the above mentioned requirements we will also install Composer, a repository from which we will download the latest version of Magento and all its dependencies.

 

Install Apache

To install apache in Ubuntu we will execute the following commands in the terminal:

 

Once Apache is installed, open the file apache2.conf and at the end of the file write: ServerName localhost 

 

Check that there are no errors and restart the server:

 

Install MySQL

To install MySQL in our system we will execute the following command in the terminal, accept all and choose the password for the root user (the password can’t be empty):

 

Once installed MySQL we created the database for Magento 2:

 

Install PHP

In this example we will use PHP version 7 to run our installation of Magento, we will also install some libraries the project will need:

 

We then verify that our PHP installation is working correctly on the server by creating the file info.php:

Once created, write the following lines:

If we type http: //localhost/info.php in our web browser we should see the PHP configuration of our server. Once verified that everything works correctly we will delete the file for security.

 

An alternative way to install the lamp environment in ubuntu is to use the following command:

 

If we have any problem installing Apache, MySQL or PHP we can go to the Ubuntu troubleshooting page for Apache.

 

Install Composer

Composer is a dependency manager for PHP. It will be responsible for installing the necessary libraries for the project in their corresponding versions. In this case it will manage Magento installation and all its dependencies.

To install composer we will follow the instructions of the official website (Do not copy the code from here, the instructions may change).

 

Once installed we will verify that everything is correct by executing:

 

Generate Magento Marketplace authentication keys

In order to download Magento 2 and its modules from the repository we need to be able to connect to it in a secure way. We can obtain the keys by registering in Magento Marketplace and following these instructions.

Once the keys are generated, we will create the authentication file:

 

And we will include the following code (including quotation marks), replacing “public_key” y “private_key” with the keys we generated in our Magento account:

 

Install Magento 2

Once our server meets all the requirements we will install Magento 2. There are three ways for installing it:

  • Using composer
  • Cloning Github repository (in this case you cannot use the Magento software in a production environment.)
  • Downloading Magento 2 from its official website

 

Install Magento 2 using Composer

For speed and to ensure that our store is fully updated we will use composer for the installation, in this case we will install the version of Magento 2.1.1 in the route “/var/www/html/magento2”. For this we will wwil go to the project folder and we will execute composer:

 

Install Magento 2 cloning GitHub repository

Note that if you install Magento 2 from Github the project can not be used in a production environment. To install it we will go to the project folder and run (in this case we are installing version 2.1.1):

 

Install Magento 2 from file

To install Magento 2 manually we must download the latest version of Magento 2 available on the official webpage and unzip the file where we want to host the project.

 

Set file permissions

Whether you installed Magento 2 using Composer, Git or a downloaded file from the official page, it is necessary that the folder structure has certain permissions before the installation to be able to configure Magento correctly:

 

Configure Magento 2

To start Magento 2 configuracion we will go to http://localhost/magento2/setup in our browser and we will follow the steps of the configurator.

 

This guide can be applied for later versions of Magento 2 and for other GNU / Linux based operating systems.

Leave a comment