X-osadmin的自留地 X-osadmin的自留地
  • ? 博客主页•Index
  • ? 技术小絮·Tech
  • ✍ 点点滴滴·Diary
  • ? 作品发布·Works ↓
    • 下载中心
    • Y-OS
    • SpeedTest · 云测速
  • ? 专题文章·Catalogs
  • ? 友情链接
  • ? 博客主页•Index
  • ? 技术小絮·Tech
  • ✍ 点点滴滴·Diary
  • ? 作品发布·Works ↓
    • 下载中心
    • Y-OS
    • SpeedTest · 云测速
  • ? 专题文章·Catalogs
  • ? 友情链接
首页 技术小絮 CentOS 7用yum配置php7.2+mariadb+nginx

CentOS 7用yum配置php7.2+mariadb+nginx

xosadmin 2年前
  1. 更新Linux源并安装EPEL+Webtatic源

yum -y install epel*

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2. 清理系统,清除原有软件

yum -y remove httpd* mysql* php*

3. 安装PHP 7.2

yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-gd php72w-mbstring php72w-mysqlnd php72w-pdo php72w-xml

安装完成后,需要将php-fpm设置为开机启动,并立即启动它,命令如下:

systemctl enable php-fpm

systemctl start php-fpm

4. 安装Mariadb,这里也采用yum安装

yum -y install mariadb mariadb-server

5. 安装完成后,需要对mariadb进行初始设置,命令如下:

systemctl enable mariadb && systemctl start mariadb

mysql_secure_installation

在执行最后一条命令时,会提示输入初始mariadb root密码。由于我们是全新安装,所以默认密码为空,直接回车即可。其他的设置可以依据个人需要通过接下来的设置向导完成。

6. 安装nginx

yum -y install nginx

安装完成后,设置开机启动,并立即启动nginx:

systemctl enable nginx && systemctl restart nginx

在这条命令完成后,nginx已经被成功地安装在/etc/nginx文件夹下,默认的网站存放位置为/usr/share/nginx/html。

7. 默认的nginx是不支持PHP的,所以需要对Nginx作出一点点配置,使其支持PHP。所以,需要编辑/etc/nginx/nginx.conf,并在server的大括号中加入以下内容:

location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}

为了避免不必要的麻烦,这里将fastcgi的SCRIPT_FILENAME地址直接修改成绝对路径。完成后,重启nginx。

systemctl restart nginx

若想测试Nginx和PHP是否配合运行完美,可以在/usr/share/nginx/html目录下新建一个test.php,并填入以下代码后用浏览器访问:

<?php

phpinfo();

?>

若出现PHP的配置信息,则表示各个配置一切正常。反之,请检查配置。

到这里,所有的安装已经全部完成。若出现Nginx成功启动,但访问IP时无法访问,显示拒绝连接的问题,请检查防火墙设置及Selinux设置。

systemctl stop firewalld && setenforce 0

Enjoy~

0
猜你喜欢
  • Bark提示TokenExpired的解决方法
  • Debian 11启用rc.local方法
  • Debian 11通过apt安装proxmox 7
  • 为proxmox 6/7一键开启bbr
  • CentOS迁移后开机提示lvm not found的解决方法
  • curl: (35) Peer reports incompatible or unsupported protocol version的解决方法
评论 (0)
再想想
    暂无评论
xosadmin
站长
Codes learner / Love Linux & OpenWrt
110
文章
2
评论
0
获赞

文章聚合

  • ♥ X-osadmin’s Website ♥
  • 下载中心
  • 网站通知
  • Y-OS
  • 友情链接
  • 联系站长
  • X-osadmin’s Git Server
Copyright © 2016-2022 X-osadmin的自留地. Designed by nicetheme.