Monday, February 7, 2022

Install Magento 2 with Nginx, Self signed SSL, MariaDB 10.x, PHP 7.3 on Ubuntu 20

 Description: Here I have explained, How to install Magento 2 with Nginx, Self signed SSL, MariaDB 10.x, PHP 7.3 on Ubuntu 20

  • Before start the installation Update the packages 
# apt update 



  • Install Nginx using apt command 
# apt install nginx 



  • Start and Enable Nginx service. Check the Nginx service status
# systemctl start nginx
# systemctl enable nginx 
# systemctl status nginx 


  • Install and configure PHP-FPm 7.3
  • Before install PHP add repository for same 
sudo apt install software-properties-common
add-apt-repository ppa:ondrej/php



  • Install PHP from PPA repository 
# 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-pear php7.3-dev php7.3-common php7.3-mbstring php7.3-zip php7.3-soap php7.3-bcmath php7.3-opcache -y



 
  • Update PHP FPm and CLI configuration as follow
Open /etc/php/7.3/fpm/php.ini and vi /etc/php/7.3/cli/php.ini configuration file and update the parameters as follow:

date.timezone = Asia/Kolkata memory_limit = 2G max_execution_time = 1800 zlib.output_compression = On cgi.fix_pathinfo = 1 opcache.enable=1 opcache.save_comments = 1

  • Start and Enable php-fpm service. Also check php-fpm status
# systemctl start php7.3-fpm
# systemctl enable php7.3-fpm
# systemctl status php7.3-fpm 

  • Install and Configure MariaDB
# apt install mariadb-server

After installation start and enable mariadb service 

# systemctl start mariadb
# systemctl enable mariadb

Configure Mariadb

# mysql_secure_installation 

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

Login into mysql using root user and create database and user with privileges

# mysql -u root -p 

create database magentodb; create user magentouser@'localhost' identified by 'magentopassdb'; grant all privileges on magentodb.* to magentouser@'localhost'; flush privileges;

Install composer and verify the version

# apt install composer -y
# composer --version 

Download and Install Magento 2 

# cd /var/www   ### You  can change to path as per your requirement ###
# wget -q https://github.com/magento/magento2/archive/2.3.5.tar.gz
# tar -xf 2.3.5.tar.gz
# mv magento2-2.3.5/ magento2
# cd /var/www/magento2/
# composer install


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

Setup SSL for Magento Site: Here I am going to create self signed certificate and use it for same

  • Generate Self Signed SSL in ubuntu [In this example I will use magentotestlab.com as URL]
# mkdir /home/ssl
# cd /home/ssl
#  openssl req -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes -out magentotestlab.crt -keyout magentotestlab.key


Country Name (2 letter code) [AU]:IN State or Province Name (full name) [Some-State]:GJ Locality Name (eg, city) []:AH Organization Name (eg, company) [Internet Widgits Pty Ltd]:magentotestlab pvt ltd Organizational Unit Name (eg, section) []:IT Common Name (e.g. server FQDN or YOUR name) []:magentotestlab.com Email Address []:

Note: After filled all the details certificate and key file will be created on same path

Setup Nginx Virtual Host for Magento2 

  • Open the Nginx configuration directory and create configuration for Magento
# cd /etc/nginx/sites-available/
# vi magentotestlab                    ### Create the configuration and paste as follow ###

upstream fastcgi_backend { server unix:/run/php/php7.3-fpm.sock; } server { listen 80; listen [::]:80; server_name magentotestlab.com; return 301 https://$server_name$request_uri; } server { listen 443 ssl http2; server_name magentotestlab.com; ssl_certificate /home/ssl/magentotestlab.crt; ssl_certificate_key /home/ssl/magentotestlab.key; set $MAGE_ROOT /var/www/magento2; set $MAGE_MODE developer; include /var/www/magento2/nginx.conf.sample; }
f
Remove Default host configuration from /etc/nginx/sites-available and /etc/nginx/sites-enable 
After remove the configuration link the configuration using ln  command 

# ln -s /etc/nginx/sites-available/magentotestlab /etc/nginx/sites-enabled
# nginx -t   ### Verify the configuration after setup ###


# systemctl restart nginx

Magento Post Installation Task 

Browse the URL and complete the task 

https://magentotestlab.com/


First step is to check the readiness 



Give Database and User details to connect DB



URL and Admin URL Details


Store Configuration Details 


Create Admin User for Magento 


Install Magento








Once the installation will completed you will receive Screen as follow



Troubleshooting:

Too Many Redirection error in Admin Page 
  • After installation some time Admin page showing error like too many redirection 

  • To resolve this redirection issue navigate to installation path /var/www/magento2 and run the following commands
# cd /var/www/magento2/
# bin/magento config:set web/secure/use_in_adminhtml 1
# php bin/magento cache:clean


  • Now try to reopen the admin url 



Setup Cron in Magento: After setup Magento Need to setup default cron job for Magento 

Navigate to Path /var/www/magento2
# cd /var/www/magento2
# bin/magento cron:install --force     ### Install cron job ### 


Verify the cron by using crontab -l  command 



















No comments:

Post a Comment