install-magento-2-on-an-ubuntu-14-04-vpsIn this guide, we will explain how to install Magento 2 on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx. Magento 2 is a complete overhaul of the Magento 1.x codebase and it requires PHP 5.5+, MySQL 5.6+ and Nginx 1.8+ or Apache 2.2+, This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 14.04 VPS.

Login to your VPS via SSH

ssh [email protected]

Update the system and install necessary packages

[user]$ sudo apt-get update && sudo apt-get -y upgrade
[user]$ sudo apt-get install software-properties-common curl nano

Install MariaDB 10.0

To add the MariaDB repository to your sources list and install the latest MariaDB server, run the following commands:

[user]$ sudo apt-key adv --recv-keys --keyserver hkp:// 0xcbcb082a1bb943db
[user]$ sudo add-apt-repository 'deb trusty main'
[user]$ sudo apt-get update
[user]$ sudo apt-get install -y mariadb-server

When the installation is complete, run the following command to secure your installation:

[user]$ mysql_secure_installation

Next, we need to create a database for our Magento installation.

[user]$ mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE magento;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'localhost' IDENTIFIED BY 'okdf9Js8fj';
MariaDB [(none)]> \q

Install PHP, composer and required PHP modules

To install the latest stable version of PHP version 5.6 and all necessary modules, run:

[user]$ sudo add-apt-repository -y ppa:ondrej/php5-5.6
[user]$ sudo apt-get update
[user]$ sudo apt-get -y install php5-fpm php5-cli php5-gd php5-imagick php5-mysqlnd php5-mcrypt php-pear php5-curl php5-intl php5-gd php5-xsl

Composer is a dependency manager for PHP with which you can install packages. Composer will pull in all the required libraries and dependencies you need for your project.

[user]$ curl -sS | php
[user]$ sudo mv composer.phar /usr/local/bin/composer

Install Magento 2

Create a root directory for your Magento using the following command:

[user]$ mkdir -p ~/{public_html,logs}
[user]$ cd ~/

Issue the Composer create-project command:

composer create-project --repository-url= magento/project-community-edition public_html

When prompted, enter your Magento support portal user name and password. If you don’t have an account you can create one at:

Change to the directory and install Magento:

[user]$ cd ~/

Change the following values as per your setup

admin_email='[email protected]'
php bin/magento setup:install --base-url=$base_url \
--db-host=$db_host --db-name=$db_name --db-user=$db_name --db-password=$db_password \
--admin-firstname=$admin_firstname --admin-lastname=$admin_lastname --admin-email=$admin_email \
--admin-user=$admin_user --admin-password=$admin_password --language=$language \
--currency=$currency --timezone=$timezone --use-rewrites=1

When the installation is complete, you’ll see the message below.

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

PHP-FPM configuration

Create a new PHP-FPM pool for your user:

[user]$ sudo nano /etc/php5/fpm/pool.d/your_user.conf
user = your_user
group = your_user
listen = /var/run/php5-fpm-your_user.sock
listen.owner = your_user = your_user
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 200
chdir = /

Do not forget to change your_user with your username.

Restart PHP-FPM:

[user]$ sudo service php5-fpm restart

Install and configure Nginx

Ubuntu 14.04 comes with nginx version 1.4, to install the latest stable version of Nginx version 1.8, run:

[user]$ sudo add-apt-repository -y ppa:nginx/stable
[user]$ sudo apt-get update
[user]$ sudo apt-get -y install nginx

Create a new Nginx server block with the following content:

[user]$ sudo nano /etc/nginx/sites-available/
upstream fastcgi_backend {
  server   unix:/var/run/php5-fpm-your_user.sock;

server {
    listen 80;
    set $MAGE_ROOT /home/your_user/;
    set $MAGE_MODE developer; # or production

    access_log /home/your_user/;
    error_log /home/your_user/;

    include /home/your_user/;        

Do not forget to change your_user with your username.

Activate the server block by creating a symbolic link :

[user]$ sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Test the Nginx configuration and restart nginx:

[user]$ sudo nginx -t
[user]$ sudo service nginx restart

That’s it. You have successfully installed Magento 2 on your Ubuntu 14.04 VPS. For more information about how to manage your Magento installation, please refer to the official Magento documentation.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.