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 [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://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}

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='[email protected]'
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.

Related Post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.