قالب وردپرس درنا توس
Home / How To / How to install Magento 2 with Nginx and Let's Encrypt SSL on Ubuntu 20.04 LTS

How to install Magento 2 with Nginx and Let's Encrypt SSL on Ubuntu 20.04 LTS



Magento is a widely used open source e-commerce software and content management system for e-commerce sites based on the PHP Zend Framework. It uses MySQL or MariaDB as a database backend. The development of Magento was started in 2008 by Varien.

In this tutorial we will show you step by step how to install Magento 2 in the latest version Ubuntu 20.04. We will install Magento under the LEMP stack, Nginx web server, PHP-FPM 7.3 and MariaDB server.

Requirements

For this tutorial, we install Magento 2 on the Ubuntu 20.04 system with 2 GB RAM, 50 GB free hard disk space and 2 processors.

What to do?

  • Install Nginx Web Server
  • Install and Configure PHP-FPM 7.3
  • Install and Configure MySQL Server
  • Install PHP Composer
  • Download and Install Magento
  • Generate SSL Letsencrypt
  • Virtual Ngin Setup for Magento
  • Magento Post-Installation

Step 1 – Installing Nginx Web Server

First we will install Nginx web server on the Ubuntu 20.04 system.

Install Nginx with the apt command below.

  sudo apt install nginx 

When all installation is complete, start the Nginx service and add it to the system boot.

  systemctl start nginx 
systemctl enable nginx

Then check the Nginx service st atus with the following command.

  systemctl status nginx 

The Nginx web server is running on Ubuntu 20.04 Server.

  Installing Nginx

Then we open the HTTP and HTTPS ports on our Ubuntu system.

Run the ufw command below.

  for svc in ssh http https 
do
ufw allow $ svc
done

As a result, the SSH, HTTP and HTTPS services have been added to the ufw firewall rule.

Now run activate the ufw firewall with the following command.

  ufw enable 

Type & # 39; y & # 39; and press Enter to activate the ufw firewall.

Step 2 – Install and Configure PHP-FPm 7.3

After installing the Nginx web server, we install PHP-FPM on our Ubuntu 20.04 Server.

By default, Ubuntu 20.04 comes with the latest version of PHP / PHP-FPM 7.4. But currently, Magento only works with PHP / PHP-FPM 7.3. And in this step we will install PHP-FPM 7.3 from the PPA repository.

Before proceeding, install the "software-features-common" package and add the PPA repository for PHP 7.3 with the following command. [19659017] sudo apt install software properties-common
sudo add-apt-repository ppa: ondrej / php

"add-apt-repository" will automatically update all layers in the system.

Now install PHP-FPM 7.3 packages from the PPA archive using the apt command below.

  sudo apt install php7.3-fpm php7.3 - common php7.3-curl php7.3-cli php7.3-mysql php7.3-gd php7.3-xml php7.3-json php7.3- intl php-pair php7.3-dev php7.3-common php7.3-mbstring php7.3-zip php7.3-soap php7.3-bcmath php7.3-opcache -y 

And the installation of PHP-FPM 7.3 is complete.

Then go to & # 39; /etc/php/7.3' directory and edit the configuration & # 39; php.ini & # 39; for PHP-F PM.

  cd /etc/php/7.3/strong19459025strongvim fpm / php.ini 

Cancel and change the configuration below.

  date.timezone = Asia / Singapore 
memory_limit = 1G
max_execution_time = 1800
zlib.output_compression = On
cgi.fix_pathinfo = 0

opcache.enable = 1
opcache .save_comments = 1

Save and close. Ads

Then start the PHP-FPM service and add it to the system startup.

  systemctl start php7.3-fpm 
systemctl enable php7.3-fpm

 Install and configure PHP-FPM 7.3

The PHP-FPM service is running, check it with command below.

  ss -xa | grep php 
systemctl status php7.3-fpm

As a result, PHP-FPM is running on the Ubuntu 20.04 server, it runs under the sock file & # 39; /run/php/php7.3-fpm .sock & # 39 ;.

 Checking PHP-FPM Service

Step 3 – Install and configure MariaDB server

In this step we will install the MariaDB database server, set the default password for MariaDB and create a new database and users for Magento.

Install MariaDB server package for Ubuntu 20.04 with the apt command below.

  sudo apt install mariadb server 

When all installation is complete, launch the MariaDB service and add it to the system boot.

  systemctl start mariadb 
systemctl enable mariadb

MariaDB service is running.

Then we set the root password MariaDB using the "mysql_secure_instalaltion" tool. 19659062] Ads

Run the "my" ql_secure_instalaltion command below. and enter "Y" for all configuration.

  Set a root password? [Y/n]   Y 
Remove anonymous users? [Y/n] Y
Removing root login remotely? [Y/n] Y [19659066] Remove the test database and access it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

As a result, MariaDB root password has been configured.

 Setup MariaDB root password

Then we create a new database and user for Magento installation.

Log in to the MariaDB / MySQL shell using the mysql command below.

  mysql -u root -p [19659018] Now create a new database for our Magento installation, create the database & # 39; stomach todb & # 39; and the user & # 39; magentouser & # 39; with the password & # 39; magentodbpass & # 39 ;. 

Run the MySQL queries below.

  create database magentodb; 
create user [email protected] "localhost" identified by "magentopassdb";
grant all privileges on gastric cancer. * Till [email protected] "localhost";
flush privileges;

Now type "exit" to log out of the MySQL shell.

 Creating Database for Magento

As a result, the new database and user for the Magento installation have been completed.

Step 4 - Install Composer

Composer is a PHP dependent manager. it is an application level for PHP that allows you to download additional PHP dependencies and libraries for your PHP project.

In this step we will install PHP Composer from the Ubuntu repository.

Install Composer with apt command below.

  sudo apt install composer -y 

When the installation is complete, check the composite version below.

  composer --version 

Below is the answer.

  Composer 1.10 .1 2020-03-13 20:34:27 

As can be seen, Composer 1.10 has been installed on Ubuntu 20.04 Server.

Step 5 - Download and install Magento 2

In this step, we will download and install Magento 2 and all PHP packages needed with Composer.

First, go to the & # 39; / var / www / & # 39; and download the source code Magento 2.3.5 CE (Community Edition) using the wget command as below.

  cd / var / www / 
wget -q https://github.com/magento/magento2/archive/2.3.5 .tar.gz

When all is done, extract the Magento source code and swap name of the extracted directory into the "magento2" directory.

  tar -xf 2.3.5.tar.gz 
etc. magento2 - * / magento2 /

Then go to the Magento installation directory & # 39; / var / www / magento2 & # 39; and install all PHP package dependencies for Magento using the Composer command as below.

  cd / var / www / magento2 / 
composer install

 Download and install Magento 2 Ads

Ads

When all installation is complete, fix ownership of Magento 2 installation directory to user & # 39; www data & # 39 ;.

  chown -R www-data: www-data / var / www / magento2 

As a result, Magento 2 installed and all package dependencies have been completed.

Step 6 - Generate SSL Letsencrypt

For this tutorial, we will secure the Magento 2 installation with SSL Le tsencrypt. And in this step we generate SSL Letsencrypt with the certbot command. Also, make sure your domain name is resolved to the server's IP address.

Install the certbot utility with the apt command below.

  sudo apt install certbot 

When the installation is complete, stop the Nginx service.

  systemctl stop nginx 
certbot certonly - standalone --ree-tos --no-eff-email - mail [email protected] -d magento.hakase-labs.io

After all, your SSL- certificate in the & # 39; /etc/letsencrypt/live/magento.your-domain.com' directory.

As a result, SSL Letsencrypt for Magento 2 has been generated.

Step 7 - Set up Nginx Virtualhost for Magento 2

In this step we will add a new Nginx virtualhost configuration for Magento 2.

Go to directory & # 39; / etc / nginx / sites -available / & # 39; and create a new configuration "magento" uses the vim editor.

  cd / etc / nginx / sites-available / 
vim magento

Paste the following configuration into it.

  upstream fastcgi_backend {
server unix: /run/php/php7.3-fpm. sock;
}

server {
listen 80;
listen [::]: 80;
servername magento.hakase-labs.io;
return 301 https: // $ server name $ request_uri;
}

server {

listen 443 ssl http2;
servername magento.hakase-labs.io;

ssl_certificate /etc/letsencrypt/live/magento.hakase-labs.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/magento.hakase-labs.io/privkey.pem; ebrit19659125] set $ MAGE_ROOT / var / www / magento2;
set $ MAGE_MODE developer;
include / var / www / magento2 / nginx.conf.sample;
}

Save and close.

Then enable Magento Nginx virtualhost and test the nginx configuration and make sure there is no error.

  ln-s / etc / nginx / sites-available / magento / etc / nginx / sites-enabled / 
nginx -t

Restart Nginx service using the following command.

  systemctl restart nginx 

As a result, the virtual host configuration of Nginx for Magento 2 has been created and enabled.

 Setting Nginx virtual host for Magento

Step 8 - Magento Post-Installation [19659015] Open your browser and enter your Magento installation domain name in the address bar.

https://magento.hakase-labs.io/

You will now be edited to HTTPS secure connection and you will receive the Magento welcome page and terms of use.

 Install Magento 2

Click & # 39; Agree and Setup Magento & # 39; to proceed.

On the "Contingency Control" page, make sure all requirements are green and click & # 39; Next ".

 System Requirements Preparedness

Enter the details in the MariaDB database and the user we created above and click on " Next ".

 Settings Database

For "web configuration", change all HTTP protocol to HTTPS and see to change Magento Admin Address & # 39;

 Setting HTTPS Magento

Now click on "Advanced Options" and select all HTTPS options, then uncheck "Apache Rewrites" and click " Next " button again.

Next, in the Magento configuration "Customize your store", leave it by default and click on the " Next " button.

 Magento Large Cuztomization

Enter details for admin users e, e-mail address and password. Then click the Next button.

 Magento Setup user

Click the "Install Now" button to install your Magento 2 store.

 Install Magento

Now all installation has no errors.

 Install Magento

When all installation is complete you will get " Success & # 39; page as below.

 Magento Install is ready

Click & # 39; Launch Magento Admin & # 39; to log in to your Magento Admin Dashboard.

 Magento Login Admin

Now write your Magento Admin user and password, then click "Login" and you will get Magento Admin Dashboard as below.

 Magento Admin Dashoard

For Magento's default index page, open new tab and enter your domain name in the address field.

Below is Magento's standard index page.

 Magento Index

As a result, the installation of Magento 2 has been completed.

Next, back to your server shells and we will set up Magento Cron and remove the condition to rewrite any Magento installation directory.

To set Magento cron, run the command below.

  cd / var / www / magento2 
sudo -u www-data php bin / magento cron: install - -force

Magento cron runs under user & # 39; www-data & # 39; check it with the following command.

  crontab -u www-data -l 

As a result, Magento Cron has been added to the system.

 Magento Setup Cron and delete write state

Then we need to remove the write state in the & # 39; / var / www / magento2 / app / etc & # 39; directory. [19659025] Run the chmod command below.

  chmod uw / var / www / magento2 / app / etc 

And finally the installation of Magento 2 with Nginx web server, MariaDB server, PHP-FPM 7.3 on the latest U buntu 20.04 has been successfully completed.

Reference


Source link