显示普通的PHP代码

我正在使用Amazon EC2,CentOS 7 x64_86,1GB内存。

(1)运行命令

php -v 

结果

 PHP 7.0.24 (cli) (built: Sep 30 2017 10:10:28) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies 

(2)运行命令

 httpd -v 

结果

 Server version: Apache/2.4.6 (CentOS) Server built: Oct 19 2017 20:39:16 

(3)运行命令

 vi /etc/httpd/conf.d/welcome.conf 

结果

 # # This configuration file enables the default "Welcome" page if there # is no default index page present for the root URL. To disable the # Welcome page, comment out all the lines below. # # NOTE: if this file is removed, it will be restored on upgrades. # #<LocationMatch "^/+$"> # Options -Indexes # ErrorDocument 403 /.noindex.html #</LocationMatch> <Directory /usr/share/httpd/noindex> AllowOverride None Require all granted </Directory> Alias /.noindex.html /usr/share/httpd/noindex/index.html Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png 

错误

在这里输入图像说明

在这里输入图像说明

如何解决它?

我不确定你从哪里得到PHP,因为CentOS 7的版本是5.4.16。 无论如何,stock php包会安装Apache的configuration,以便通过PHP解释器提供*.php文件(所以它们不只是返回源代码)。 你需要这样的东西添加到你的Apacheconfiguration:

 LoadModule php5_module modules/libphp5.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> 

这是基于标准的php包configuration。 如果你自己编译PHP,你将需要适应它。