Install Linux Centos 7, Nginx, MySQL, Postgres, PHP 8.0

Update LANG

Edit environtment vi /etc/environment add these lines…

LANG=en_US.utf-8
LC_ALL=en_US.utf-8

Update and upgrade Core

yum -y update
yum -y upgrade

Install NGINX

yum install epel-release
yum install nginx

Start NGINX and Enable Service

systemctl start nginx
systemctl enable nginx

Install PHP 8.0

Enable Remi Repo

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Check

yum --disablerepo="*" --enablerepo="remi-safe" list php[7-9][0-9].x86_64

Enable Remi php8.0

yum -y install yum-utils
yum-config-manager --enable remi-php80

Install PHP

yum -y install php php-fpm php-mysqlnd php-pgsql php-gd php-imagick php-json php-opcache php-mcrypt php-curl php-mongodb php-mbstring php-intl php-dom php-zip

Make sure the /var/lib/php directory has the correct ownership :

chown -R root:nginx /var/lib/php

Edit nano /etc/php-fpm.d/www.conf

user = nginx
group = nginx
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

Start and Enable php-fpm

systemctl start php-fpm
systemctl enable php-fpm

Create VirtualHost Default NGINX nano /etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  server_domain_or_IP;

    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
        root /usr/share/nginx/html;
    }

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

Check dan Restart Nginx

nginx -t
systemctl restart nginx

Testing PHP nano /usr/share/nginx/html/info.php

<?php
  echo phpinfo();
?>

Install Postgres (Latest Version)

rpm -Uvh https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum list postgresql*
yum -y install postgresql13-server postgresql13-contrib postgresql13

Init Postgres

/usr/pgsql-13/bin/postgresql-13-setup initdb

Start and Enable Postgres

systemctl start postgresql-13
systemctl enable postgresql-13

Edit pg_hba.conf

nano /var/lib/pgsql/13/data/pg_hba.conf

Replace ident to md5

host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

Create Database

su postgres
psql

CREATE DATABASE db_name;
CREATE ROLE username WITH PASSWORD 'password'
GRANT ALL PRIVILEGES ON DATABASE db_name TO username;
ALTER ROLE username WITH LOGIN;

Install MariaDB 10 (Centos 7 default using MariaDB 5)

First download and use the mariadb_repo_setup script to configure the MariaDB repositories for YUM

wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
./mariadb_repo_setup

then

yum install mariadb-server

Configuring and Securing MariaDB Server

systemctl start mariadb
systemctl enable mariadb
sudo mysql_secure_installation

Testing the Installation

mysqladmin -u root -p version

indicates the installation has been successful like this

mysqladmin  Ver 9.1 Distrib 10.5.8-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version		10.5.8-MariaDB
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/lib/mysql/mysql.sock
Uptime:			2 hours 50 min 24 sec

Threads: 2  Questions: 690  Slow queries: 0  Opens: 100  Open tables: 94  Queries per second avg: 0.067

Install phpMyAdmin

Download latest version

cd /tmp
wget https://files.phpmyadmin.net/phpMyAdmin/5.0.4/phpMyAdmin-5.0.4-all-languages.zip
unzip phpMyAdmin-5.0.4-all-languages.zip
mv phpMyAdmin-5.0.4-all-languages /usr/share

Update config virtualhost

nano /etc/nginx/conf.d/default.conf

Add this line

location /phpMyAdmin {
    root /usr/share/;
    index index.php index.html index.htm;
    
    location ~ ^/phpMyAdmin/(.+\.php)$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    
    location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
        root /usr/share/;
    }
}

location /phpmyadmin {
    rewrite ^/* /phpMyAdmin last;
}

Reload nginx

nginx -s reload

Install CSF & LFD

dependency

yum -y install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph dns-utils

now install CSF

cd /usr/src
rm -fv csf.tgz
wget https://download.configserver.com/csf.tgz
tar -xzf csf.tgz
cd csf
sh install.sh

Disable Firewall

systemctl stop firewalld
systemctl disable firewalld

Install Let’sencrypt

yum install certbot-nginx

Solving problem error nginx nginx open() failed (13: Permission denied)

Check selinux, you must disable selinux for solving this error

setenforce 0

if still error, do it step below. Check permission

sudo -u username stat /home/username/public_html
sudo -u nginx stat /home/username/public_html

Add username to group nginx

gpasswd -a nginx username

Change permission

chmod g+x /home && chmod g+x /home/username/public_html

Upgrade NGINX (if version nginx installed lower than current version)

Create nginx repo /etc/yum.repos.d/nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

then

yum update

if error after upgrade (module
"/usr/lib64/nginx/modules/ngx_http_image_filter_module.so" version
1016001 instead of 1018000 in
/usr/share/nginx/modules/mod-http-image-filter.conf:1
), do it this step

yum remove nginx-mod*
yum install nginx-module-*

Sam

Similar Posts