Professional Documents
Culture Documents
How To Install Magento 2.4 With LEMP Stack On Ubuntu 20.04 - RoseHosting
How To Install Magento 2.4 With LEMP Stack On Ubuntu 20.04 - RoseHosting
04 - RoseHosting
Categories
Select Category
In this guide, we will show you how to install Magento 2.4 with LEMP stack on an
Ubuntu 20.04 VPS.
Installing Magento 2.4 with a LEMP Stack on Ubuntu 20.04 should take less than Buy a Managed VPS - 25% OFF
10 minutes to complete. Let’s get started with the tutorial.
Table of Contents
Prerequisites Managed NVMe VPSes
Getting Started
Install LEMP and Elasticsearch Managed NVMe Dedicated
Create a Database for Magento 2 Servers
Install Magento 2
Create an Nginx Con guration File
Install an SSL Certi cate
Install Cron Job
Prerequisites
An Ubuntu 20.04 VPS with root access enabled, or a user with sudo privileges
Search …
4GB of RAM or higher
Nginx
MariaDB 10.4
Elasticsearch 7.6.x because Magento 2.4 is tested with this version
How To Install Docker
PHP 7.4 with bcmath, ctype, curl, dom, gd, hash, iconv, intl, libxml, mbstring,
Compose on Debian 9
openssl, pdo_mysql, simplexml, soap, xsl and zip extensions enabled. Also, for
performance reasons it is a good idea to install and enable the opcache
extension. Stateful and Stateless
A valid domain name for accessing the Magento 2 website. Also, a valid SSL Horizontal Scaling for
certi cate is required for accessing the website using HTTPS. Cloud Environments
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 1/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
If you don’t have a LEMP stack set up (Nginx, MariaDB, PHP), no problem – we’ll be MySQL SHOW USERS:
covering how to install those in this tutorial as well. List All Users in a
MySQL Database
Getting Started
How to Fix WordPress
First, we’re going to need to log into our server using SSH. You can do that by
Error Missing MySQL
entering this command:
Extension Problem
Replace “root” with a user that has sudo privileges if necessary. Additionally, replace
“IP_Address” and “Port_Number” with your server’s respective IP address and SSH
port number.
Join our Blog
Once you are logged in, you should update all of your Ubuntu OS packages to their
Sign up and receive noti cations
latest available versions. as soon as new content is posted.
Once all of the OS packages are up-to-date, restart your server if required to apply
any new con guration changes.
Install Nginx
If there is an Apache web server installed on the server already, stop the Apache
service and disable it from starting on server boot:
Install MySQL
Next, we will install the MySQL database server, which will be used for storing the
data of our Magento website, such as the products, categories, customers, and
orders.
For the purposes of this tutorial, we will install and use MariaDB. To install the
MariaDB database server, enter the following commands:
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 2/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
Update your APT repositories so that the package lists get read.
apt update
Once MariaDB installed, enable the MariaDB service to start on server boot:
Install Elasticsearch
cd /opt
wget
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-
7.6.1-amd64.deb
dpkg -i elasticsearch-7.6.1-amd64.deb
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 3/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
add-apt-repository ppa:ondrej/php
Next, update the OS package list and install PHP 7.4 with the following command:
apt-get update
apt-get install php7.4
Install all of the required PHP extensions with the following command:
Once the PHP extensions have been installed on the server, install a few other OS
packages that are required for the Magento 2 installation:
nano /etc/php/7.4/fpm/php.ini
file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
zlib.output_compression = On
upload_max_filesize = 128M
max_execution_time = 600
max_input_time = 900
date.timezone = America/Chicago
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 4/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
mysql_secure_installation
Enter current password for root (enter for none): Press [Enter]
since no password is set by default
Set root password? [Y/n]: N (You can set a password if you like)
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
Next, we will create our MySQL user and database for our Magento 2 website. Log in
to your MySQL server with the following command and enter your MySQL root
password when prompted:
mysql -u root -p
To create a new database for our Magento 2 instance, run the following commands:
Make sure that you give your magento MariaDB user a real and strong password.
Install Magento 2
We can now proceed with the Magento 2 installation. At the time of writing this
article, the latest stable version of Magento is version 2.4.
First, go to the GitHub repository and download the latest version of Magento with
the following command:
mkdir -p /var/www/magento2/
cd /var/www/magento2/
git clone https://github.com/magento/magento2.git
/var/www/magento2/
Next, we will need to install Composer to install all necessary Magento components.
You can install Composer by just running the following command:
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 5/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
cd /var/www/magento2
composer install
bin/magento setup:install --base-url=http://yourdomain.com/ --db-
host=localhost --db-name=magentodb --db-user=magento --db-
password=strongPassword --admin-firstname=FirstName --admin-
lastname=LastName --admin-email=your@emailaddress.com --admin-
user=magentoadmin --admin-password=strong-password --language=en_US
--currency=USD --timezone=America/Chicago --use-rewrites=1
Remember the ‘Magento Admin URI’. You will need this info later as that’s the URL
that you’ll be using to log in to the Magento back-end.
Change the ownership of the magento2 directory to www-data with the following
command:
nano /etc/nginx/sites-available/magento2
upstream fastcgi_backend {
server unix:/run/php/php7.4-fpm.sock;
}
server {
server_name yourdomain.com;
listen 80;
set $MAGE_ROOT /var/www/magento2;
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/magento2/nginx.conf.sample;
}
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 6/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
Make sure that you set yourdomain.com to your registered domain name.
Remove the default Nginx con guration le, if is not being used:
rm -f /etc/nginx/sites-enabled/default
Enable the newly created Nginx con guration le, then test the Nginx con guration
and make sure that there are no errors:
ln -s /etc/nginx/sites-available/magento2 /etc/nginx/sites-
enabled/magento2
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Then install a new SSL certi cate for your domain name, making sure that
yourdomain.com is set to your registered domain name:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
1: No redirect - Make no further changes to the webserver
configuration.
2: Redirect - Make all requests redirect to secure HTTPS access.
Choose this for
new sites, or if you're confident your site works on HTTPS. You can
undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to
cancel): 2
Use the following Magento 2 CLI commands to update the Magento base-url and
the base-url-secure values:
cd /var/www/magento2/
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 7/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
nano /etc/nginx/sites-enabled/magento2
Replace:
With:
crontab -u www-data -e
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 8/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
We hope that this tutorial helped you install Magento 2 on your Ubuntu 20.04 VPS. If
it did, please consider sharing this post on social media with our share shortcuts, or
leave a comment below with any questions or suggestions that you might have.
Thank you.
Teddy
November 14, 2020 | Reply
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 9/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
admin
November 15, 2020 | Reply
Ateq
February 25, 2021 | Reply
Ra aele Filomena
March 21, 2021 | Reply
Ha zur
April 1, 2021 | Reply
admin
April 2, 2021 | Reply
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 10/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
Leave a Comment
Name *
Email *
Save my name, email, and website in this browser for the next time I comment.
× 7 = seven
Post Comment
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 11/12
4/17/2021 How to Install Magento 2.4 with LEMP Stack on Ubuntu 20.04 - RoseHosting
https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/ 12/12