Skip to content

Instantly share code, notes, and snippets.

@cras4202tw cras4202tw/CentOS 8 LNMP
Last active Sep 25, 2019

Embed
What would you like to do?
CentOS 8 LNMP

CentOS 8 + Mysql 8 + PHP 7.3 + Nginx Mainline

#!/bin/bash
clear
setenforce 0
sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
sed -i 's@LANG=.*$@LANG="en_US.UTF-8"@g' /etc/locale.conf
cat > /etc/yum.repos.d/nginx.repo << EOF
[nginx]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/8/\$basearch/
gpgcheck=0
enabled=1
EOF
dnf install wget epel-release -y
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
dnf install @mysql:8.0 -y
dnf install yum-utils -y
dnf module install php:remi-7.3 -y
dnf update -y
wget http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/libmcrypt-2.5.8-4.el7.art.x86_64.rpm
dnf install libmcrypt-2.5.8-4.el7.art.x86_64.rpm -y
dnf install nginx php-bcmath net-snmp php php-cli php-fpm php-gd php-curl php-mbstring php-mcrypt php-odbc php-mysql php-xmlrpc php-xml php-pdo php-opcache python2-pip -y
systemctl enable php-fpm
systemctl enable nginx
systemctl enable snmpd
systemctl enable mysqld
sed -i 's@^memory_limit.*@memory_limit = 256M@' /etc/php.ini
sed -i 's@^;cgi.fix_pathinfo.*@cgi.fix_pathinfo=0@' /etc/php.ini
sed -i 's@^;date.timezone.*@date.timezone = Asia/Taipei@' /etc/php.ini
sed -i 's@^post_max_size.*@post_max_size = 10M@' /etc/php.ini
sed -i 's@^upload_max_filesize.*@upload_max_filesize = 10M@' /etc/php.ini
sed -i 's@^user.*@user = nginx@' /etc/php-fpm.d/www.conf
sed -i 's/^group =.*$/group = nginx/' /etc/php-fpm.d/www.conf
sed -i 's/127.0.0.1:9000/\/var\/run\/php-fpm\/www.sock/g' /etc/php-fpm.d/www.conf
sed -i 's@^;listen.owner.*@listen.owner = nginx@' /etc/php-fpm.d/www.conf
sed -i 's@^;listen.group.*@listen.group = nginx@' /etc/php-fpm.d/www.conf
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Taipei /etc/localtime
rm -rf /etc/nginx/nginx.conf
cat > /etc/nginx/nginx.conf << EOF
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
worker_rlimit_nofile 51200;
include /usr/share/nginx/modules/*.conf;
events {
use epoll;
worker_connections 51200;
multi_accept on;
}
http {
access_log /var/log/nginx/access.log main;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /nginx-status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 10.0.0.0/8;
deny all;
}
location ~ [^/]\.php(/|$) {
try_files \$uri =404;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
}
EOF
rm -rf /etc/nginx/conf.d/php-fpm.conf
rm -rf /etc/nginx/default.d/php.conf
mkdir /var/run/php-fpm
chown -R nginx.nginx /var/run/php-fpm
chown -R nginx.nginx /var/lib/php/session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.