1.安装php7.2
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 install php
yum install php-fpm php-mysqlnd php-pdo php-json php-mbstring php-gd php-xml php-common
systemctl start php-fpm.service
systemctl enable php-fpm.service
2.安装nginx
2.1创建www用户
groupadd www
useradd -s /sbin/nologin www -g www -M
2.2添加nginx官方yum源
vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
输入 :wq 保存
2.3下载nginx签名密钥
rpm --import http://nginx.org/keys/nginx_signing.key
yum -y install nginx
3.配置nginx支持php
3.1处理php-fpm配置
vi /etc/php-fpm.d/www.conf
user = www
group = www
3.2处理nginx配置
vi /etc/nginx/nginx.conf
user www;
3.4处理nginx默认虚拟主机配置
vi /etc/nginx/conf.d/default.conf
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
3.5重启nginx,php-fpm
systemctl restart nginx.service
systemctl restart php-fpm.service
附:如果以上都配置完,输入IP无法访问网页,而且nginx的access.log、error.log为空,考虑是服务器的80端口没有开启(如果购买的是阿里云或者腾讯云,直接在控制台->安全组添加端口即可)
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
如果php启动失败,提示please specify user and group other than root,则用户权限不足,需要设置为将nginx和php的.conf文件中的用户配置改为www。
Nginx 403错误可能原因:
1.权限问题,如果nginx没有web目录的操作权限,也会出现403错误。
chmod -R 777 /data
chmod -R 777 /data/www/
- 由于启动用户和nginx工作用户不一致所致
2.1查看nginx的启动用户,发现是nginx,而不是用root启动的
ps -aux | grep nginx
2.2将nginx.conf的user改为和启动(worker)用户一致
3.SELinux设置为开启状态(enabled)的原因。
3.1、查看当前selinux的状态。
/usr/sbin/sestatus
3.2、将SELINUX=enforcing 修改为 SELINUX=disabled 状态。
vi /etc/selinux/config
#SELINUX=enforcing
SELINUX=disabled
3.3、重启生效
reboot
安装MySQL5.7
列出所有被安装的mariadb package
rpm -qa | grep mariadb
卸载mariadb
rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64
如果提示错误:
依赖检测失败: libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要 libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要
那就强制卸载
rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64
安装mysql依赖
yum install vim libaio net-tools
下载mysql的repo源
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
安装mysql rpm包
yum -y install mysql57-community-release-el7-10.noarch.rpm
安装mysql
yum -y install mysql-community-server
如果报错:
mysql-community-libs-5.7.37-1.el7.x86_64.rpm 的公钥尚未安装
失败的软件包是:mysql-community-libs-5.7.37-1.el7.x86_64 GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
可以修改配置跳过校验,修改/etc/yum.repos.d/mysql-community.repo文件内容
修改对应安装版本的gpgcheck=0即可,默认值为1
设置密码
mysql -u root
有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
chown -R root:root /var/lib/mysql
然后,重启服务:
service mysqld restart
接下来登录重置密码:
mysql -u root
如果提示密码错误,首次安装未修改过密码,那输入
grep "A temporary password is generated for root@localhost" /var/log/mysqld.log
mysql -uroot -p
输入上面显示的密码即可
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';或者 set password for root@localhost = '123456';
如果上面报错则:
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
如果提示密码策略不安全,那么
set global validate_password_policy=0;
exit;
开启3306防火墙端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
ERROR 1130: Host ’192.168.1.3′ is not allowed to connect to this MySQL server
mysql -uroot -p
use mysql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;