Wednesday, August 12, 2020

Magento 2.4 installation on Linux Mint 20c


How to Install Magento 2.4 installation on Linux Mint 20c


Prerequisites:

1.An Ubuntu 20.04 or Linux Mint 20c server with 4GB RAM and 2 CPUs set up with a non-root sudo user. You can achieve this by following the Initial Server Setup with Ubuntu 20.04 or Linux Mint 20c

2.OpenJDK 11 installed

Step 1 – Search OpenJDK Packages

sudo apt-cache search openjdk

Step 2 – Install JAVA (OpenJDK)

sudo apt-get install openjdk-11-jre openjdk-11-jdk

Step 3 – Configure Default Java Version

java -version

Step 4 – Set JAVA_HOME
open /etc/environment file and add below code :

JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/

after check below command :
echo $JAVA_HOME














Installing and Configuring Elasticsearch 

Step 1 — Installing and Configuring Elasticsearch

curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

sudo apt-get update

sudo apt install elasticsearch

Step 2 — Configuring Elasticsearch :

Edit You  /etc/elasticsearch/elasticsearch.yml 

cluster.name: my-application
node.name: magecomp
network.publish_host: localhost
discovery.seed_hosts: [ ]
network.host: 127.0.0.1
http.port: 9200
cluster.initial_master_nodes: 127.0.0.1

Step  3 - check Elasticsearch
sudo systemctl start elasticsearch

Running Elasticsearch with systemdedit
To configure Elasticsearch to start automatically when the system boots up, run the following commands:
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
Elasticsearch can be started and stopped as follows:
sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service


Vesrion Check : curl -XGET 'http://localhost:9200'

curl http://localhost:9200/_cluster/health?pretty

curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:9200/tutorial/helloworld/1?pretty'










How To install Magento 2.4.0 

  Magento 2.4 technology stack requirements:

 Linux distributions, such as RedHat Enterprise Linux (RHEL), CentOS, Ubuntu, Debian, and similar. Magento may not work properly With:

-- Windows OS
-- Mac OS

 Memory requirement
-- Minimum Up to 2GB of RAM
 Composer (latest stable version)
  --  1.10.9

 Web servers
Apache 2.4
nginx 1.x
To install the default version of Apache (Ubuntu 14, 16—Apache 2.4):
1. Install Apache
apt-get -y install apache2

Verify the installation.
apache2 -v

The result displays similar to the following:
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2016-04-15T18:00:57

3. Enable rewrites and .htaccess as discussed in the following sections.
Enable rewrites and .htaccess for Apache 2.4
Use this section to enable Apache 2.4 rewrites and specify a setting for the distributed configuration file, .htaccess
Magento uses server rewrites and .htaccess to provide directory-level instructions for Apache.
Failure to enable these settings typically results in no styles displaying on your storefront or Admin.
1. Enable the Apache rewrite module:
a2enmod rewrite

To enable Magento to use the distributed .htaccess configuration file, see the guidelines in the Apache 2.4 documentation.
Note that in Apache 2.4, the server’s default site configuration file is /etc/apache2/sites-available/000-default.conf.
For example, you can add the following to the end of 000-default.conf:
<Directory "/var/www/html">
    AllowOverride All
</Directory>

•  In some cases, additional parameters might be required. For more information, see the Apache 2.4 documentation.
•  If you changed Apache settings, restart Apache:
service apache2 restart

If you upgraded from an earlier Apache version, first look for <Directory "/var/www/html"> or <Directory "/var/www"> in 000-default.conf.
You must change the value of AllowOverride in the directive for the directory to which you expect to install the Magento software. For example, to install in the web server docroot, edit the directive in <Directory /var/www>.

 Database
-- MySQL 8.0 or greater
-- MariaDB 10.4 Magento Commerce Cloud projects

 PHP
-- 7.4.0 or greater(it may work with 7.3 but not fully tested)

sudo apt install php7.4

Step 1: Add PHP PPA Repository
We’ll add ppa:ondrej/php PPA repository which has the latest build packages of PHP.
sudo apt-get update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Step 2: Install PHP 7.4 on Ubuntu 18.04/19.04/16.04
Install PHP 7.4 on Ubuntu 18.04/19.04/16.04 using the command:
sudo apt -y install php7.4

sudo apt-get install -y php7.4-bcmath php7.4-ctype php7.4-curl php7.4-dom  php7.4-gd  php7.4-hash  php7.4-iconv  php7.4-intl  php7.4-mbstring  php7.4-openssl  php7.4-pdo_mysql  php7.4-simplexml  php7.4-soap  php7.4-xsl  php7.4-zip  php7.4-libxml
I am going to assume that you have PHP 7
1. If it isn't already, install php7.4-mysql:
sudo apt-get install php7.4-mysql
2. It is possible that it was already installed but the pdo_mysql module wasn't enabled. Either way, enable pdo_mysql:
sudo phpenmod pdo_mysql
3. Then just restart Apache:
sudo service apache2 restart
Hope it helps!

In the command line, type:
php -m

to see the list of installed modules
 Required PHP extensions
-- bcmath
-- ctype
-- curl
-- dom
-- gd
-- hash
-- iconv
-- intl
-- mbstring
-- openssl
-- pdo_mysql
-- simplexml
-- soap
-- xsl
-- zip
-- libxml
 Elasticsearch
-- Magento supports Elasticsearch 7.6.x or greater

 Mail server
-- Mail Transfer Agent (MTA) or an SMTP server

 Technologies Magento can use (Extra)
-- Redis version 5.0 is recommended and used in testing for page caching and session storage
-- Varnish version 6.x (tested with 6.3.1)
-- RabbitMQ 3.8.x

 Check Version of required setup before Installation:

 check composer version : composer

 check php version : php -v

 check mysql version    : mysql -V

 Check Elasticsearch Version : curl -XGET 'http://localhost:9200'


Steps on How to Install Magento 2.4.0 with Composer

So before Start create the folder as the given directory

Path : /var/www/html/magento240

1. Install Composer

sudo curl -sS https://getcomposer.org/installer | php
1.1 Make Composer Globally Available

sudo mv composer.phar /usr/local/bin/composer


2. Download magento2.4.0 file:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition

3.Set Up Permissions :
sudo chmod -R 777 ./

4. Create The Database

echo "CREATE DATABASE magento" | mysql -u root -p

4. Install Magento 2 :


sudo chown -R www-data:www-data /var/www/html/magento/ 
sudo chmod 777 -R var
sudo chmod 777 -R generated
sudo chmod 777 -R app/etc
sudo chmod 777 -R  /var/www/html/magento/ pub/media
sudo chmod 777 -R  /var/www/html/magento/ pub/static
sudo rm -rf var/cache/* var/page_cache/* var/generation/*

and

php bin/magento setup:di:compile;


php bin/magento setup:install --base-url="http://<domainname>/ " --db-host="localhost" --db-name="magento" --db-user="magento" --db-password="magento" --admin-firstname="First name" --admin-lastname="Lastname" --admin-email="user@email.com" --admin-user="admin" --admin-password="<password>" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin" --cleanup-database

Note: If you get a memory error message, run the following command.

sudo php -dmemory_limit=-1 bin/magento sampledata:deploy

9. After successfully installing Magento 2 sample data, run the following commands one by one.

    php bin/magento setup:upgrade
    php bin/magento setup:di:compile
    php bin/magento setup:static-content:deploy -f

You can change above installation detail as per your requirement.

6.Set Up Permissions :
sudo chmod -R 777 ./


7. Final, run all below command

sudo php -dmemory_limit=-1 bin/magento setup:upgrade
sudo php -dmemory_limit=-1 bin/magento setup:static-content:deploy -f
sudo php -dmemory_limit=-1 bin/magento indexer:reindex
sudo php -dmemory_limit=-1 bin/magento cache:clean
sudo php -dmemory_limit=-1 bin/magento cache:flush 

sudo chmod -R 777 ./

========================================================================TrTrouble Shooting:
Open terminal.
- Go on own Magento project directory.
Ex. I am using the lamp server in the localhost so my path is var/www/Html/magento
where magento is my Magento project directory.
- Type a command "cd /var/www/Html/magento" and press enter button.
- Currently, my current terminal directory is magento.
- Run the command "chmod -R 777 var/* generated/* pub/static/"
- If you will use ubuntu OS so please run the command "sudo chmod -R 777 var/* generated/* pub/static/".
 
Magento 2 offers a feature of static content signing to invalidate the browser cache for static resources. To do so, it adds a deployment version to the URL of the static files.

However, these files’ URLs contain the deployed version due to which 404 error occurs.

The solution is to remove version number in file paths in Magento 2 and there is method given below for the same.

Method: Run the below commands
insert into core_config_data (config_id, scope, scope_id, path, value) values (null, 'default', 0, 'dev/static/sign', 0);
Now, run the below commands
php bin/magento setup:static-content:deploy -f
sudo chmod 777 -R /var/www/html/magento

php bin/magento config:set dev/static/sign 0
php bin/magento cache:clean
php bin/magento cache:flush

Try the above method to disable static content signing in Magento 2.

sudo chmod -R 777 /var/www/html/magento/

sudo a2enmod rewrite

sudo service apache2 restart


open the terminal and navigate to magento web root
 $ cd /var/www/html/magento 
Step 1.
$ php bin/magento setup:static-content:deploy
Step 2.
$ php bin/magento indexer:reindex
Step 3.
make sure apache “rewrite_module” is enable and then restart the server
$ sudo a2enmod rewrite && sudo service apache2 restart
Step 4.
$ sudo chown -R www-data:www-data /var/www/html/magento
Step 5.
 $ sudo chmod -R 777 /var/www/html/magento/
Step 6.
delete cache folder under var/cache


=====================================

Pages 404 not found error also admin panel not accessible.
Put .htaccess on root of magento installation folder


Admin panel shows but error of 2 factor auth: disable it as per below cmd

bin/magento mo:di Magento_TwoFactorAuth

Cache cleared successfully.
Generated classes cleared successfully. Please run the 'setup:di:compile' command to generate classes.
Info: Some modules might require static view files to be cleared. To do this, run 'module:disable' with the --clear-static-content option to clear them.
======================================

Sample data installation:

sudo php bin/magento sampledata:deploy

(for multiple file or network stream failure try again, it is simple network issue)
If you’re installing sample data after installing Magento, you must also run the following command to update the database and schema in the <magento_root> folder:
php bin/magento setup:upgrade

You are required to authenticate to complete the action.