CentOS7 nginx + php + redis + mysql

 

https://www.jb51.net/article/137124.htm

 

 

  1. 安装nginx

     yum install nginx
    
  2. 启动nginx

     systemctl start nginx
  3. 设置开机自启 

    systemctl enable nginx.service

安装php

1、如果之前已经安装我们先卸载一下

1
yum -y remove php*

2、由于linux的yum源不存在php7.x,所以我们要更改yum源

3、yum 安装php72w和各种拓展,选自己需要的即可

 
4,设置开机自启
systemctl enable httpd

5.查看php版本
php-v

6.此时php虽然安装完成,但是要想可以运行指定的项目,需要修改 nginx 配置

6.1
find / -name nginx.conf

 

 6.2 

  打开对应的文件,展示了nginx 的配置文件对应的位置(/etc/nginx/conf.d)下的所有文件,还没有配置域名,所以修改default.conf 文件即可

 

 

 

6.3 对应修改文件

 

 


 server { listen 80; server_name localhost; location / { root /var/www; index index.html index.htm; if (!-e $request_filename) { rewrite ^/index.php(.*)$ /index.php?s=$1 last; rewrite ^(.*)$ /index.php?s=$1 last; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www; } location ~ \.php$ { root /var/www/share/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/share/public$fastcgi_script_name; include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(.*)$; } } 6.4 查看nginx 配置文件是否正确 (有 successful 说明正确)


 

6.5 重新加载nginx

  nginx -s reload

 

 

MySQL

  1. 下载mysql源安装包

    wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
    
  2. 安装mysql源

     yum localinstall mysql57-community-release-el7-8.noarch.rpm
    
  3. 安装mysql

     yum install mysql-community-server
    
  4. 启动MySQL服务

     systemctl start mysqld
    

5.开机启动

systemctl enable mysqld
systemctl daemon-reload

注意:mysql5.7版安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。

查看默认密码

grep 'temporary password' /var/log/mysqld.log

进入mysql控制台

mysql -u root -p
Enter password: Q2>r4=l-DWIP(你查看到的随机密码)

解决mysql > show databases;无法使用

输入mysql指令提示 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

提示必须修改密码,步骤

mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourPassword'

又提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql5.7 此处说明密码设置提供了限制

开始设置的密码必须符合给定长度,且必须含有数字,小写或大写字母,特殊字符。
想随意修改密码就要配置两个全局参数

mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

validate_password_policy 属性取值及说明

0 or LOW    Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file

允许root远程登录

前提——打开服务器3306端口——方法在文末

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123@asdf' WITH GRANT OPTION;
mysql> flush privileges;

第一句中”%”表示任何主机都可以远程登录到该服务器上访问。如果要限制只有某台机器可以访问,将其换成相应的IP即可,如:

GRANT ALL PRIVILEGES ON . TO root@”172.168.193.25” IDENTIFIED BY “123@asdf”;
123@asdf是登录密码。

第二句表示从mysql数据库的grant表中重新加载权限数据。因为MySQL把权限都放在了cache中,所以在做完更改后需要重新加载。

1
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php7

6,绑定域名 并 修改为https 协议

  在上面找到的 nginx 配置文件所在的文件夹下 新建一个 你的域名.conf 文件。文件内容如下:

server {

listen 80;

server_name www.shensing.cn;

rewrite ^(.*)$ https://$host$1 permanent;

root /var/www/share/public;

 

}

 

server {

    listen     443   ssl;

    index index.html index.htm;

    ssl_certificate /etc/nginx/cert/2676927_www.shensing.cn.pem;

    ssl_certificate_key /etc/nginx/cert/2676927_www.shensing.cn.key;

    ssl_session_timeout 5m;

    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    ssl_prefer_server_ciphers on;

 

server_name www.shensing.cn;

    root /var/www/share/public;

location / {

 

index index.php index.html index.htm;

if (!-e $request_filename) {

rewrite ^(.*)$ /index.php?s=$1 last;

break;

}

}

 

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 SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

 

 6.4 查看nginx 配置文件是否正确 (有 successful 说明正确)



 

6.5 重新加载nginx

  nginx -s reload

 

 

posted @ 2019-09-27 16:44  贪婪的猫  阅读(444)  评论(0编辑  收藏  举报