Magento 2 setup on Ubuntu 16.04

In you have the pre-installed Magento 2 image available, but if you are interested in doing the setup yourself, here is a tutorial with all the steps to set up the Magento e-commerce, would you rather have it set up by our technical team? Call us or e-mail us to [email protected], we’ll get to work right away so you can start your online business now!

Magento is the most popular content management system for e-commerce websites. This CMS is used both in small and large companies as it can be adapted to the needs of each one owing to its thousands of extensions and themes.

Magento uses MySQL, PHP programming language and Zend framework. In the tutorial below, we will explain how to install Magento in a Clouding VPS with a previous installation of LAMP under Ubuntu 16.04.

Before starting

It is important that before going on with the tutorial we have a VPS server in Clouding with the following:

It is recommended that our VPS has RAM 2GB or more due to the processing requirements of Magento.

To continue, it is important that the VPS has a LAMP installed (Linux, Apache, MySQL, PHP) in addition to a basic setup.

Server prep for Magento

Magento requires some extra PHP instances to work well:

# apt install php7.0-common php7.0-gd php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-iconv

Apache setup for Magento

Before downloading and installing Magento, Apache needs to be setup to properly handle the Magento traffic and computing tasks, and some additional modules will have to be setup and activated.

First we check that we are using version 2.4 of Apache with:

# apache2 -v

Activate the rewrite module for Apache:

# a2enmod rewrite

Create a setup file for Magento:

# touch /etc/apache2/sites-available/magento.conf

On the file, add the following:

Directory /var/www/html/vhosts/magento/www>
Require all granted
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/vhosts/magento/www

ErrorLog /var/www/html/vhosts/magento/logs/error.log
CustomLog /var/www/html/vhosts/magento/logs/access.log combined
<Directory /var/www/html/vhosts/magento/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All

It is important that from this setup you modify the parameters ServerName, ServerAlias, ServerAdmin and DocumentRoot.

We create the directories where we’ll copy Magento:

# mkdir -p /var/www/html/vhosts/magento/{logs,www}

Activate the VirtualHost for Magento:

# a2ensite magento.conf

And we recharge the Apache setup:

# systemctl reload apache2

Database Formation

We start session within MySQL with the root user:

# mysql -u root -p

We create the database for Magento, a user and set up the permissions. For this tutorial we have decided to call the database and the user like Magento have. Replace p4ssw0rd for a secure password.

CREATE USER 'magento' IDENTIFIED BY 'p4ssw0rd';
GRANT ALL PRIVILEGES ON magento.* TO 'magento';

We leave the MySQL shell:


PHP Setup

We need to modify two parameters in the PHP configuration so that Magento works correctly. We edit the files /etc/php/7.0/cli/php.ini and /etc/php/7.0/apache2/php.ini. We look for the following parameters and modify them so that:

memory_limit = 2G
date.timezone = Europe/Madrid

Magento Setup

Once we have configured the web server it is time to set up Magento on it. The first thing we’ ll do is to register on the Magento website to download the packages. We have downloaded the Full Release package.

We select the finished file in tar.gz and click on “Download”.



As we have downloaded it locally, we’ll have to copy it to our server. For example, we can use scp:

# scp Magento-CE-2.1.6-2017-03-29-01-08-05.tar.gz [email protected]:/root

Once we have it on our server, we will unzip it in the directory indicated in the Apache setup file:

# tar zxf Magento-CE-2.1.6-2017-03-29-01-08-05.tar.gz -C /var/www/html/vhosts/magento/www/

Users and Permissions Setup

We create a user for the Magento files. To simplify we will call it magento:

# useradd magento

Next, we will add it to the Apache group (the www-data):

# usermod -g www-data magento

And once the user is created, we set up the permissions the following way and execute these commands in the established order:

# find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \;
# find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
# chown -R magento:www-data ../../magento
# chmod u+x bin/magento

Magento CE Installation

There are two ways to set up Magento, the first one is by CLI version, that is, with commands from the server. The second one, easier and more recommended, is to do it through the browser in a GUI environment.

CLI Version

Access in the path where we have copied on our Magento and enter the bin directory. In this directory we’ll find a file that allows us to execute an installation using commands.

# ./magento setup:install --admin-firstname="Soporte" --admin-lastname="Clouding" --admin-email="[email protected]" --admin-user="soporte" --admin-password="p4ssw0rd" --db-name="magento" --db-host="localhost" --db-user="magento" --db-password="p4ssw0rd"

It is important that all the parameters are replaced in quotes that you want to setup:

  • admin-firstname / admin-lastname: Es el nombre completo del administrador.
  • admin-email: EL correo electrónico para reiniciar la contraseña y para recibir las notificaciones
  • admin-user / admin-password: Son las credenciales para iniciar sesión en el panel de control de Magento.
  • db-name: Nombre de la base de datos
  • db-host: Anfitrión del servidor MySQL, si es el mismo servidor utiliza localhost.
  • db-user: Usuario de la base de datos.
  • db-password: Contraseña configurada para la base de datos.

When the setup is done, it shows the following at the end:

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

GUI Version

We access the installation from a browser where we’ll put the server IP in the address bar or, if we have set up a domain, the domain name. We should load the following page:magento_install_1We initiate the installation doing a check on the necessary extensions for PHP:

magento_install_2If all shows in green and is correct, we move on. If there is an error, examine the registry to find out what extension or problem exists. Once solved, go ahead with the installation:magento_install_3We set up the database that we have created before:

magento_install_4Then we set up the store, adding the domain and accessing the administration panel:

magento_install_5Next, we set up the time zone, currency and language:

magento_install_6Eventually, we set up an administrator:

magento_install_7Once we have all the setup done, we start the setup of the store:


And ready! You can now access your Magento store.

Magento setup

If you have accessed the Magento Dashboard, you’ll see that Cron Jobs news show up. It is necessary that the following is setup for a good operation:

Set up Cron Jobs

We open crontab with the Magento user we have created:

# crontab -u magento -e

If this is the first time you are using cron, a message will show up asking you what editor you want to use. Select one with a number.

At the end of the file we add the following:

* * * * * /usr/bin/php /var/www/html/vhosts/magento/www/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/vhosts/magento/www/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/vhosts/magento/www/update/cron.php >> /var/www/html/vhosts/magento/www/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/vhosts/magento/www/bin/magento setup:cron:run >> /var/www/html/vhosts/magento/www/var/log/setup.cron.log

Note: Remember to change /var /www/html/vhosts/magento/www for the path of the Magento installation you have configured. It is important that php is executed with the absolute path/usr /bin/php to work properly on Cron Jobs.

The first line is responsible for reindexing. The second and third are required for the Component Manager and system update.

Now, to check that this setup works, we leave Magento and log in again, in this case we should not see any notification.

Setup the X-Frame options

We strongly recommend disabling the ability to display the Magento store in one frame, this way we avoid clickjacking attacks. For this, we have to modify the app/etc/env.php file.

Change SAMEORIGIN for DENY, as shown below:

'X-frame-options' => 'DENY',

This prevents attackers from embedding their store in a frame (for instance, in a malicious site that mimics their store) in an attempt to intercept payments and other confidential customer information.

To write a comment on this article, fill out the form below. Fields marked with an asterisk (*) are required.