- A+
所属分类:VPS相关
一、问题描述
Centos8中我们在使用Apache部署配置网站的时候发现Apache服务已经正常启动且网站也配置完成到Apache主目录中但是访问时网站却不能正常运行【即只能够以列表的方式列出所有网站的资源文件而不是以网页的形式展现】
二、思路分析
通过大致查看网站的文件可知该网站使用到了php内容即需要搭配PHP才能使用接下来就是查看该Centos8服务器中是否安装了PHP模块且是否启用。
三、解决步骤
3.1、检查php是否启用
Bash
#查看php是否启用命令
ps -ef | grep php
如下图所示发现php在Centos8中并没有启用

3.2、查看php所在位置
Bash
#查看php所在位置命令
whereis php-fpm
如下图所示发现php并没有在Centos8中进行安装

3.3、PHP不存在则进行安装配置
通过以上【检查php是否启用】、【查看php所在位置】操作可以发现该Centos8上还没有安装配置php接下来就是进行php的安装配置
3.3.1、启用remi仓库源
Bash
#启用remi仓库源命令
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm --skip-broken


3.3.2、获取当前可用的所有php版本
Bash
#获取当前可用的所有php版本命令
sudo dnf module list php
如下图所示

3.3.3、安装指定的php版本
《1》Centos8中默认使用php7.2版本如果你想要切换当前的php版本则可以进行如下操作
Bash
#切换Centos8中的php版本命令
sudo dnf module reset php
sudo dnf module enable php:remi-版本号
#比如我这里要切换为php7.4命令为
sudo dnf module reset php
sudo dnf module enable php:remi-7.4
《2》安装php模块
Bash
#安装php模块命令
sudo dnf install php php-opcache php-gd php-curl php-mysqlnd

《3》启动php的 fpm 服务且设置开机启动
Bash
#启动php的fpm服务器设置开机启动命令
sudo systemctl enable --now php-fpm

《4》配置php到Apache上
Bash
配置php到Apache上命令
sudo systemctl restart httpd

《5》Centos8中Apache服务无法启动原因排查
Centos8中Apache服务无法启动原因排查——Apache默认端口被占用
《6》打开Apache的对应的防火墙端口
您可以选择一种方式赞助本站
赏