Как установить Magento 2 with Varnish, Apache and Pound as SSL Termination



В этой статье, Мы покажем вам, как установить Magento 2 на Ubuntu 16.04 VPS with MariaDB, Лак в полной страницы кэша, Apache and Pound as SSL termination. Это руководство должно работать на других Linux VPS systems as well but was tested and written for an Ubuntu 16.04 VPS.

Прежде чем мы начнем, you may want a different setup for your Magento. Вы можете следить за Этот учебник to install Magento 2 на Ubuntu 16.04 VPS с MariaDB, PHP-FPM 7.0, Лак в полной страницы кэша, Nginx as SSL termination and Redis for session storage and page caching.

Or you can check out Этот учебник to install Magento 2 на Ubuntu 16.04 VPS with MariaDB, Лак в полной страницы кэша, Apache и Memcache для хранения сессии.

If you have any different requirements, просто get a Linux VPS from us and we’ll set everything up for you, бесплатно.

1. Login and update your server

Прежде всего, you need to login to your Ubuntu 16.04 VPS через SSH as user root:

SSH [Электронная почта защищена]_IP_address

It is also recommended to start a screen session выполнив следующую команду

screen -U -S magento

Обновление системы and install necessary packages with:

APT получить обновление && apt-get -y upgrade
apt-get -y install curl nano git

It is crucial that you always keep your server up to date. Вы можете даже включить автоматическое обновление in order to achieve this.

2. Install and configure MariaDB

Install the latest MariaDB 10.0 server from the official Ubuntu repositories:

apt-get install -y mariadb-server

Следующая, we need to create a database for our Magento installation.

MySQL -u корень -p
MariaDB [(нет)]> CREATE DATABASE magento;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'localhost' IDENTIFIED BY 'strong_password';
MariaDB [(none)]> q

Do not forget to replace ‘strong_password’ with an actual strong password. Вы можете даже generate a strong password from the command line.

3. Install Apache2 web server

apt-get установить apache2

4. Установить необходимые модули PHP и PHP

Для установки последней стабильной версии PHP версии 7 и все необходимые модули, выполните:

apt-get install php7.0 libapache2-mod-php7.0 php7.0-mbstring php7.0-curl php7.0-zip php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-xsl php-imagick php7.0-gd php7.0-cli php-pear php7.0-intl

Change few default PHP settings:

sed -i "s/memory_limit = .*/memory_limit = 256M/" /etc/php/7.0/cli/php.ini
sed -i "s/upload_max_filesize = .*/upload_max_filesize = 128M/" /etc/php/7.0/cli/php.ini
sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/" /etc/php/7.0/cli/php.ini
sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php/7.0/cli/php.ini

Enable the Apache2 rewrite module if it is not already done:

переписать a2enmod

In order to activate the new configuration, restart the Apache web server using the following command:

перезапуск службы apache2

5. Install Composer

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.

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

6. Установить Magento 2 с Github

Clone the Magento repository to the ~/myMagentoSite.com directory using the following command:

git clone https://github.com/magento/magento2.git /var/www/myMagentoSite.com

Get the latest Magento 2 stable release:

cd /var/www/myMagentoSite.com
git checkout $(git describe --tags $(git rev-list --tags --max-count=1))

Run composer to install all Magento dependencies:

композитор установки

To continue with the installation you can either use the installation wizard or the command line, in this guide we will use the latter.

bin/magento setup:install 
[Электронная почта защищена] 

If the installation is successful you will see something like below:

[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_1m0ezr

Запуск crontab command to create a cronjob

crontab -u www-data -e

and add the following line:

* * * * * /usr/bin/php /var/www/myMagentoSite.com/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/myMagentoSite.com/var/log/magento.cron.log

И наконец, set the correct permissions:

chown -R www-data: /var/www/myMagentoSite.com

7. Configure Apache

Создайте новую директиву виртуальных хостов в Apache. Например, you can create a new Apache configuration file named ‘magento.conf’ on your server:

touch /etc/apache2/sites-available/magento.conf
ln -s /etc/apache2/sites-available/magento.conf /etc/apache2/sites-enabled/magento.conf
nano /etc/apache2/sites-available/magento.conf

Затем, Добавьте следующие строки:

<VirtualHost *: 80>
ServerAdmin [Электронная почта защищена]
DocumentRoot /var/www/myMagentoSite.com/
ServerName myMagentoSite.com
ServerAlias www.myMagentoSite.com
<Directory /var/www/myMagentoSite.com/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
ErrorLog /var/log/apache2/myMagentoSite.com-error_log
CustomLog /var/log/apache2/myMagentoSite.com-access_log common

Перезапустите веб-сервер Apache для изменения вступили в силу:

перезапуск службы apache2

You should be now able to login to your Magento back-end by going to http://myMagentoSite.com/admin_1m0ezr using the information you set when running the bin/magento setup:install.

8. Install and configure Varnish

To install Varnish, просто выполните следующую команду:

apt-get install varnish

From you Magento Admin dashboard click on the STORES link (left sidebar) -> Configuration -> ADVANCED -> System -> Full Page Cache

Uncheck “Use system value” and from the Caching Application list, select Varnish Cache (Recommended), save the configuration, click on the Varnish Configuration link and click on the Export VCL for Varnish 4 Кнопка. В varnish.vcl file which we will use will be exported in the /var/www/myMagentoSite.com/var/ Каталог.

Flush the Magento cache with:

php bin/magento cache:flush

Delete the /etc/varnish/default.vcl and symlink it to the exported varnish configuration.

rm -f /etc/varnish/default.vcl
ln -sf /var/www/myMagentoSite.com/var/varnish.vcl /etc/varnish/default.vcl

To change varnish port from 6081 Кому 80, we need to edit the systemd service configuration.

Create a new customexec.conf файл

mkdir -p /etc/systemd/system/varnish.service.d
nano /etc/systemd/system/varnish.service.d/customexec.conf

вставьте следующее:

ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

and reload systemd units

systemctl демон перезагрузка

Now we need to change Apache listening port from 80 Кому 8080. Для этого, open the Apache ports configuration file and change it as follows:

nano /etc/apache2/ports.conf

Listen 80 -> Прослушать 8080
nano /etc/apache2/sites-available/magento.conf

<VirtualHost *: 80> -> <VirtualHost *: 8080>

If everything is setup correctly now you should be able to login to your Magento back-end by going to https://myMagentoSite.com/admin_1m0ezr.

Stuck somewhere? Получить VPS from us and we’ll do all of this for you, бесплатно!

9. Install and configure Pound as SSL termination

Varnish doesn’t support SSL traffic, so you will need to install a proxy or load balancer like Pound to handle the SSL traffic. Для этого, we will configure Pound to only listen on port 443 and pass the traffic to Varnish on port 80.

Первый, let’s install Pound with:

apt-get install pound

Open the Pound configuration file:

nano /etc/pound/pound.cfg

and set the following:

    Address ## this should be your server public IP address
    Port 443
    Cert "/etc/apache2/ssl/myMagentoSite.com.pem" ## path to your SSL certificate
    HeadRemove "X-Forwarded-Proto"
    AddHeader "X-Forwarded-Proto: https"
            Порт 80

After you are done, restart your Apache and Varnish, and Pound:

service apache2 restart
service varnish restart
service pound restart

10. Further Optimizations

To further optimize your Magento installation from your Magento admin dashboard:

1. Go to STORES -> Configuration -> CATALOG -> Catalog -> Use Flat Catalog Category, select Yes and click Save Config.
2. Go to STORES -> Configuration -> ADVANCED -> Developer -> JavaScript Settings and set both Merge JavaScript Files and Minify JavaScript Files to Yes and click Save Config..
3. Go to STORES -> Configuration -> ADVANCED -> Developer -> CSS Settings and set both Merge CSS Files and Minify CSS Files to Yes and click Save Config.
4. Consider using a CDN – Content Delivery Network

Do not forget to flush the cache again:

php bin/magento cache:flush

You can also follow our guide on how to speed up Magento.

Ну вот. You have successfully installed Magento 2 with Memcache as a session storage and page caching, Varnish as a full page caching and Apache on your Ubuntu 16.04 VPS and you have set up Pound as SSL termination. For more information about how to manage your Magento installation, please refer to the official Magento Документация.


Оставь ответ