Install magento2 in Nginx server Ubuntu 14.04

Tutorial setup magento in LEMP Ubuntu 14.04

1. Update the system and install necessary packages

sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install software-properties-common curl nano

2. Install MariaDB over 10.0
sudo apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository ‘deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu trusty main’
sudo apt-get update
sudo apt-get install -y mariadb-server

after install create new database In my tutorial i create database m2
– you can create database by phpmyadmin, adminer.php , command line, or using navicat connect to mysql server.

3. Install PHP, composer and required PHP modules
sudo add-apt-repository -y ppa:ondrej/php5-5.6
sudo apt-get update
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
after install you can check version again by php -v

4. With m2 i think need install composer for easy update later

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

5. Install and configure Nginx over 1.10
sudo add-apt-repository -y ppa:nginx/stable
sudo apt-get update
sudo apt-get -y install nginx

check version after install:
nginx -v

6. Create virtual host nginx

sudo nano /etc/nginx/sites-available/magento2.phpcoban.com

paste content on it

upstream fastcgi_backend {
# use tcp connection
# server 127.0.0.1:9000;
# or socket
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name magento2.phpcoban.com;
set $MAGE_ROOT /var/www/magento2;
include /var/www/magento2/nginx.conf.sample;
}

Activate the server block by creating a symbolic link :*******MUST USE FIX PATH

sudo ln -s /etc/nginx/sites-available/magento2.phpcoban.com /etc/nginx/sites-enabled/magento2.phpcoban.com

Test the Nginx configuration and restart nginx:

sudo nginx -t
sudo service nginx restart

7. Install magento 2 on virtual host

– Download stable version with sample data from magento
– upload to magento root folder /var/www/magento2
– install zip
sudo apt-get install zip
– unzip Magentoxxxxxxxxxxxxxxxxxxxxxxxxxxxx.zip
remember change your file name.

*** INSTALL MAGENTO2 IN NGINX CAN’T INSTALL BY WEB UI. YOU MUST INSTALL BY COMMAND LINE (PARAMS IN COMMAND LINE ARE ALWAYS CHANGE)

when i installed it , command look like

sudo php bin/magento setup:install –db-host=localhost –db-name=m2 –db-user=root –db-password=abcabcabc –backend-frontname=admin –admin-user=admin –admin-password=abcabcabc –admin-email=demo@gmail.com –admin-firstname=thanh –admin-lastname=long –base-url=http://magento2.phpcoban.com/ –base-url-secure=https://magento2.phpcoban.com/ –language=en_US –currency=USD –use-rewrites=1 –use-secure=0 –use-secure-admin=0 –cleanup-database

8. after install

sudo php bin/magento cache:flush
sudo php bin/magento deploy:mode:set developer
php bin/magento setup:static-content:deploy -f
sudo chmod 777 -R /var/www/magento2/var/
sudo chmod 777 -R /var/www/magento2/pub/

That’s it !

How to debug when it don’t work .

– Check log nginx
tail -f /var/log/nginx/error.log
– check exception in magento
tail -f /var/www/html/var/log/exception.log
– Check file virtualhost config work or not
don’t use /var/www/html/ to place magento on it. Because you will don’t know default config was used or virtual host was used

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">