Centos 8安装LNMP(PHP-7.4.7 Nginx-1.18.0 MariaDB-10.4.13) - 开发说
当前位置: 主页 » Centos » Centos 8安装LNMP(PHP-7.4.7 Nginx-1.18.0 MariaDB-10.4.13)

Centos 8安装LNMP(PHP-7.4.7 Nginx-1.18.0 MariaDB-10.4.13)

      2020年06月14日   阅读 1,160 次     0 评论   Tags: · ·

以前写过一篇文章Centos7.7安装LNMP(PHP-7.4.5 Nginx-1.18.0 MariaDB-10.4.12),今天再写一篇如何在Centos8部署最新版的LNMP环境,Centos8部署LNMP相对比较容易。
Centos 8如何选择更快的软件源
在Centos 8 中部署LNMP环境并安装WordPress
在VirtualBox安装体验Centos Linux 8

1、安装依赖环境


1.1、安装EPEL源

[root@uscdn1 ~]# yum -y install epel-release.noarch

1.2、firewalld开放http和https端口

[root@uscdn1 ~]# firewall-cmd --zone=public --add-service=http --permanent
[root@uscdn1 ~]# firewall-cmd --zone=public --add-service=https --permanent
[root@uscdn1 ~]# firewall-cmd --reload


1.3、安装相关依赖包:

[root@uscdn1 ~]# yum -y install gcc gcc-c++ make cmake  perl autoconf automake libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel openssl openssl-devel pcre pcre-devel libtool  pcre-devel libaio-devel libaio bzip2-devel libcurl-devel gd-devel bison  openldap openldap-devel libicu-devel

1.4、更新系统

[root@uscdn1 ~]# yum -y update

1.5、设置系统时间
[root@uscdn1 ~]# timedatectl set-timezone Asia/Hong_Kong
[root@uscdn1 ~]# timedatectl

1.6、创建openladp库链接
[root@uscdn1 ~]# cp -frp /usr/lib64/libldap* /usr/lib/

2、添加nginx stable(稳定版或者开发板)源 ,在http://nginx.org/packages/centos/7/noarch/RPMS/ 查看最新库信息



2.1、添加nginx稳定版:
[root@uscdn1 ~]#  vi /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

2.1.1、添加nginx mainline(长期开发版)源

[root@uscdn1 ~]#  vi /etc/yum.repos.d/nginx.repo 

[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


2.2、安装nginx,nginx启动和自启动

[root@uscdn1 ~]# yum -y install nginx
[root@uscdn1 ~]# systemctl enable nginx.service 
[root@uscdn1 ~]# systemctl start nginx.service

nginx配置文件位置(配置文件都是一样的)
nginx主配置文件:/etc/nginx/nginx.conf
nginx默认配置文件目录:/etc/nginx/conf.d/
nginx默认站点主目录:/usr/share/nginx/html/
nginx默认日志目录:/var/log/nginx/

3、创建mariadb源,安装mariadb


[root@uscdn1 ~]# cat /etc/yum.repos.d/MariaDB.repo 
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1


3.1、安装mariadb

[root@uscdn1 ~]# yum install -y MariaDB-shared MariaDB-server MariaDB-client MariaDB MariaDB-devel 

启动和自启动
[root@uscdn1 ~]# systemctl enable mariadb.service
[root@uscdn1 ~]# systemctl start mariadb.service


初始化MySQL数据库并创建密码,创建wordpress库 create database wordpress charset=utf-8; 来存放wordpress的数据库文件。
[root@uscdn1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2021
Server version: 10.4.10-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'mysqlrootpwd';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'localhost' IDENTIFIED BY 'mysqlrootpwd';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysqlrootpwd';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'mysqlrootpwd';
MariaDB [(none)]> use mysql;
MariaDB [(none)]> select user,host,password from user;
MariaDB [(none)]> create database wordpress charset=utf-8;
MariaDB [(none)]> delete from user where password="";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

4、安装PHP-7.4.7



###安装PHP依赖包oniguruma
[root@uscdn1 ~]# dnf remove oniguruma
[root@uscdn1 ~]# wget https://github.com/kkos/oniguruma/archive/v6.9.5.tar.gz -O oniguruma-6.9.5.tar.gz
[root@uscdn1 ~]# tar xf oniguruma-6.9.5.tar.gz 
[root@uscdn1 ~]# cd oniguruma-6.9.5
[root@uscdn1 ~]# yum install autoconf automake libtool
[root@uscdn1 ~]# ./autogen.sh && ./configure --prefix=/usr
[root@uscdn1 ~]# make && make install

###安装php-7.4.7
[root@uscdn1 ~]# wget http://php.net/distributions/php-7.4.7.tar.gz
[root@uscdn1 ~]# tar xf php-7.4.7.tar.gz
[root@uscdn1 ~]# cd php-7.4.7
[root@uscdn1 ~]# vi config.nice 

#! /bin/sh
#
# Created by configure

'./configure' \
'--prefix=/usr/local/php' \
'--with-config-file-path=/usr/local/php/etc' \
'--enable-fpm' \
'--with-fpm-user=nobody' \
'--with-fpm-group=nobody' \
'--enable-mysqlnd' \
'--with-mysqli=mysqlnd' \
'--with-pdo-mysql=mysqlnd' \
'--enable-mysqlnd-compression-support' \
'--with-iconv-dir' \
'--with-freetype' \
'--with-jpeg' \
'--with-zlib' \
'--enable-xml' \
'--disable-rpath' \
'--enable-bcmath' \
'--enable-shmop' \
'--enable-sysvsem' \
'--enable-inline-optimization' \
'--with-curl' \
'--enable-mbregex' \
'--enable-mbstring' \
'--enable-intl' \
'--enable-ftp' \
'--enable-gd' \
'--with-webp' \
'--enable-gd-jis-conv' \
'--with-openssl' \
'--with-mhash' \
'--enable-pcntl' \
'--enable-sockets' \
'--with-xmlrpc' \
'--enable-soap' \
'--with-gettext' \
'--enable-opcache' \
'--with-pear' \
'--with-ldap=shared' \
'--enable-embed' \
'--without-gdbm' \
'--enable-fast-install' \
'--disable-fileinfo' \
'--without-sqlite3' \
'--without-pdo-sqlite' \
"$@"

[root@uscdn1 ~]# chmod +x config.nice
[root@uscdn1 ~]# ./config.nice && make && make install
[root@uscdn1 php-7.4.7]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@uscdn1 php-7.4.7]# cp php.ini-production /usr/local/php/etc/php.ini
[root@uscdn1 ~]# cd /usr/local/php/etc
[root@uscdn1 ~]# cp php-fpm.conf.default php-fpm.conf
[root@uscdn1 ~]# cd php-fpm.d
[root@uscdn1 ~]# cp www.conf.default www.conf

### 安装Cmake3、pdo_mysql和libzip,让PHP支持MySQL PDO和ZIP扩展

[root@uscdn1 ~]# yum remove -y libzip
[root@uscdn1 ~]# yum install -y cmake3
[root@uscdn1 ~]# sudo ln -sf /usr/bin/cmake3 /usr/bin/cmake
[root@uscdn1 ~]# cd /usr/local/src/
[root@uscdn1 ~]# wget https://libzip.org/download/libzip-1.6.1.tar.gz
[root@uscdn1 ~]# tar xf libzip-1.6.1.tar.gz 
[root@uscdn1 ~]# cd libzip-1.6.1
[root@uscdn1 ~]# mkdir build && cd build
[root@uscdn1 ~]# cmake ..
[root@uscdn1 ~]# make && make install
[root@uscdn1 ~]# /usr/local/php/bin/pecl install zip

###安装MySQL PDO扩展

[root@uscdn1 php-7.4.7]# cd ext/pdo_mysql/
[root@uscdn1 php-7.4.7]# /usr/local/php/bin/phpize 
[root@uscdn1 php-7.4.7]# ./configure -with-php-config=/usr/local/php/bin/php-config -with-pdo-mysql=mysqlnd
[root@uscdn1 php-7.4.7]# make && make install

5、把nginx、mariadb、php-fpm加入开机自启动



[root@uscdn1 php-7.4.7]# systemctl enable nginx mariadb php-fpm
[root@uscdn1 php-7.4.7]# systemctl restart nginx mariadb php-fpm

6、配置php.ini、php-fpm.conf、www.conf文件,需要先创建/var/log/php-fpm/目录,mkdir /var/log/php-fpm/



[root@uscdn1 php-7.4.7]# vi /usr/local/php/etc/php.ini

;配置MySQL socket文件
pdo_mysql.default_socket= /var/lib/mysql/mysql.sock
mysqli.default_socket = /var/lib/mysql/mysql.sock

;不显示错误,默认
display_errors = Off

;在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置),默认
log_errors = On

;字符集,默认
default_charset = "UTF-8"

;文件上传大小,默认值太小,建议修改10M
upload_max_filesize = 2M

;Maximum size of POST data that PHP will accept.  表单最大值,默认是8M,如果表单含有多图上传,大小可能不够。超过该大小后台收不到 表单数据
post_max_size = 8M

;设置PHP的扩展库路径,默认被注释了,之后一个文件夹 于 你/usr/local/php/lib/php/extensions/ 下的文件夹同名。
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/"
extension = "pdo_mysql.so"
extension = "ldap.so"
extension = "zip.so"

;设置PHP的时区
date.timezone = PRC

;开启opcache,默认是0
[opcache]
; Determines if Zend OPCache is enabled
zend_extension= "/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/opcache.so"
opcache.enable=1

### 开启opcache 和 JIT
### opcache 配置参数参考:https://www.php.net/manual/zh/opcache.configuration.php
### JIT 配置参数参考:https://www.laruence.com/2020/06/27/5963.html

opcache.jit=1205
opcache.jit_buffer_size=64M

### 配置/usr/local/php/etc/php-fpm.conf文件

[root@uscdn1 php-7.4.7]# vi /usr/local/php/etc/php-fpm.conf

; 去掉里分号,方便以后重启。建议修改
;Default Value: none
; 下面的值最终目录是/usr/local/php/var/run/php-fpm.pid
; 开启后可以平滑重启php-fpm
pid = run/php-fpm.pid

; 设置错误日志的路径,可以默认值
; Note: the default prefix is /usr/local/php/var
; Default Value: log/php-fpm.log, 即/usr/local/php/var/log/php-fpm.log
error_log = /var/log/php-fpm/error.log

; Log等级,可以默认值
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice

; 后台运行,默认yes,可以默认值
; Default Value: yes
;daemonize = yes

; 引入www.conf文件中的配置,可以默认值
include=/usr/local/php/etc/php-fpm.d/*.conf

### 配置/usr/local/php/etc/php-fpm.d/www.conf

[root@uscdn1 php-7.4.7]# vi /usr/local/php/etc/php-fpm.d/www.conf
; 设置用户和用户组,默认都是nobody。可以默认值
user = nobody
group = nobody

; 设置PHP监听
; 下面是默认值,不建议使用。可以默认值
listen = 127.0.0.1:9000
; 根据nginx.conf中的配置fastcgi_pass unix:/dev/shm/php-fpm.sock;
listen = /dev/shm/php-fpm.sock

;修改权限
listen.owner = nobody
listen.group = nobody
listen.mode = 0660

######开启慢日志。可以默认值
slowlog = /var/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 10s



### 添加PHP-fpm自启动和启动
[root@uscdn1 ~]# systemctl enable php-fpm.service 
[root@uscdn1 ~]# systemctl start php-fpm.service 

  • 版权声明:本文版权归开发说和原作者所有,未经许可不得转载。文章部分来源于网络仅代表作者看法,如有不同观点,欢迎进行交流。除非注明,文章均由 开发说 整理发布,欢迎转载,转载请带版权。

  • 来源:开发说 ( https://www.kaifashuo.com/ ),提供主机优惠信息深度测评和服务器运维编程技术。
  • 链接:https://www.kaifashuo.com/1931.html
  • 评论(0

    1. 还没有任何评论,你来说两句吧

    发表回复

    您的电子邮箱地址不会被公开。 必填项已用*标注