centos7php7.2环境搭建(nginx1.12.1 php7.2 mysql5.7 redis)

安装nginx

如果是控系统先安装nginx 依赖的一些 lib 库:

yum install gcc-c++
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl--devel

// 查看yum源
yum list | grep nginx

//检查一下安装已有的 nginx
find -name nginx

//如果系统安装了Nginx,那么卸载
yum remove nginx
//这三步也可以忽略

选择想要下载的版本

// 没有版本要求直接安装
yum install nginx

centos7php7.2环境搭建(nginx1.12.1 php7.2 mysql5.7 redis)
确认需要下载的版本,没问题直接 y y y 看见Complete! 安装完成

// 查看版本
nginx -v

// 检测配置文件
nginx -t

// 启动 .service 可以省略
systemctl start nginx.service 

// 停止
systemctl stop nginx

//重启
systemctl restart nginx

//热启动
systemctl reload nginx

//设置开启启动
systemctl enable nginx

//取消开机启动
systemctl disable nginx

//查看服务状态
systemctl status nginx

//查看进程
ps -aux | grep nginx

这时候直接输入ip 就已经可以成功访问了

安装php7.2


// 首先安装epel-release 升级软件包
yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

什么是EPEL 及 Centos上安装EPEL

RHEL以及他的衍生发行版如CentOS、Scientific Linux为了稳定,官方的rpm repository提供的rpm包往往是很滞后的,当然了,这样做这是无可厚非的,毕竟这是服务器版本,安全稳定是重点,官方的rpm repository提供的rpm包也不够丰富,很多时候需要自己编译那太辛苦了,而EPEL恰恰可以解决这两方面的问题。

EPEL的全称叫 Extra Packages for Enterprise Linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源。


// 安装php7.2 fpm cli
yum install php72w-fpm php72w-opcache php72w-cli

//启动
systemctl start php-fpm

//设置开机启动
systemctl enable php-fpm

//查看版本
php -v

//查看相关扩展
php -m

安装mysql5.7

从CentOS 7.0发布以来,yum源中开始使用Mariadb来代替MySQL的安装。即使你输入的是yum install -y mysql , 显示的也是Mariadb的安装内容。使用源代码进行编译安装又太麻烦。因此,如果想使用yum安装MySQL的话,就需要去下载官方指定的yum源,网址为: https://dev.mysql.com/downloads/repo/yum/


// 进入安装包目录(安装在了用户目录)
cd ~

//下载yum源rpm包
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

//安装rpm包
rpm -ivh mysql57-community-release-el7-11.noarch.rpm

//安装mysql
yum install -y mysql-server

//启动服务 设置开机启动
systemctl start mysqld
systemctl enable mysqld

使用初始密码登录
由于MySQL从5.7开始不允许首次安装后,使用空密码进行登录,系统会随机生成一个密码以供管理员首次登录使用,这个密码记录在/var/log/mysqld.log文件中,使用下面的命令可以查看此密码:


// 最后一行冒号后面的部分就是初始密码
cat /var/log/mysqld.log|grep 'A temporary password'

//进入mysql 输入密码
mysql -u root -p

//这时候输入什么都会提示错误:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 是要必须修改密码才能继续操作,修改密码:
alter user 'root'@'localhost' identified by 'your_password';

//ok 可以进行操作了

安装redis


// reids一般我都安装系统提供的默认版本 简单粗暴
yum install redis

//启动 开启启动
systemctl start redis
systemctl enable redis

//cli操作
redis-cli

常规配置和扩展

nginx


cd /etc/nginx/conf.d/

vim xxx.conf

//server内容
server {
	
	
    listen       80;
    server_name  localhost;
	
	#https
	#listen              443 ssl;
    #server_name         ***.com;
    #ssl_certificate     /var/crt/***.crt;
    #ssl_certificate_key /var/crt/***.key;
    #ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    #ssl_ciphers         HIGH:!aNULL:!MD5:!DH;
    #ssl_prefer_server_ciphers on;

	

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;


    root   /var/www/html;
    index index.php index.html index.htm;
    
    charset utf-8;
	
	#laravel
    #location / {
    #        try_files $uri $uri/ /index.php?$query_string;
    # }

	#tp
	#location / {
   #        if (!-e $request_filename){

   #              rewrite ^(.*)$ /index.php?s=$1 last;
   #              break;
   #        }
   #        try_files $uri $uri/ /index.php$uri?$query_string;
   #}


    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /var/www;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php {
        fastcgi_pass                  127.0.0.1:9000;
        fastcgi_index                 /index.php;
        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include                       fastcgi_params;
    }

	
}

#301
#server{
#       listen       80;
#       server_name   ***.com;
#       return 301 https://***.com$request_uri;
#}

php

//查看相关文件
whereis php

//常规配置
vim /etc/php.ini

memory_limit //内存使用
error_reporting //错误级别
post_max_size //post 最大限制
upload_max_filesize //上传最大限制

//session多服务器共享一般配置存在reids
session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379"

//扩展安装 先查看需要的扩展
yum search php72 

//常规需要安装的扩展
yum install php72w-pdo php72w-mysql php72w-mbstring php72w-gd

//reids 扩展
yum install php-redis

//最后不要忘记重启php-fpm
systemctl restart php-fpm