Install Magento 2 on an Ubuntu 14.04 VPS

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 user@vps

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

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.

21 thoughts on “Install Magento 2 on an Ubuntu 14.04 VPS”

  1. Hi,
    Thanks for the tutorial, very good material but I am stuck at step “php bin/magento setup:install” because magento can not be found. Can you give me an advice here, please?

  2. OK,
    Before launch :
    composer create-project –repository-url= magento/project-community-edition public_html
    type :
    cd ~/

  3. I got confused with the “your_user” parts at the end. Maybe this is the source of my error message after sudo nginx -t:

    nginx: [emerg] open() “/home/admin/” failed (2: No such file or directory) in /etc/nginx/sites-enabled/
    nginx: configuration file /etc/nginx/nginx.conf test failed

    And as a way around the php bin/magento problem, I found another “public_html” folder inside the one created, where I found the so needed bin folder; then the php bin/magento command works.

      • your_user is the user you are logged in as. You can find out what your username (your_user) is by executing “whoami”

        For example if your user is “mark” the command “mkdir -p ~/{public_html,logs}” will create two directories:

        You can try to delete the magento directory “rm -rf ~/” and start again from the step “Install Magento 2”.

  4. Hi,
    I followed your documentation but , i got runtime exception in magento install cmd [ EX: 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] , I run this command for specified my details but it says [RuntimeException] The “–cleanup_database” option does not exist. what is the problem

  5. [Composer\Downloader\TransportException]
    Invalid credentials for ‘’, abortin

    create-project [-s|–stability STABILITY] [–prefer-source] [–prefer-dist] [–repository-url REPOSITORY-URL] [–dev] [–no-dev] [–no-plugins] [–no-custom-installers] [–no-scripts] [–no-progress] [–keep-vcs] [–no-install] [–ignore-platform-reqs] [–] [] [] []

  6. Go to Magento Connect register and get a secure keys couple. Use public key as username and private key as password. After this step is done you need a personal access token from github account. Get it also.

  7. hi after ï

    Issue the Composer create-project command: getting below error
    Writing lock file
    Generating autoload files
    Deprecation Notice: The callback MagentoHackathon\Composer\Magento\Plugin::onNew CodeEvent declared at /root/ -composer-installer/src/MagentoHackathon/Composer/Magento/Plugin.php accepts a C omposer\Script\CommandEvent but post-update-cmd events use a Composer\Script\Eve nt instance. Please adjust your type hint accordingly, see https://getcomposer.o rg/doc/articles/ in phar:///usr/local/bin/composer/src/C omposer/EventDispatcher/EventDispatcher.php:289

    Can you please suggest

    • We successfully installed Magento 2 using this tutorial. Please follow the instructions closely and you should not have any problem with it.

  8. – Installing magento/module-multishipping (100.1.0)
    Downloading: Failed
    Downloading: 100%

    How do I install just this module? Every other component installed.

    I tried installing again and received the following error;

    Installing magento/project-community-edition (2.1.0
    Project directory public_html/ is not empty.

    • No worries. I’ve used the following to empty the Dir and Deleted the folder using SFTP access

      rm -rf /*
      rm -f /*
      rm -rf /{*,.*}


Leave a Comment

To prove you are human please solve the following *