LNMP, CentOS8 + PHP8 + MySQL8

发布者:站点默认
2022/07/11 浏览数(563) 分类:CentOS/RockyLinux, MySQL/MariaDB, Nginx, PHP LNMP, CentOS8 + PHP8 + MySQL8已关闭评论

启用防火墙

systemctl start firewalld
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
firewall-cmd --remove-port=3306/tcp --permanent
firewall-cmd --reload

启用交换空间 swap 分区

dd if=/dev/zero of=/swapfile bs=1024k count=8192
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab

软件源

官方在2021年12月31日停止了 CentOS8 的源服务
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

~/.inputrc

"\e[A": history-search-backward                                                                                              
"\e[B": history-search-forward
"\e[1;2C": forward-word
"\e[1;2D": backward-word
set show-all-if-ambiguous on
set completion-ignore-case on

~/.bashrc

alias vi='vim'
alias bye='exit'
PS1='\[\e[1;37m\][\u@\h \W]\$ \[\e[0m\]'

~/.vimrc

syntax on
filetype on
inoremap <f5> <c-r>=strftime("%Y-%m-%d %T")<cr>
let &termencoding=&encoding
set fileencodings=utf-8,gbk
set nocompatible
set number
set history=1000
set background=dark
set tabstop=2
set shiftwidth=2
set showmatch
set vb t_vb=
set ruler
set nohls
set incsearch
set nowrap
set cursorline
set scrolloff=5
set laststatus=2

防止 SSH 超时

/etc/ssh/sshd_config
ClientAliveInterval 50
ClientAliveCountMax 10
systemctl reload sshd

配置 Nginx 源

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

配置 MySQL 源

https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html
rpm -Uvh https://repo.mysql.com/mysql80-community-release-el8-4.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

配置 php 源

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-8.rpm
# rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
# rpm -ivh remi-release-8.rpm --nodeps --force
rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module list php # 可安装的 php 版本列表,
dnf module reset php && dnf module enable php:remi-8.1

安装依赖

dnf install -y epel-release dnf-utils

安装

dnf install \
  nginx \
  mysql-server \
  php \
  php-mysqlnd \
  php-fpm \
  php-gd \
  php-mbstring \
  php-curl \
  php-pdo \
  php-json \
  php-mcrypt \
  php-bcmath \
  php-xml \
  php-zip

MySQL

/etc/my.conf 或 /etc/my.cnf.d/mysql-server.cnf
[mysqld]
datadir=/data/db

# MySQL 启动后会生成一个临时密码,在 /var/log/mysqld.log 里找
mysql_secure_installation

PHP

vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen.acl_users = apache,nginx
# acl_users 没有 nginx 会出现「connect() to unix:/run/php-fpm/www.sock failed (13: Permission denied)」 

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

配置

systemctl start nginx
systemctl start php-fpm.service
systemctl start mysqld.service

systemctl enable nginx
systemctl enable php-fpm.service
systemctl enable mysqld.service
点击返回顶部
  1. 留言
  2. 联系方式