如何在 Linux Fedora 上的 Apache 中启用 PHP?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14660125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:54:22  来源:igfitidea点击:

How to enable PHP in Apache on Linux Fedora?

phplinuxapachefedora

提问by

The title pretty much sums it up. I'm running Fedora 18 64-bitwith Apache installed through 'httpd'. I have my Apache running just fine but my PHP doesn't seem to work. I'm fairly certain I do have it installed on my machine (new to Linux).

标题几乎总结了它。我正在运行Fedora 18 64 位,并通过“httpd”安装了 Apache。我的 Apache 运行得很好,但我的 PHP 似乎不起作用。我很确定我的机器上安装了它(Linux 新手)。

I created a 'test.php' file in my /var/www/html/directory containing the code: <?php phpinfo(); ?>But it's not displaying the way it should, it's just printing out the text to my browser.

我在/var/www/html/包含代码的目录中创建了一个“test.php”文件:<?php phpinfo(); ?>但它没有按应有的方式显示,它只是将文本打印到我的浏览器。

So I'm of the idea that PHP isn't set up in my Apache configuration or something. Can someone shed some light on this and have some suggestions on how to go about to get this to work?

所以我认为我的 Apache 配置中没有设置 PHP。有人可以对此有所了解,并就如何使其发挥作用提出一些建议吗?

Thanks in advance!

提前致谢!

Edit, this is my httpd.config file:

编辑,这是我的 httpd.config 文件:

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost

<Directory />
   AllowOverride none
   Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
   AllowOverride None    
   Require all granted
</Directory>

<Directory "/var/www/html">
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</Directory>

<IfModule dir_module>
   DirectoryIndex index.html
</IfModule>

<Files ".ht*">
   Require all denied
</Files>

ErrorLog "logs/error_log"
LogLevel warn

<IfModule log_config_module>

   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
   LogFormat "%h %l %u %t \"%r\" %>s %b" common

   <IfModule logio_module>
     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
   </IfModule>

   CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
   ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
   AllowOverride None
   Options None
   Require all granted
</Directory>

<IfModule mime_module>
   TypesConfig /etc/mime.types
   AddType application/x-compress .Z
   AddType application/x-gzip .gz .tgz
   AddType text/html .shtml
   AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8
MIMEMagicFile conf/magic
EnableSendfile on
IncludeOptional conf.d/*.conf

回答by Hanky Panky

  1. yum install php
  2. Restart apache.
  3. Try again.
  1. yum install php
  2. 重启阿帕奇。
  3. 再试一次。

PHP Needs to be installed itself. Its not an apache module to simply enable without first installing PHP.

PHP 需要自行安装。它不是一个无需先安装 PHP 就可以简单启用的 apache 模块。

回答by mohammad mohsenipur

You May have some Problem One Of Them is You didn't define ".php" index for Apache

您可能有一些问题其中之一是您没有为 Apache 定义“.php”索引

like This

像这样

<IfModule mime_module>
   AddType text/html .php .phps
</IfModule>

see this tutorial install Apache and php

请参阅本教程安装 Apache 和 php

and install Apache and php

安装 Apache 和 php

回答by Savan Koradia

I solved this problem by re-installing httpd & php both. Then php file was executing.

我通过重新安装 httpd 和 php 解决了这个问题。然后php文件正在执行。

回答by peter

Apparently, PHP is installed as a package, but interpreted through a module for apache: viz; mod_php. That is a bit of conjecture, I just discovered it for a way to embed HTML.

显然,PHP 是作为一个包安装的,但通过 apache 的一个模块进行解释:即;mod_php。这有点猜想,我只是发现它是一种嵌入 HTML 的方法。