How to Install Magento2 On Ubuntu

Updated 19 December 2018

Magento is one of the most popular content management system for e-commerce websites. There are also a large numbers of extensions and themes available online for further enhancement as per requirements. Magento has released its new version Magento2 with a variety of improvements and optimizations over the previous version Magento-1. This blog will help you to install Magento2 on Ubuntu and Debian systems. You can also follow my blogs for Magento2 installation on Windows and Mac OS.

 

Prerequisites:

 

Operating systems:- Various Linux (x86-64) distributions can be used such as Ubuntu, RedHat Enterprise Linux (RHEL), CentOS, Debian, etc. Here I will be using Ubuntu LAMP server to install Magento 2.x for this demo.

 

Memory requirement:- Minimum 2GB of RAM is recommended for a smooth functioning and performance of Magento. If less than 2GB of RAM is present, it is recommended to create a swap file.

 

Web servers:-

  • Apache 2.2 or 2.4 : In addition, the Apache mod_rewrite module must be enabled. mod_rewrite enables the server to perform URL rewriting.
  • nginix 1.8 or later.

In my demo, i will be using Apache or 2.4

 

Database:-

  • MySQL 5.6 is compatible with all Magento2 versions.
  • Magento application version 2.1.2 and later are compatible with MySQL 5.7.
  • MariaDB and Percona are compatible with Magento.

In my demo, i will be using MySQL 5.7

 

PHP:- Magento2 supports php versions 7.0.13–7.0.x and 7.1.x. We will use here the latest version of php 7.0 for this demo.

 

Required PHP extensions:-

bc-math, curl, gd, imagemagick 6.3.7 or later, intl, mbstring, mcrypt, mhash, openssl, pdo/mysql, mysqli, simplexml, soap, xml, xsl, zip, and json, iconv (for php 7 only).

 

Composer (Optional):- Composer is a dependency manager for PHP. Composer will manage the dependencies you require on a project by project basis. This means that Composer will pull in all the required libraries, dependencies and manage them all in one place.

 

 

Installation:

 

Now that we have the prerequisites installed, let’s get started with Magento 2.x Installation on our Ubuntu LAMP server. To begin first prepare your LAMP Server with required prerequisites.

 

Step-1 : Install Apache2

 


 

Enable apache rewrite and headers module.

 


 

Step-2: Install php7 and its extensions:

 

Install php7 and all the required extensions with their dependencies.

 


 

Press enter if prompt for confirmation.



 

Step-3: Download MySQL 5.7 Database

 

We will install MySQL 5.7 on our Ubuntu server. Magento uses a MySQL database to manage site data, like product and order information.

Now install the mysql server. Enter the root password when prompt. Finally check the mysql version to verify its installation.

 



 

Now since our LAMP server is ready, we can now verify the settings and further download the Magento2 source code for installation.

 

Step-4: PHP Settings

 

Magento uses PHP for various complex operations and needs sufficient amount of memory to run the Magento scripts without crash. By default, the memory allocated by PHP for each script is 128 MB which must be increased to 512 MB better performance.

Edit the below file. Find the line “memory_limit = 128M” and change the value to 512M. Then save and exit.

 


 

Step-5: Prerequisite check:

 

Before you begin, you can quickly check all the prerequisites on your Ubuntu server by running below commands.

Check the version of apache and php:

 



 

Check the version of MySQL and verify its connectivity :

mysql  -u <DB user> -p

 

for example:-

 


 

If database server is on remote host, use the below command.

mysql -h <remote_host_IP>  -u <DB user> -p

 

Step-6: Download Magento2 source code.

 

You can download the latest source code from Magento official website or from github.

 

NOTE: If you download from github, we need to download and use composer for Magento installation. In case you download from official website through your browser, you can directly use the source code as it provides the required dependencies.

 

a) Without Composer:

 

Download the latest source code from Magento official website, i.e. https://magento.com/tech-resources/download/. If you need to install magento2 on a remote server, copy the downloaded source code to the server through scp or rsync, etc.

 



 

The source code downloaded from the official website contains all the required dependencies. So there is no need for composer here.

 

 

b) With Composer:

 

Now let us download and install the latest source code from github. At the time of this blog, the latest version is 2.2.6.

To install magento2 with composer, first create the Access keys of magento marketplace. If you have an account on Magento Marketplace, simply signin and generate the access keys. If you don’t have an account, create an account by registering yourself on marketplace.magento.com

For generating Access keys, login in to magento marketplace and from the top right corner of the page where your user name is displayed, navigate to My profile > Marketplace > My products > Access Keys

Now create a new pair of Access keys. You need to provide the public Key as username and Private Key as password when prompt.

First install composer on the server.

 


 

The syntax for installing magento2 through composer is as follows.
composer create-project –repository=https://repo.magento.com/ magento/project-community-edition <install-directory-name>

 

You can use the below command for installing magento2 latest version through composer.

 


 

For installing a specific version of magento2, mention the magento version at the end of the command as follows.

 


 

During this process, you will be asked to provide the username and password. Provide the generated Access Keys where the public Key is the username and Private Key is the password. Also, you will be asked whether you want to store the credentials in auth.json. You can select “n” if you don’t wish to save your credentials on the server.

Then copy the magento2 files to the Document root of the webserver.

 


 

Give the proper web-server permissions.

 


 

Step-7: Configuring Apache

 

Configure the Apache with the below configuration. If you want to run magento on a domain, uncomment and provide the server name as per your requirement in the below configuration. Else you can leave it commented and access it later with IP or localhost.

 



 

Save and quit the file and restart the apache2 server.

 


 

Step-8: Create a MySQL Database and User

 

Login to your MySQL server and create a user and database for your Magento application. Change the database name, database user and password as per your need.

 



 

Now create the below database with the relevant information as follows or alternatively you can do it later through the web interface by hitting the Magento url you provided in apache configuration.

 



 

Step-9: Accessing Magento2 web interface.

 

Make entry in /etc/hosts if don’t have a DNS entry of the domain on your DNS server.

 



 

To Access your Magento2, you can enter your URL in browser.

http://mymagento2.com                    -> for home page

http://mymagento2.com/admin         -> for admin pannel

 

If you have not configured the database through the install command in step-8, you can do the same through the GUI web interface. Just follow the instructions and provide the required database and admin user information and install Magento2.

 

 

So by now, you have successfully installed and configured Magento2 on your Ubuntu LAMP server.

 

In case of any query, please feel free to Contact us.

         

Tag(s) magento2 ubuntu
author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


4 comments

  • Tijo
    • Kamal Verma (Moderator)
  • Aasik Ellahi
  • Trigle
  • Start a Project




      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home