一、准备三台主机
192.168.100.11 mysql
192.168.100.12 nginx
192.168.100.13 php
二、关闭防火墙及安全策略
systemctl stop firewalld
setenforce 0
三、安装nginx(192.168.100.11)
1、添加nginx源
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
2、yum下载nginx
yum install nginx -y #--安装nginx
nginx -v #--查看nginx版本
3、启动nginx
systemctl start nginx.service
systemctl enable nginx.service
四、安装mysql(192.168.100.12)
1、安装mysql
yum remove mariadb* -y
2、配置
cd /etc/yum.repos.d
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
#---解析主机地址,使用阿里源
yum -y install mysql57-community-release-el7-10.noarch.rpm#--下载mysql源
sed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repo#--修改源文件
yum -y install mysql-community-server
#--安装mysql
3、启动mysql
systemctl start mysqld.service
systemctl enable mysqld.service
4、获取mysql初始密码
grep "password" /var/log/mysqld.log | awk '{print $NF}'
#--在日志文件中找出root用户的初始密码
5、登录mysql
mysql -uroot -p
Enter password: #输入初始密码 Q3ua.n-36/-RALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123'; #更改密码
yum -y remove mysql57-community-release-el7-10.noarch #--卸载mysql自动更新
五、安装php
1、安装php
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm#--失败就多试几次
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache
2、启动php
systemctl start php-fpm
systemctl enable php-fpm
3、配置php
useradd -M -s /sbin/nologin php #--创建php用户
vim /etc/php.ini
date.timezone = Asia/Shanghaivim /etc/php-fpm.d/www.conf
user = php
group = php
listen = 192.168.80.12:9000
listen.allowed_clients = 192.168.80.10
六、配置nginx支持php
cd /etc/nginx/conf.d
vim default.conf
......
location ~ \.php$ {
root /www;
fastcgi_pass 192.168.80.12:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # $document_root 和 root 属性一样
include fastcgi_params;
}systemctl restart nginx