一、LNMP架构设计
服务器A: centos7.3 部署nginx服务
服务器B: centos7.3 部署php-fpm服务
服务器C: centos7.3 部署mariadb服务
二、nginx服务安装并配置
1.安装
yum install nginx
2.配置
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
#vim /etc/nginx/nginx.conf
user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log /var/log/nginx/error.log info;
#pid /var/log/nginx/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
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;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
index index.php index.html index.htm;
#charset koi8-r;
access_log /var/log/nginx/host.access.log main;
location / {
}
#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 html;
}
# 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$ {
# root html;
#指向php服务器IP的9000端口
fastcgi_pass 172.17.17.173:9000;
fastcgi_index index.php;
#指明php程序路径
fastcgi_param SCRIPT_FILENAME /data/web/xiaomi$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
nginx -t
检查配置文件格式
3.启动服务
#注意
在开启服务前,把有关日志的配置去掉
然后开启服务,添加日志配置到配置文件中
再重启服务
systemctl start nginx
三、PHP服务
1.安装
yum install php-fpm php-mysql -y
2.配置
php.ini
vim /etc/php.ini
#修改下面两行
short_open_tag = on
date.timezone = Asia/Shanghai
/etc/php-fpm.d/www.conf
vim /etc/php-fpm.d/www.conf
#修改下面4行
#监听本机9000端口改为全部9000端口
listen = 9000
listen.allowed_clients = 172.17.16.173
user = nobody
group = nobody
#php默认进程以apache身份运行
3.开启服务
systemctl start php-fpm
四、mariadb服务
1.安装,开启服务,运行安全加固脚本
yum -y install mariadb-server
systemctl start mariadb
mysql_secure_installation
2.创建数据库,用户,赋予权限
create database xiaomi;
grant all on xiaomi.* to xiaomiuser@'%' identified by 'xiaomipassword';
五、网站源码部署
1.将网站源码放到php服务器的/data/web/xiaomi目录下
mkdir -p /data/web/xiaomi
unzip -d /data/web/xiaomi/ xiaomi.zip
2.修改网站源码各种文件权限
#在nginx配置文件中设置了user nobody;
#在php的php.ini配置文件中,设置了user nobody;group nobody;
chown -R nobody.nobody /data/web/xiaomi
3.修改连接数据库的设置
网站源码中config.php记录了连接数据库设置
#修改下面几行
// 数据库主机 3306为默认主机端口,如不是默认也需要修改
$db_host = "172.17.17.174:3306";
// 数据库名称
$db_name = "xiaomi";
// 数据库用户名
$db_user = "xiaomiuser";
// 数据库密码
$db_pass = "xiaomipassword";
4.进入http://172.17.16.173/ebak/index.php
登陆---->设置参数---->恢复数据