Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • VirtualBox
  • VMware
  • Windows
  • 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
  • VirtualBox
  • VMware
  • Windows
  • 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 CentOS 8/RHEL 8

October 28, 2022
in Blog, Linux
0
ADVERTISEMENT

Table of Contents

The LEMP software stack is a group of software that can be used to serve dynamic web pages and web applications written in PHP. This bash script will install LEMP stack on your CentOS 8 and configure it to maximize its performance of website serving.

# cat /etc/os-release
NAME="CentOS Stream"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"

Before you begin, let’s take a look this bash script. This script will install and configure the following packages:

  • PHP 7.4 and Nginx
  • MariaDB 10.8

Usage

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.

1. SSH into your CentOS 8 Linux server.

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

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

Verification

Once done, you can verify the installation with the info.php file or using the following commands to check the version of PHP, Nginx and MariaDB.

# 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

Alternatively, you can type the IP address of your CentOS 8 in a browser address bar to access the default welcome page.

Bg2208

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_centos8.sh
drwx------ 3 root root 4096 Oct 25 13:01 snap
rm -f "install_lemp_centos8.sh"

The Nginx server block needs the following example below for Nginx to process the PHP files. Below is an example of all server {} blocks that process PHP files that need the location ~ .php$ added.

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index   index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

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 vi 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 the CentOS 8 System
sudo sed -i 's/best=True/best=False/g' /etc/yum.conf
sudo sed -i 's/best=True/best=False/g' /etc/dnf/dnf.conf
sudo dnf -y update
sudo dnf -y install wget

###Configure SELinux and Firewall
sudo sed -i 's/enforcing/disabled/g' /etc/selinux/config
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

####Install PHP7.4 and Nginx
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf -y install dnf-utils
sudo dnf -y module reset php
sudo dnf -y module install php:remi-7.4

###Install PHP 7.4 Extensions
sudo dnf update -y
sudo dnf -y install nginx php php-cli
sudo dnf -y install php-fpm php-gd php-json php-mbstring php-mysqlnd php-xml php-xmlrpc php-opcache
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 64M/g' /etc/php.ini
sudo sed -i 's/post_max_size = 8M/post_max_size = 64M/g' /etc/php.ini
systemctl restart php-fpm && systemctl enable php-fpm
systemctl restart nginx && systemctl enable nginx

###Configure php-fpm
sudo sed -i 's/user = apache/user = nginx/g' /etc/php-fpm.d/www.conf
sudo sed -i 's/group = apache/group = nginx/g' /etc/php-fpm.d/www.conf
sudo sed -i 's/listen = 127.0.0.1:9000/listen =\/run\/php-fpm\/www.sock/g' /etc/php-fpm.d/www.conf
sudo sed -i 's/;listen.owner = nobody/listen.owner = nginx/g' /etc/php-fpm.d/www.conf
sudo sed -i 's/;listen.group = nobody/listen.group = nginx/g' /etc/php-fpm.d/www.conf

#### Install Packages for MariaDB
sudo curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.8
sudo dnf clean all
sudo dnf -y install MariaDB-server MariaDB-client MariaDB-backup
sudo systemctl enable mariadb && sudo systemctl start mariadb
sudo mariadb-secure-installation

#### Restart all services
systemctl restart nginx && systemctl restart php-fpm && systemctl restart mariadb.service
ADVERTISEMENT
5/5 - (1 vote)
Previous Post

How to Get the List of Services on Linux

Next Post

How to Install VMware Tools on CentOS 7 Virtual Machine

Related Posts

Ftr21

Export Microsoft 365 Disabled Users Report Using Microsoft Graph

December 7, 2023
Ftr22

Export List of Users with Managers Name and UPN in Microsoft 365

December 7, 2023
Ftr38

How to Split an Email Addresses From @ with PowerShell

December 5, 2023
Ftr38

[WinForms] Creating GUIs in Windows PowerShell with WinForms

November 15, 2023
Ftr21

Converting DateTime Obtained from Microsoft Graph Call to PowerShell Date and Time Format

October 21, 2023
Ftr21

How to Get Microsoft 365 License Expiration Dates using Graph Api

December 7, 2023

Leave a Reply Cancel reply

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

Recent Posts

  • How to Enable Outlook Modern Authentication from Registry Setting
  • Export Microsoft 365 Disabled Users Report Using Microsoft Graph
  • Export List of Users with Managers Name and UPN in Microsoft 365

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 2023 © 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