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 7.0 in FPM mode, and MariaDB as the database. I will use ubuntu 16.04 (Xenial Xerus) as server operating system. If you don't have a minimal server setup yet, please see this tutorial to get a proper base setup.

Prerequisites:

Ubuntu 16.04 - 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 suapt-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 7 in PHP-FPM mode. Additionally we will install the following PHP extensions that are required by magento.

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

mysql_secure_installation

Set root password? [Y/n] YNew password:Re-enter new password: <-- Enter the new password

Remove anonymous users? [Y/n] Y ... Success!

Disallow root login remotely? [Y/n] Y ... Success!

Remove test database and access to it? [Y/n] Y

Reload privilege tables now? [Y/n] Y ... Success!

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 '[email protected]'. Please choose a secure password for the 'magentouser' on your server and not the one '[email protected]' that I used in this example!

- Configure the Magento Key

Register an account on the Magento website repo.magento.com. 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.

- Install Third-party Components 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.

- 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:

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 http://randomkeygen.com/.Base-url = make sure it is same with virtual host configuration.

Conclusion

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 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.

About Muhammad Arul

Muhammad Arul is a freelance system administrator and technical writer. He is working with Linux Environments for more than 5 years, an Open Source enthusiast and highly motivated on Linux installation and troubleshooting. Mostly working with RedHat/CentOS Linux and Ubuntu/Debian, Nginx and Apache web server, Proxmox, Zimbra Administration, and Website Optimization. Currently learning about OpenStack and Container Technology.

I did not have any issues executing all of this, but when I hit my browser to go to magento, I get sent to the internet vs bring up magento. Any suggestions on what I might have missed? I did use the www.newmagento.com.

I installed Magento2 using this guide. After the server went into production after months of development I started getting strange issues, like problems in installing modules, system upgrade etc. Then I came to know that one should never install a production server using composer. It is for testing/development purposes only.

I then got stuck as it was produciton site with lots of products/blog posts etc. Well I had to create a new server and then copy everything one by one... hard luck.

Secondly I've seen Magento2 is tightly integtrated with Apache. It gives strange problems with NginX when in production. It does run but it limps. My 2nd advice will be to run it on Apache if you want to save yourself headaches down the line. Though you would need more resources but it's better than not being even able to access Web Setup Wizard without a hack.

Using Composer is fine on production systems as well, it does not matter for a PHP file if you copy it manually or if it got copied by a composer script. Magento works fine on Nginx, many large Magento shops use it and it's also documented by the Magento developers how to run their software n Nginx.