CentOS7.4 nginx+php7.0+redis+mysql5.7+ssl 配置
php的接触得很少,记录一下
环境:CentOS 7.4
安装软件
# 安装 mysql5.7
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum install mysql-server -y
# 获取密码
grep "password" /var/log/mysqld.log
# 设置新密码
set global validate_password_policy=LOW;
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;
grant all privileges on *.* to root@"%" identified by "123456";
grant all privileges on *.* to root@"localhost" identified by "123456";
flush privileges;
# 安装 nginx
yum install nginx
# 配置PHP7的源,安装 PHP 7.0 及扩展
yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w-pdo php70w-json php70w-pecl-apcu php70w-pecl-apcu-devel
useradd www
# 修改 nginx.conf 的用户
vi /etc/nginx/conf/nginx.conf
useradd www www;
# 修改 php-fpm 的用户
vi /etc/php-fpm.d/www.conf
#找到user和group改为:
user = www
group = www
# 注意,项目要改成 www 的用户
chown -R www.www /www/
# 测试 php-fpm
php-fpm -t
systemctl start php-fpm
# 安装 redis 及 redis 扩展
yum install php70w-pecl-redis redis
配置网站 /etc/nginx/conf.d/www.conf
server {
listen 80;
server_name klvchen.com www.klvchen.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl http2;
server_name klvchen.com www.klvchen.com;
ssl_certificate /etc/nginx/cert/3177653_klvchen.com.pem;
ssl_certificate_key /etc/nginx/cert/3177653_klvchen.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:1m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
root /data/web/thinkphp_5.0.15_full/public;
location / {
index index.html index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
nginx -t
nginx
测试 phpinfo.php
<?php
phpinfo();
?>
注意:若是使用 phpcms 框架,注意php版本,老的框架不支持 php7.0以上版本会,浏览器会报500错误,需要把 php 降级到 5.4 版本