技术饭

CentOS8 Nginx+PHP7.2+mysql8+redis+git的配置以及注意事项

copylian    0 评论    9269 浏览    2020.11.11

CentOS8 Nginx+PHP7.2+mysql8的配置以及注意事项,CentOS8的配置相对Contos7比较简单。在以下讲解中会详细讲解到两个系统nginx、php、mysql8的安装和配置。目前nginx1.14、php7.2、mysql8都已经加入centos8官方源,使用和配置都简单很多。

参考资料:https://www.copylian.com/technology/83.html

参考资料:https://www.rednn.com/createsite/202003/2176.html

讲在安装配置前:准备一台centos8的云服务器,没有服务器可以在阿里上买个几天,没几个钱。

一、安装并配置php

1、下载php

centos8 安装php比较简单,因为7.2版本已经放入官方仓库,直接yum install php-* 安装php所有。也可以按照以上的选定扩展方式安装,只需要去掉72w即可。

yum install php-*

启动服务

systemctl start php-fpm.service

查看php版本,php-fpm -v   

[root@iZbp1ce64o4g9q2js1du3rZ conf.d]# php -v

PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.24,Copyright (c) 1999-2018, by Zend Technologies


2、配置php

配置php.ini文件

vi /etc/php.ini

memory_limit = 1024M                 // 内存大小,大小可自行设定

post_max_size = 100M                 // 表单上传大小。默认为8M

file_uploads = on                   // 是否允许上传文件。默on(开)

upload_max_filesize = 100M              // 文件上传大小。默认为2M


配置/etc/php-fpm.d/www.conf文件

vi /etc/php-fpm.d/www.conf


将用户和组都改为nginx

user = nginx

group = nginx


php-fpm所监听的端口为9000

listen = 127.0.0.1:9000


去掉下面几行注释

env[HOSTNAME] = $HOSTNAME

env[PATH] = /usr/local/bin:/usr/bin:/bin

env[TMP] = /tmp

env[TMPDIR] = /tmp

env[TEMP] = /tmp


修复有关nextcloud内OPcache提示的问题

vi /etc/php.d/opcache.ini

vi /etc/php.d/10-opcache.ini       // CentOS8 php7.2在此位置


修改以下每个参数

opcache.enable=1

opcache.enable_cli=1

opcache.interned_strings_buffer=8

opcache.max_accelerated_files=10000

opcache.memory_consumption=128

opcache.save_comments=1

opcache.revalidate_freq=1


二、安装并配置nginx

yum install -y nginx

centos8 中nginx1.14版本已加入官方仓库,直接下载安装即可

[root@iZbp1ce64o4g9q2js1du3rZ conf.d]# nginx -v

nginx version: nginx/1.14.1 


启动nginx

systemctl start nginx


安装完成后访问ip:端口,应该是这一个样子的

11-44-190269756881444.png

配置nginx.conf

vi /etc/nginx/nginx.conf


写入以下内容到nginx.conf


# For more information on configuration, see:

#   * Official English Documentation: http://nginx.org/en/docs/

#   * Official Russian Documentation: http://nginx.org/ru/docs/


user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;


# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;


events {

    worker_connections 1024;

}


http {

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';


    access_log  /var/log/nginx/access.log  main;


    client_header_buffer_size 32k;

    large_client_header_buffers 4 32k;


    sendfile            on;

    tcp_nopush          on;

    tcp_nodelay         on;

    keepalive_timeout   65;

    types_hash_max_size 2048;    

    client_max_body_size 8M;


    gzip                 on;

    gzip_vary            on;

    gzip_min_length      1k;

    gzip_buffers         4 16k;

    gzip_http_version    1.0;

    gzip_comp_level      2;

    gzip_disable         "MSIE [1-6]\.";

    gzip_types           text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;


    fastcgi_connect_timeout 300;

    fastcgi_send_timeout 300;

    include             /etc/nginx/mime.types;

    default_type        application/octet-stream;


    # Load modular configuration files from the /etc/nginx/conf.d directory.

    # See http://nginx.org/en/docs/ngx_core_module.html#include

    # for more information.

    #加载配置

    include /etc/nginx/conf.d/*.conf;


    #默认

    server {

        listen       80 default_server;

        listen       [::]:80 default_server;

        server_name  _;

        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;


        location / {

       }


        error_page 404 /404.html;

            location = /40x.html {

        }


       error_page 500 502 503 504 /50x.html;

            location = /50x.html {

        }

    }

    

    #禁止ip访问

    server {

       listen       80;

        server_name  47.99.182.235;

        return 403;

    }

# Settings for a TLS enabled server.

#

#    server {

#        listen       443 ssl http2 default_server;

#        listen       [::]:443 ssl http2 default_server;

#        server_name  _;

#        root         /usr/share/nginx/html;

#

#        ssl_certificate "/etc/pki/nginx/server.crt";

#        ssl_certificate_key "/etc/pki/nginx/private/server.key";

#        ssl_session_cache shared:SSL:1m;

#        ssl_session_timeout  10m;

#        ssl_ciphers PROFILE=SYSTEM;

#        ssl_prefer_server_ciphers on;

#

#        # Load configuration files for the default server block.

#        include /etc/nginx/default.d/*.conf;

#

#        location / {

#        }

#

#        error_page 404 /404.html;

#            location = /40x.html {

#        }

#

#        error_page 500 502 503 504 /50x.html;

#            location = /50x.html {

#        }

#    }

}


三、安装配置mysql8

Centos8 直接安装即可

安装mysql8

yum install mysql mysql-server         //系统默认安装mysql8

启动mysqld

systemctl start mysqld

如果安装完mysql之后没有cat到密码,那么只能初始化mysql密码,然后重新进到mysql里去修改密码

mysqld --initialize --user=mysql --console

alter user root@localhost identified by '你的密码'

这里你可以设置mysql等,比如:客户端登录,比如做主从等

参考资料:

MySQL 8.0主从(Master-Slave)配置

MySQL8让我们先登录它

MySQL删除用户(DROP USER)

Navicat连接Mysql报错:Client does not support authentication protocol requested by server;

Mysql主从数据库(Master/Slave)同步配置与常见错误

四、安装配置redis

yum install redis         //系统默认安装redis

配置可以参考:

centos7下php7、mysql5.7、nginx、redis、git、svn知识整理

安装PHP的redis扩展

PHP7.2 redis扩展的安装

五、安装配置git

yum install  git //系统默认安装git

配置可以参考:

git 生成秘钥

安装PHP的redis扩展

git 永久记住密码

六、负载均衡:NGINX分发+redis+mysql主从+N台服务器+oss存储

文档配置请参考阿里云负载均衡 SLB,其实阿里的负载均衡也只是分发请求而已,当然自己也可以开一台专门的服务器做NGINX分发,当有多台服务器的时候应该考虑的是系统的文件存储与数据架构问题,早规划早舒服,不然到后期很累啊,这里还有一个问题是:thinkphp5 tp5 url生成启用https支持,如果使用了https可能会报https不能跨http,这里就需要把请求的http改成https即可。

最后就是进程做开机启动:

systemctl enable nginx

systemctl enable php-fpm

systemctl enable redis

systemctl enable mysqld

只袄早~~~
感谢你的支持,我会继续努力!
扫码打赏,感谢您的支持!

文明上网理性发言!

  • 还没有评论,沙发等你来抢