There is a new revision of this tutorial available for Ubuntu 16.04 (Xenial Xerus).

How to Install Magento with Nginx on Ubuntu 15.10

Magento is an open source e-commerce software and content management system for e-commerce websites based on the PHP Zend Framework. It uses MySQL or MariaDB as database backend. The Magento development has been started in 2008 by Varien.

In this tutorial, I will show you how to install Magento 2 with Nginx, PHP-FPM, and MariaDB as the database. I will use ubuntu 15.10 (Wily Werewolf) as a basis for the installation. If you don't have a minimal server setup yet, please see this tutorial to get a proper base setup.


  • Ubuntu 15.10 - 64 bit.
  • Root Privileges.

Step 1 - Install Nginx

Login to your Ubuntu server with your root account (e.g. by SSH) and update the repository.

sudo su
apt-get update

Then install Nginx:

apt-get install nginx -y

Verify that nginx has been installed properly by checking the port:

netstat -plntu | grep 80

Step 2 - Install and Configure PHP-FPM

In this step we will to install PHP 5.6 in PHP-FPM mode. Additionally we will install the following PHP extensions that are required by magento.

  • php-gd
  • php-mhash
  • php-mcrypt
  • php-xsl
  • php-pear
  • php-soap

Install the packages with the apt command below:

apt-get install php5-fpm php5-mhash php5-mcrypt php5-curl php5-cli php5-mysql php5-gd php5-xsl php5-json php5-intl php-pear php5-dev php5-common php-soap libcurl3 curl -y

We have to enable the php5-mcrypt extension manually by creating a symlink in the conf.d directory.

cd /etc/php5/fpm/conf.d
sudo ln -s ../../mods-available/mcrypt.ini

cd /etc/php5/cli/conf.d
sudo ln -s ../../mods-available/mcrypt.ini

Now edit the php.ini files for fpm and cli.

vim /etc/php5/fpm/php.ini
vim /etc/php5/cli/php.ini

and increase the memory limit and php execution time and turn on zlib compression by adding the following lines at the end of the files:

memory_limit = 512M
max_execution_time = 1800
zlib.output_compression = On

Save and exit.

Restart the PHP-FPM service to apply the configuration changes:

systemctl restart php5-fpm

Step 3 - Install and Configure MariaDB

I will use MariaDB instead of MySQL here. Install MariaDB with the apt command:

apt-get install mariadb-server mariadb-client -y

Set the MariaDB root user password with this command:

mysqladmin -u root password mypassword

Then connect to the MySQL shell (the MariaDB shell gets started with the command MySQL) with your root password, create a database with the name 'magentodb' and a user 'magentouser' with the password 'magentouser@'. Please choose a secure password for the 'magentouser' on your server and not the one 'magentouser@' that I used in this example!

Login to the MySQL shell:

mysql -u root -p

In the MySQL shell, run these commands:

create database magentodb;
create user [email protected] identified by 'magentouser@';
grant all privileges on magentodb.* to [email protected] identified by 'magentouser@';
flush privileges;

 Database Configuration.

Database created and configured.

Step 4 - Install and Configure Magento 2

We will install Magento in the directory '/var/www/magento2'. For the Magento installation, we need the PHP composer.

Install php composer

Go to the root directory, download the composer installer file with curl and run it to install composer.

cd ~/
curl -sS | php

Move the file 'composer.phar' file to the bin directory of your server and rename it to composer so it can be executed easily:

mv composer.phar /usr/bin/composer

Now verify that composer command is working:

composer -v

- Download and Extract Magento 2

Go to the web directory '/var/www/' and download Magento from it's Github repository, then unpack the downloaded tar.gz file:

cd /var/www/
tar -xzvf 2.0.0.tar-gz
mv magento2-2.0.0/ magento2/


- Configure the Magento Key

Register an account on the Magento website This account is required to use Magento and the Magento composer store. When you have registered, go to the Tab 'My Account > Developer > Secure Keys', next generate your keys.

Magento Keys

- Configure the Github Token

Make sure you have registered at Generate the GitHub access token by clicking on your top profile, go to 'Settings > Personal Access Tokens' and click on 'Generate new token'.

Generate a Github Token.

- Install Third-party Component for Magento

Go to the Magento 2 installation directory '/var/www/magento2' and run the composer command:

cd /var/www/magento2/
composer install -v

You will be asked for the Magento authentication, use the public key as username  and the private key for the password.

Then you will be asked for the GitHub token, paste it and press 'enter' to continue the third-party component.

Magento Third party Component installation.

- Configure the Nginx Virtualhost

Magento offers a ready-made Nginx virtual host configuration, so we just have to include it in our configuration.

Go to the Nginx virtual host directory and create new file called magento:

cd /etc/nginx/sites-available/
vim magento

Paste configuration below:

upstream fastcgi_backend {
        server  unix:/var/run/php5-fpm.sock;

server {

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

Replace with the domain name of the website that your shop shall use.

Save and exit.

Now activate the virtual host and restart Nginx:

ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled/
systemctl restart nginx

- Install Magento

We will install magento on the command line. In the Magento directory '/var/www/magento2/' there is binary file with the name 'magento' that is used to install and manage magento. Run the command:

bin/magento setup:install --backend-frontname="adminlogin" \
--key="biY8vdWx4w8KV5Q59380Fejy36l6ssUb" \
--db-host="localhost" \
--db-name="magentodb" \
--db-user="magentouser" \
--db-password="magentouser@" \
--language="en_US" \
--currency="USD" \
--timezone="America/New_York" \
--use-rewrites=1 \
--use-secure=0 \
--base-url="" \
--base-url-secure="" \
--admin-user=adminuser \
--admin-password=admin123@ \
[email protected] \
--admin-firstname=admin \
--admin-lastname=user \

backend-frontname = the admin page for our magento site, we use 'adminlogin'.
Key = our magento keys, we can generate it, or find it random on etc.
Base-url = make sure it is same with virtual host configuration.

At the end of the installation procedure you should see this lines:

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

Before we will test the Magento installation, ensure the web directory owner is 'www-data', then restart nginx.

cd /var/www/magento2/
chown -R www-data .

systemctl restart nginx

Now open the Magento domain in your browser:

In my case, the name is:

Magento home.

Try to log in to the Magento admin dashboard:

Magento Admin page.

Note :

If you get an error about the Magento indexer and cronjob, then you can solve it by adding the following cronjob to your server:

crontab -u www-data -e

Add the following lines:

*/1 * * * * php -c /etc/php5/cli/php.ini /var/www/magento2/bin/magento cron:run 
*/1 * * * * php -c /etc/php5/cli/php.ini /var/www/magento2/update/cron.php 
*/1 * * * * php -c /etc/php5/cli/php.ini /var/www/magento2/bin/magento setup:cron:run 

Save and exit.

Magento 2 with Nginx and PHP-FPM on Ubuntu 15.10 is installed now.


Magento is an open source e-commerce platform based on the PHP Zend Framework. It is a complex e-commerce software to help you with your online business. Magento uses an MVC (Model-View-Controller) architecture and MySQL or MariaDB as the database. Magento is easy to install, we can install it with Nginx or Apache web server. Magento has become one of the most popular e-commerce software on the internet and is uses by many successful shop websites worldwide.

Share this page:

9 Comment(s)

Add comment


From: Betty at: 2016-01-21 17:41:22

Hi, I followed everything through with no errors right until the end. Nothing works because my nginx root is /var/www/html and my magento folder is in www. Can you tell me where I went wrong please?Thanks :)

From: till at: 2016-01-21 19:00:04

/var/www/html is the default nginx vhost, this tutorial creates a new one in the file /etc/nginx/sites-available/magento

Check that you created that file, that you changed the domain name inside, that you reloaded anginx and that you access the website trough that exact domain name. If you use another domain name that points to the same server or when you use the Ip, then you'll end up in the default vhost and not the magento site.

From: Betty at: 2016-01-21 19:18:12

Yes, file /etc/nginx/sites-available/magento exists and the url looks good for my site. When I go to url it does show the default 

Welcome to nginx!


From: Betty at: 2016-01-21 21:18:33

Just deleted my server instance and started again from the beginning. Still not showing my Magento and going straight to nginx default page. 

From: Stephanie at: 2016-03-03 11:57:46

I found that single quotes instead of double quotes would let complex passwords pass on the setup:install line without trouble.  Anything else would freak it out.  I also never needed the developer creds on install.  I used 2.0.2 downloaded from their website.


bin/magento setup:install --backend-frontname="adminlogin" \

--key="23dlasdf2vade2sdg4SJA5umasdfafKsI" \

--db-host="localhost" \

--db-name="magento" \

--db-user="magento" \

--db-password='tRau}?>Zd)' \

--language="en_US" \

--currency="USD" \

--timezone="America/New_York" \

--use-rewrites=1 \

--use-secure=1 \

--base-url="" \

--base-url-secure="" \

--admin-user="admin" \

--admin-password='lI=sff[YD' \

--admin-email="[email protected]" \

--admin-firstname=admin \

--admin-lastname=user \


From: anthony portillo at: 2016-03-20 14:20:49

Thanks for your Tutorial, i had a problem and now i could fix it

From: Andy at: 2016-03-25 18:48:59

Such a great tutorial. Thanks so much I've been trying to install this magento for a day now and have reinstalled the server twice before finsing your step by step simplified.

In step 4 installing magento2 section you have

tar -xzvf 2.0.0.tar-gz where it should read

tar -xzvf 2.0.0.tar.gz

I was getting erro and noticed it. So far its a great learning resource.

From: patrickpeng at: 2016-05-14 00:13:44

cron job :

cd /var/www/magento2/


bin/magento cron:run --group="www-data"

From: philip at: 2016-05-28 15:17:50

Using php-7.0,

after logging in to magento with "composer install -v", I never made it to github key:

Deprecation Notice: The callback MagentoHackathon\Composer\Magento\Plugin::onNewCodeEvent declared at /var/www/magento2/vendor/magento/magento-composer-installer/src/MagentoHackathon/Composer/Magento/Plugin.php accepts a Composer\Script\CommandEvent but post-install-cmd events use a Composer\Script\Event instance. Please adjust your type hint accordingly, see in phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:289Stack trace: phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:169 phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:95 phar:///usr/bin/composer/src/Composer/Installer.php:296 phar:///usr/bin/composer/src/Composer/Command/InstallCommand.php:133 phar:///usr/bin/composer/vendor/symfony/console/Command/Command.php:259 phar:///usr/bin/composer/vendor/symfony/console/Application.php:844 phar:///usr/bin/composer/vendor/symfony/console/Application.php:192 phar:///usr/bin/composer/src/Composer/Console/Application.php:221 phar:///usr/bin/composer/vendor/symfony/console/Application.php:123 phar:///usr/bin/composer/src/Composer/Console/Application.php:101 phar:///usr/bin/composer/bin/composer:43 /usr/bin/composer:24