Install Magento on Ubuntu 16.04

Install Magento on Ubuntu 16.04


Magento is an eCommerce open source software, and a content management system for eCommerce websites. It uses MySQL 5.6+ or MariaDB as possible databases, and it’s compatible with both NGINX and Apache web servers. It also requires PHP7+ and some of its extensions.
This tutorial demonstrates how to install Magento 2 on an Ubuntu 16.04 server using NGINX and MySQL.

Getting started

Update the server

First check for updates, and then install:

# apt update

Install NGINX

NGINX is available on Ubuntu repository, so you can easily install it with



# apt install nginx

Install PHP

Since you are likely hoping that the site will be accessed by many visitors, it’s better to install PHP-FPM (FastCGI Process Manager), which has various features. So, install it and the extensions required by Magento:

# apt install php7.0-mcrypt php7.0-fpm php7.0-curl php7.0-mysql php7.0-cli php7.0-xsl php7.0-json php7.0-intl php7.0-dev php-pear php7.0-mbstring php7.0-common php7.0-zip php7.0-gd php-soap



 as well:

# apt install curl libcurl3
Editing PHP settings

Modify the two configuration files:

  • /etc/php/7.0/fpm/php.ini

    – FPM configuration;

  • /etc/php/7.0/cli/php.ini

    – PHP-CLI configuration file;

In both, add the following lines (or edit if already existing):

memory_limit = 2G
max_execution_time = 3600
opcache.save_comments = 1
zlib.output_compression = On

Save, exit and restart PHP-FPM so that changes will be applied:

# systemct restart php7.0-fpm

Install and configure MySQL

To install MySQL, execute the following command:

# apt install -y mysql-server mysql-client

Next, set up a root account for it:

# mysql_secure_installation
Set root password? [Y/n]
New password:
Re-enter new password:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]

If importing a large numbers of products into Magento is required, just increase the value for the 


option using the following code:

# $EDITOR /etc/mysql/mysql.cnf

There, search for the mentioned line, and modify as follow:


Save, exit and restart MySQL:

# systemctl restart mysql

Next, start a MySQL command prompt:

# mysql -u root -p

Create a new user and database:

mysql> CREATE DATABASE magento_db;
mysql> CREATE USER 'magentousr'@'localhost' IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON 'magento_db.*' TO 'magentousr'@'localhost' IDENTIFIED BY 'user_strong_password';
mysql> EXIT;

Downloading Magento

Magento 2 will be installed in the 


directory. The installation requires PHP Composer. Install PHP Composer by executing the following command:

# curl -sS | php

Move the


file to



mv composer.phar /usr/local/bin/composer

Test that everything is going smoothly so far with:

# composer -v

This should print out the composer version.

To obtain Magento (the Community Edition, in this tutorial), first go to and create an account there. Next, follow My Account > Developer > Secure Keys, and generate new keys.

Now it’s time to download Magento. On a terminal, execute the following command:

# composer create-project --repository-url= magento/project-community-edition /var/www/magento2

During this process, use the public key for username and the private key for the password.

Configure a Virtual Host

Create a new Virtual Host file:

# $EDITOR /etc/nginx/sites-available/magento

In the Host File, paste the following configuration:

upstream fastcgi_backend {
        server  unix:/run/php/php7.0-fpm.sock;

server {

        listen 80;
        set $MAGE_ROOT /var/www/magento2;
        set $MAGE_MODE developer;
        include /var/www/magento2/nginx.conf.sample;

Magento already contains an NGINX configuration file, so it’s not necessary to create one.

Save and exit.
Next, activate the virtual host:

# ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled/

Restart NGINX:

# systemctl restart nginx

Install Magento



there is a binary file named magento. This will be used for installing Magento 2.

# /var/www/magento2/bin/magento setup:install --backend-frontname="admin" \
--db-host="localhost" \
--db-name="magento_db" \
--db-user="magentousr" \
--db-password="usr_strong_password" \
--language="en_US" \
--currency="USD" \
--timezone="My/Timezone" \
--use-rewrites=1 \
--use-secure=0 \
--base-url="" \
--base-url-secure="" \
--admin-user=admin \
--admin-password=admin_password \ \
--admin-firstname=admin \
--admin-lastname=user \

At the end:

[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin

Final configuration

As usual in cases like this, the last step is a “graphical configuration” through a web browser. Go to, and log in with the admin credentials you created during the installation process.
After signing in the Magento Dashboard should appear, signifying that everything went well. The ecommerce web site is now ready to be filled with products!