Installation and configuration of Nginx and Magento

Magento is an open source online shopping management platform.

The system is quite demanding on resources, so popular shop will generate a high load on the hardware and software. Therefore Magento on Nginx will provide the best performance and speed. Magento and Nginx

Requirements

Before installing Magento, you need to have installed Nginx with ngx_http_fastcgi_module, MySQL, PHP at least version 5.5, and modules php-fpm, php-cli, php-mysql, php-curl, php-gd.

Installation

Magento requires Composer:

curl -sS https://getcomposer.org/installer | php


# Move file
mv composer.phar /usr/bin/composer



# Test
composer -v

# Download and installation of Composer

After that you can download and put Magento in the correct directory:

tar -xzvf 2.1.0.tar-gz
mv magento2-2.1.0/ /var/www/magento2/

# Placing in the /var/www/magento2/

Now you can install the system. There are several methods we use the console:

cd /var/www/magento2/

bin/magento setup:install --backend-frontname="adminlogin" \ 	# URI for administration dashboard 
--db-host="localhost" \ 					# Database adress (IP, localhost or URL with port)
--db-name="magentodb" \ 					# Database name
--db-user="magentouser" \ 					# Database user
--db-password="magentouser@" \ 					# Database user password
--language="en_US" \ 						# Administration panel language
--currency="USD" \ 						# Currency by default
--timezone="America/New_York" \ 				# Timezone
--use-rewrites=1 \ 						# Links rewrite
--use-secure=0 \ 						# Enable TLS/SSL
--base-url="http://www.newshop.com" \ 				# Website adress
--base-url-secure="https://www.newshop.com" \ 			# HTTPS website adress
--admin-user=adminuser \ 					# Magento administrator
--admin-password=admin123@ \ 					# Magento administrator password
--admin-email=admin@newshop.com \ 				# e-mail администратора
--admin-firstname=admin \ 					# User name
--admin-lastname=user \ 					# User surname
--cleanup-database

# Installation of Magento with additional parameters, marked are mandatory

Nginx configuration

After we can proceed to Nginx configuration. First you need to create a configuration file for /etc/nginx/sites-available/magento.conf and fill it. Server section will look like:

server {
    listen   80;
    server_name newshop.com www.newshop.com;
    root   /var/www/magento2;
	
	...
	}

# Don't forget to specify the domain

First location section:

location / {
        index index.html index.php; 


        try_files $uri $uri/ @handler;
        expires max;
}

    location ^~ /app/                { deny all; }
    location ^~ /includes/           { deny all; }
    location ^~ /lib/                { deny all; }
    location ^~ /media/downloadable/ { deny all; }
    location ^~ /pkginfo/            { deny all; }
    location ^~ /report/config.xml   { deny all; }
    location ^~ /var/                { deny all; }

# Transfers the URI, if the path does not exist, specifies a cache life, prohibits access to internal directories

Next you need to specify access to the export directory:

location /var/export/ { 
        auth_basic           "Restricted";
        auth_basic_user_file htpasswd;
        autoindex            on;
    }

# Permits acess to user, specified in /etc/nginx/htpassword

Additional location sections:

    location  /. { 
        return 404;
    }

    location @handler { 
        rewrite / /index.php;
    }

    location ~ .php/ { 
        rewrite ^(.*.php)/ $1 last;
    }

# Restricts acess to hidden files, rewrites scripts

The php-fpm parameters:

location ~ .php$ { 

        try_files $uri $uri/ /index.php last;
        expires        off;

        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_param  HTTPS $fastcgi_https;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;

        fastcgi_param  MAGE_RUN_CODE default; 
        fastcgi_param  MAGE_RUN_TYPE store;

		fastcgi_buffer_size 128k;
		fastcgi_buffers 256 4k;
		fastcgi_busy_buffers_size 256k;
		fastcgi_temp_file_write_size 256k;
}

# Specifies the default fastcgi settings and additional buffers to avoid common mistakes

Then activate host:

ln -s /etc/nginx/sites-available/magento.conf /etc/nginx/sites-enabled/
systemctl restart nginx

# Creates a link to the configuration file, restarts Nginx

The most important

Configure a heavily loaded online store backend for your needs. Extras include Varnish or Memcache, use backend balancing with Nginx.

Подпишитесь на Хайлоад с помощью Google аккаунта
или закройте эту хрень