centos nginx yum 配置nginx+mysql+p
服务器主机商:亚马逊
系统环境:centos7.7
准备工作
1.配置yum
rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
或
···
yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
···
卸载PHP历史版本
yum -y remove php*
配置PHP
1.安装php
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
2.启动php
service php-fpm start
检测是否安装成功:
php -v
image.png
安装完成
安装mysql
1.配置npm
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
2.安装 YUM Repo 文件
yum localinstall mysql80-community-release-el7-1.noarch.rpm
3.启用mysql5.7
yum-config-manager --enable mysql57-community
4.确认mysql包
yum repolist enabled | grep mysql
image.png
5.安装mysql
yum install -y mysql-community-server
6.启动mysql
systemctl start mysqld.service
#开机自启mysql
systemctl enable mysqld.server
7.获取mysql临时root 密码
grep 'temporary password' /var/log/mysqld.log
image.png
注意:
MySQL的 validate_password 插件默认安装。这将要求密码包含至少一个大写字母,一个小写字母,一个数字和一个特殊字符,并且密码总长度至少为8个字符。
配置Nginx
1.安装nginx
yum -y install nginx
2.检测是否安装完成
rpm -q nginx
3.启动nginx
启动nginx:systemctl start nginx
加入开机启动:systemctl enable nginx
4.访问端口
···
image.png
> 注意,这里有可能会出现内网可以正常curl,外网无法访问,请执行一下命令
关闭SELinux:
setenforce 0
访问成功!
5.配置nginx
目录:/etc/conf/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 root;
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_user [request" '
'body_bytes_sent "http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /www;
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
存放目录:/etc/nginx/conf.d/demo.conf
创建demo.conf 网站nginx配置:
server {
listen 81;
server_name localhost;
#root /var/www/;
root /www;
index index.php;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
error_page 404 /404.html;
location = /404.html {
return 404 'Sorry, File not Found!';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /www; # windows用户替换这个目录
}
location / {
try_files $uri @rewrite;
}
location @rewrite {
# set $static 0;
# if ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
# set $static 1;
# }
# if ($static = 0) {
# rewrite ^/(.*)$ /index.php?s=/$1;
# }
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ /Uploads/.*\.php$ {
deny all;
}
location ~ \.php/ {
if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_NAME $1;
fastcgi_param PATH_INFO $2;
fastcgi_param SCRIPT_FILENAME $document_root$1;
}
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;
#include fastcgi.conf;
}
location ~ /\.ht {
deny all;
}
}
网站目录:
/www
已配置了tp5的nginx伪静态,可以直接使用
# 创建开机自启
1.创建自启文件:
chmod +x /etc/rc.d/rc.local
2.修改文件
vim /etc/rc.d/rc.local
添加下面3行
service nginx start
setenforce 0
service php-fpm start
按ESC,然后输入:,键入wq保存退出,完成