You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7源码编译安装PHP7.3.33后Apache无法解析PHP求助

解决浏览器直接显示PHP代码的问题

针对Apache服务器的处理步骤

  • 重新编译PHP时必须启用Apache模块,编译命令要加--with-apxs2=/usr/bin/apxs(apxs路径根据你服务器实际位置调整),这会生成libphp7.so模块。
  • 打开Apache的主配置文件(比如httpd.conf),确认以下配置存在:
    LoadModule php7_module modules/libphp7.so
    AddHandler php7-script .php
    Include conf/extra/php7.conf
    
  • 把DirectoryIndex设置为index.php index.html,让Apache优先解析PHP格式的首页文件。
  • 重启Apache服务:CentOS/RHEL用systemctl restart httpd,Ubuntu/Debian用service apache2 restart。

针对Nginx服务器的处理步骤

  • 重新编译PHP时要加--enable-fpm参数,开启PHP-FPM支持。
  • 编辑Nginx的站点配置文件,添加或修改PHP请求处理的location块:
    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;
    }
    
  • 启动PHP-FPM并设置开机自启:systemctl start php-fpm和systemctl enable php-fpm。
  • 重启Nginx服务:systemctl restart nginx。

通用排查要点

  • 确认你的PHP文件后缀是.php,别用.html这类不被Web服务器解析的后缀。
  • 用php -v和which php检查终端里的PHP版本和路径,确保Web服务器配置里调用的是你编译的这个PHP版本。

内容的提问来源于stack exchange,提问作者justacrappyprogrammer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 19:54:39