Prerequisites
Already Installed Ubuntu 18.04
Easy Installing nginx from repo
sudo apt update && sudo apt install nginx
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
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
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 php7.3-fpm
from source (Precompiled)
Install mysql 8 fro 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
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