//Install the apt-transport-https package because the ElasticSearch repository uses
HTTPS protocol.
sudo apt-get install -y apt-transport-https
//Add the ElasticSearch repository.
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg]
https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee
/etc/apt/sources.list.d/elastic-7.x.list
//Import ElasticSearch GPG public key.
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor
-o /usr/share/keyrings/elasticsearch-keyring.gpg
//Update repository index and install ElasticSearch.
sudo apt update
sudo apt install -y elasticsearch default-jre-headless
//Then start ElasticSearch
sudo systemctl enable --now elasticsearch
//Check the status.
systemctl status elasticsearch
sudo nano /etc/elasticsearch/jvm.options.d/memory.options
//Add the following two lines in this file.
-Xms1g
-Xmx1g
//This means the Java virtual machine used by ElasticSearch will use 1G RAM. Note
that there should not be any space at the beginning of each line. Restart
ElasticSearch for the change to take effect.
sudo systemctl restart elasticsearch
//Run the following command to test if ElasticSearch is working.
curl http://localhost:9200
//Use the commands below to install Composer.
$ curl -sS https://getcomposer.org/installer -o composer-setup.php
$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
//You have successfully installed Composer on the system. It is available for
global use as we have stored it to /usr/local/bin/.
//Check the Composer version with the following command -
$ composer -V
//By default PHP 8.1 is not available in Ubuntu 20.04. Use the command below to add
a repository for it.
sudo apt install software-properties-common && sudo add-apt-repository
ppa:ondrej/php -y
sudo apt update
//Magento 2.4.4 is fully compatible with PHP 8.1.
//Run the following command to install the latest stable version of PHP 8.1 and all
its modules.
$ sudo apt install php8.1-
{bcmath,common,curl,fpm,gd,intl,mbstring,mysql,soap,xml,xsl,zip,cli}
//You can now increase some PHP variable values to meet Magento’s minimum
requirements.
$ sudo sed -i "s/memory_limit = .*/memory_limit = 768M/" /etc/php/8.1/fpm/php.ini
$ sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 128M/"
/etc/php/8.1/fpm/php.ini
$ sudo sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/"
/etc/php/8.1/fpm/php.ini
$ sudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/"
/etc/php/8.1/fpm/php.ini
//install mysql
sudo apt install mysql-server-8.0
sudo systemctl enable --now mysql
CREATE DATABASE magento;
CREATE USER 'magento'@'localhost' IDENTIFIED BY 'magento_password';
GRANT ALL PRIVILEGES ON magento.* to 'magento'@'localhost';
FLUSH PRIVILEGES;
EXIT
//setup nginx
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
cd /etc/nginx/sites-available
nano magento.conf
upstream fastcgi_backend {
server unix:/run/php/php8.1-fpm.sock;
}
server {
server_name magento.local.com;
listen 80;
set $MAGE_ROOT /var/www/html/ecommerce-project;
set $MAGE_MODE developer; # or production
access_log /var/log/nginx/magento2-access.log;
error_log /var/log/nginx/magento2-error.log;
include /var/www/html/ecommerce-project/nginx.conf.sample;
}
cd ../sites-enabled/
sudo ln -s ../sites-available/magento.conf ./
ls -l
sudo service nginx configtest # make sure the config is good before reloading!
sudo service nginx reload
//them domain
sudo nano /etc/hosts
127.0.0.1 magento.local.com
//build magentocd /
cd to project
composer install
php bin/magento setup:install \
--base-url=http://magento.local.com/ \
--db-host=localhost \
--db-name=magento \
--db-user=magento \
--db-password=magento \
--admin-firstname=admin \
--admin-lastname=admin \
--admin-email=admin@admin.com \
--admin-user=admin \
--admin-password=admin@123321 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 \
--search-engine=elasticsearch7 \
--elasticsearch-port=9200\
//chay sau khi build
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento indexer:reindex
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
sudo chmod -R 777 var/ generated/ pub/
//tat 2-auth
php bin/magento module:disable Magento_TwoFactorAuth
//them sample data
cd /var/www/html
git clone https://github.com/magento/magento2-sample-data.git --branch 2.4.5
php -f /var/www/html/magento2-sample-data/dev/tools/build-sample-data.php -- --ce-
source="/var/www/html/ecommerce-project"
//chay sau khi them sample data
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
//connect mysql
nano /etc/mysql/mysql.conf.d/mysqld.cnf
comment bind_address
//fix loi magento
//loi nginx
sudo fuser -k 80/tcp
sudo fuser -k 443/tcp
then
sudo -H apt-get purge nginx-common nginx-full
sudo -H apt-get install nginx-common nginx-full
sudo systemctl restart nginx