Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

Script: How to Install LEMP Stack on Ubuntu 20.04

October 27, 2022
in Blog, Linux
0
ADVERTISEMENT

Table of Contents

This bash script will install LEMP stack on your Ubuntu 20 LTS and configure it to maximize its performance of website serving.

Features

  • All-in-one one “click” installation of the LEMP environment.
  • Nginx will be installed with the ability to dynamically load or disable any preloaded module.
  • OPcache is enabled and configured for PHP-FPM.
Note Note: This script utilises root user privileges. If you run it from another user you need to add this user to sudoers group and prepend sudo to all commands in the script.

Before you begin, let’s take a look this bash script.

Usage

1. SSH into your Ubuntu Linux server.

2. Run the following commands at once to install wget, download the script, make it executable then execute it.

sudo apt install -y wget
sudo wget "https://filedn.com/lOX1R8Sv7vhpEG9Q77kMbn0/scripts/debian/install_lemp_ubuntu20.sh"
sudo chmod +x "install_lemp_ubuntu20.sh"
sudo sed -i 's/\r//' "install_lemp_ubuntu20.sh"
sudo /bin/bash "install_lemp_ubuntu20.sh"

Verification

Once done, you can verify the installation with the info.php file or using the following commands:

# nginx -v
nginx version: nginx/1.18.0 (Ubuntu)

# php -v
PHP 7.4.3 (cli) (built: Aug 17 2022 13:29:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

# mariadb -V
mariadb  Ver 15.1 Distrib 10.3.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Or you can type the IP address of your Ubuntu server in a browser address bar to access the default welcome page.

Bg2200

Removal

You can remove the downloaded script from your Linux server when the LEMP is installed.

# ls -l
-rwxr-xr-x 1 root root 1987 Oct 27 01:32 install_lemp_ubuntu20.sh
drwx------ 3 root root 4096 Oct 25 13:01 snap
rm -f "install_lemp_ubuntu20.sh"

Manually

If you don’t want to download the script from the internet, you can create a script then run it manually on your server.

sudo nano installer.sh
chmod +x installer.sh
./installer.sh

Copy then paste all below lines into the installer.sh file that you have created.

#/bin/sh
###Update Software Packages
sudo apt -y update && sudo apt -y upgrade

###Install Nginx Web Server
sudo apt install nginx -y
sudo systemctl enable nginx && sudo systemctl start nginx
sudo chown www-data:www-data /usr/share/nginx/html -R

#### Install Packages for MariaDB
sudo apt -y install nginx mariadb-server mariadb-client
sudo systemctl enable mariadb && sudo systemctl start mariadb
sudo mysql_secure_installation

#### Open firewall port for http/https
sudo ufw allow http && sudo ufw allow https

####Install PHP and increase file size
sudo apt -y install php7.4 php7.4-fpm php7.4-mysql php7.4-readline 
sudo apt -y install php7.4-cli php7.4-common php7.4-json php7.4-opcache 
sudo apt -y install php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl
systemctl enable php7.4-fpm && sudo systemctl start php7.4-fpm

####Download and extract latest WordPress Package
sudo rm /etc/nginx/sites-enabled/default

####Create a Nginx Server Block
cat << EOF >> /etc/nginx/conf.d/default.conf
# BEGIN
server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /usr/share/nginx/html/;
  index index.php index.html index.htm index.nginx-debian.html;

  location / {
    try_files \$uri \$uri/ /index.php;
  }

  location ~ \.php\$ {
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

 # A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)\$ {
       access_log        off;
       log_not_found     off;
       expires           360d;
  }

  # disable access to hidden files
  location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }
}
# END
EOF

#### Restart all services
systemctl restart nginx && systemctl restart php7.4-fpm && systemctl restart mariadb.service
systemctl --type=service | grep 'nginx\|mariadb\|php'
ADVERTISEMENT
5/5 - (1 vote)
Previous Post

How to Disable SELinux on CentOS 7 | Turn Off SELinux in CentOS 7

Next Post

How to Execute a Bash Script From an URL on Internet

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory