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://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
[user]$ sudo add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu 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)]> FLUSH PRIVILEGES;
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 https://getcomposer.org/installer | 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 ~/myMagentoSite.com/{public_html,logs}
[user]$ cd ~/myMagentoSite.com

Issue the Composer create-project command:

composer create-project --repository-url=https://repo.magento.com/ 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: https://www.magentocommerce.com/products/customer/account/create/

Change to the directory and install Magento:

[user]$ cd ~/myMagentoSite.com/public_html

Change the following values as per your setup

base_url='http://myMagentoSite.com'
db_password='long_password'
db_host='localhost'
db_name='magento'
db_user='magento'
admin_firstname='Name'
admin_lastname='Lastname'
admin_email='your@email.com'
admin_user='admin'
admin_password='long_password'
language='en_US'
currency='USD'
timezone='America/Chicago'
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
[your_user]
user = your_user
group = your_user
listen = /var/run/php5-fpm-your_user.sock
listen.owner = your_user
listen.group = 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/myMagentoSite.com
upstream fastcgi_backend {
  server   unix:/var/run/php5-fpm-your_user.sock;
}

server {
    server_name myMagentoSite.com;
    listen 80;
    set $MAGE_ROOT /home/your_user/myMagentoSite.com/public_html;
    set $MAGE_MODE developer; # or production

    access_log /home/your_user/myMagentoSite.com/logs/access.log;
    error_log /home/your_user/myMagentoSite.com/logs/error.log;

    include /home/your_user/myMagentoSite.com/public_html/nginx.conf.sample;        
}

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/myMagentoSite.com /etc/nginx/sites-enabled/myMagentoSite.com

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.

Tutorials
How to install Website Baker on a CentOS 7 VPS
Tutorials
Install gpEasy CMS with NGINX and PHP5-FPM on an Ubuntu 14.04 VPS
Tutorials
How to install LEMP (Linux, Nginx, MySQL & PHP-FPM) on a Debian 8 VPS
  • Bruno

    BrunoBruno

    Author Reply

    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?


    • admin

      adminadmin

      Author Reply

      Do you get some error message when you try to run the install command?


  • Serge

    SergeSerge

    Author Reply

    Hi,
    I have the same problem
    Error meesage :
    Could not open input file: bin/magento


  • Serge

    SergeSerge

    Author Reply

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


  • Francis Kim

    Thanks for the up to date tutorial, it helped me build my Docker image for Magento 2.


  • Anabolika

    AnabolikaAnabolika

    Author Reply

    Thanks for the tutorial, very good material


  • Vinicius

    ViniciusVinicius

    Author Reply

    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/myMagentoSite.com/public_html/nginx.conf.sample” failed (2: No such file or directory) in /etc/nginx/sites-enabled/myMagentoSite.com:14
    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.


    • Vinicius

      ViniciusVinicius

      Author Reply

      Btw, I tried ‘admin’, and my linux user name, still having the same issue


      • admin

        adminadmin

        Author Reply

        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 ~/myMagentoSite.com/{public_html,logs}” will create two directories:
        /home/mark/myMagentoSite.com/public_html
        /home/mark/myMagentoSite.com/logs

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


  • Rajkumar

    RajkumarRajkumar

    Author Reply

    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


  • chandu

    chanduchandu

    Author Reply

    [Composer\Downloader\TransportException]
    Invalid credentials for ‘https://repo.magento.com/packages.json’, abortin
    g.

    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] [–] [] [] []


  • Salvo

    SalvoSalvo

    Author Reply

    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.


  • nick

    nicknick

    Author Reply

    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/myMagentoSite.com/public_html/vendor/magento/magento -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/scripts.md#event-classes in phar:///usr/local/bin/composer/src/C omposer/EventDispatcher/EventDispatcher.php:289

    Can you please suggest


    • admin

      adminadmin

      Author Reply

      What version of Composer do you use?

      You can update Composer or reinstall it and try again.

      Thanks


    • admin

      adminadmin

      Author Reply

      What version of Composer do you use?

      You can update Composer or reinstall it and try again.

      Thanks.


  • Nick

    NickNick

    Author Reply

    I followed your isntruction as given above


    • admin

      adminadmin

      Author Reply

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


  • proxax

    proxaxproxax

    Author Reply

    – 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
    [InvalidArgumentException]
    Project directory public_html/ is not empty.


    • proxax

      proxaxproxax

      Author Reply

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

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