• Skip to main content
  • Skip to primary sidebar
  • Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / nginx server tutorials (installation, configuration, performance tuning, security) / install LEMP Stack on 22.04 LTS Nginx MySQL PHP fpm #wordpress #digital ocean

install LEMP Stack on 22.04 LTS Nginx MySQL PHP fpm #wordpress #digital ocean

how to install lemp stack on ubuntu 18.04 20.4 and debian 9, digitalocean google cloud for wordpress.

Prerequisites

Already Installed Ubuntu 18.04  12.04 22.04 LTS

Table of Contents

Toggle
  • 1. Installing Lemp Stack easy method from linux repository
    • a. Easy Installing nginx from repo 
    • Installing MySQL
    • Installing Php or Php -fpm
  • Semi Advanced LEMP Installation (not recommended)
    •  Installing Nginx From Source for latest 
  • 3.Installing PHP fpm 8
  • Install mysql 8  from mysql
    • Sample Nginx Server Block 
  • check lemp stack version
    • nginx version
    • php version
    • linux distribution check lsb_release -a
    • mysql -V mysql version

1. Installing Lemp Stack easy method from linux repository

 

a. Easy Installing nginx from repo 

 

(i)sudo apt update && sudo apt upgrade

(II)  sudo apt-get install nginx

 

Optional: systemctl status nginx  (my case it worked always)

visit ipadress to see nginx page

most cases Port 80,443,22 will not block by ufw firewall or iptables.

(b) Installing Mysql 8 from ubuntu repository

 apt install mysql-server

follow the instructions

check installation status

sudo service mysql status

sudo mysql_secure_installation  and setpassword if not while installation
if no password login as sudo mysql and set password
change some rules.

(C) Installing Php fm 8 or 7.4 from ubuntu repository

apt install php-fpm  or specfic version

sudo apt-get install php7.4-fpm

apt-get install php7.4 -y

 

sudo apt install php8.1-fpm

and install required php extensions for WordPress etc

sudo apt install php8.1-curl php8.1-zip mcrypt php8.1-gd php8.1-mbstring php8.1-xmlrpc php8.1-xml php8.1-intl php8.1-soap php8.1-imagick

 

sudo service php8.1-fpm status

Detailed guide on installing php fpm on ubuntu

php ini configuration and  php fpm pool configuration

One command installation

sudo apt install nginx mysql-server php-fpm

also follow migrate linux server

Installing MySQL

 

Run the following commands

from Repo  (version may be 5.7 or 5.6)

sudo apt install mysql-server

 

Part 2: securing installation

sudo mysql_secure_installation

VALIDATE PASSWORD PLUGIN

password strength will be high.

Set: Root password, remove anonymous users etc(security hardening must for mysql installation.

Upgrading Mysql databases

Optional (use with caution)

mysql_upgrade u – root -p

if your migrating from old version to new ort if mysql log asks explicitly)

that’s all you done with mysql (performance tuning you need to visit this page)

 

Installing Php or Php -fpm

from repo

sudo apt install php-fpm

or

 

Php extensions for wordpress

sudo apt-get install php7.3-mysql php7.3-curl php7.3-json php7.3-cgi php7.3-xsl

or php fpm configuration with nginx and performance tuning please php installation page.

 

 

 

Semi Advanced LEMP Installation (not recommended)

 Installing Nginx From Source for latest 

visit http://nginx.org/en/download.html  scroll down to below prebuilt packages.

http://nginx.org/en/linux_packages.html

Select Linux distributions RHEL/Centos/ Ubuntu / debian etc

 

for Ubuntu

Ubuntu

Version Supported Platforms
14.04 “trusty” x86_64, i386, aarch64/arm64
16.04 “xenial” x86_64, i386, ppc64el, aarch64/arm64
18.04 “bionic” x86_64, aarch64/arm64
18.10 “cosmic” x86_64

 

 

1st step

Adding Repository to APT

To set up the apt repository for stable nginx packages, run the following command:

echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list
or

If you would like to use mainline nginx packages, run the following command instead:

echo "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

2nd step (maybe optional if ubuntu asks)

Next, import an official nginx signing key so apt could verify the packages authenticity:

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Verify that you now have the proper key:

sudo apt-key fingerprint ABF5BD827BD9BF62

The output should contain the full fingerprint 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 as follows:

pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
      573B FD6B 3D8F BC64 1079  A6AB ABF5 BD82 7BD9 BF62
uid   [ unknown] nginx signing key <signing-key@nginx.com>

3rd & Final Step

To install nginx, 

sudo apt update && sudo apt install nginx

 

3.Installing PHP fpm 8

 

or from launchpad repo for specific version

https://launchpad.net/~ondrej/+archive/ubuntu/php

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php8.0-fpm

sudo apt-get install -y php8.0-fpm

sudo systemctl status php8.0-fpm

install required php extensions for wordpress 8

sudo apt install php8.0-mysql php8.0-curl php8.0-mbstring php8.0-opcache php8.0-zip php8.0-xml php8.0-gd

 

from source (Precompiled)

Install mysql 8  from mysql

Download MySQL APT repository

Ste p1:

Go to https://dev.mysql.com/downloads/repo/apt/

(mysql-apt-config_0.8.12-1_all.deb)

Wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb

Step 2

sudo dpkg -i mysql-apt-config_w.x.y-z_all.deb

ex: dpkg -i mysql-apt-config_0.8.12-1_all.deb

Step 3:

sudo apt-get update && sudo apt-get install mysql-server

 

Part 2: securing installation

 

root@ubuntu:~# sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: n
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

… skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
– Dropping test database…
Success.

– Removing privileges on test database…
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!
root@ubuntu:~#

sudo mysql_secure_installation

 

Sample Nginx Server Block 

server {
listen 80;
root /var/www/html;

#remove below line add this to nginx.conf (to reduce code on every block)
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com;

location / {

#for wordpress not work replace with  try_files $uri $uri/ /index.php?$args;
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

# remove locat .ht block i you are not using apache2

location ~ /\.ht {
deny all;
}
}

To start services

sudo systemctl start nginx

sudo systemctl stop nginx

sudo systemctl restart nginx

sudo systemctl reload nginx  (reload config files without restarting)

sudo systemctl status nginx (checking status whether it running or not)

 

Same applies php & Mysql

sudo systemctl restart php7.3-fpm

sudo systemctl restart mysql

 

Possible errors

Database not connected

 

check lemp stack version

nginx version

root@instance-1:~# nginx -v
nginx version: nginx/1.19.6
nginx version: nginx/1.19.9

php version

php -v
root@instance-1:~# php -v

PHP 7.4.14 (cli) (built: Jan 13 2021 08:04:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.14, Copyright (c), by Zend Technologies
PHP 8.0.3 (cli) (built: Mar 5 2021 07:53:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
with Zend OPcache v8.0.3, Copyright (c), by Zend Technologies

linux distribution check lsb_release -a

root@instance-1:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal

mysql -V mysql version

root@instance-1:~# mysql -V
mysql Ver 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

 

Nex thing Follow linux Server Migration or

wordpress lemp digitalocean

install lemp debian 9

Primary Sidebar

nginx server tutorials (installation, configuration, performance tuning, security)

  • Letsencrypt SSL Installation on apache/Nginx ubuntu / debian wordpress
  • fix error 520 522 524 on cloudflare wordpress godaddy nginx etc
  • nginx fastcgi cache wordpress how to configure
  • install LEMP Stack on 22.04 LTS Nginx MySQL PHP fpm #wordpress #digital ocean
  • Apache vs nginx (connection handling, modules, memory usage)
  • Pagespeed module install, configure, monitor, errors ft nginx &apache
  • nginx errors (504,502, 413, unable to start, syntax errors)
  • nginx conf explained best config file performance tuning tips nginx.conf location errors tutorial
  • use nginx as reverse proxy and load balancer for apache wordpress
  • nginx rewrite rules with examples 301 redirection
  • nginx modules list (enable, disable, upgrade, install dynamic module)
  • php fpm pool manager configuration settings based on server spike high cpu wordpress
  • php fpm restart nginx ubuntu enable status page, monitor etc
  • what is TTFB & how to Reduce it (server response time) Google pagespeed
  • letsencrypt install configure on ubuntu / debian nginx
  • Top 10 tips to improve nginx server security
  • nginx performance tuning connections, buffers file descriptors
  • enable brotli compression nginx brotli vs gzip
  • nginx installation on ubuntu 20.04 LTS
  • monitor nginx request with nginx status amplify datadog new relic
  • SSL faster reduce TLS hand shake improve https performance
  • nginx rate limiting explained by location time specific url
  • datadog nginx integration installation process
  • newrelic nginx integration process and errors fix and metrics
  • php fpm seems busy fixed warning and max children reached to handle max connections / requests
  • Php fpm configuration for 1000 concurrent connections server busy max children reached
  • php fpm ondemand vs dynamic vs Static (the dynamic pool problem)
  • nginx upstream response is buffered to a temporary file
  • php fpm install ubuntu 20.04 nginx
  • install phpmyadmin ubuntu nginx 22.04
  • upgrade php fpm ubuntu nginx 7.4 to 8.2
  • nginx add last modified header (remove, php wordpress)
  • php fpm dynamic pool manager settings
  • nginx fastcgi cache purge
  • nginx open file limit connections ulimits sysctl
  • php fpm high cpu usage WordPress 4 solutions nay work for you
  • nginx buffer size for wordpress
  • Cloudflare error code 524 nginx a timeout error occured
  • server configuration for 1000 concurrent users

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy