Apache:内联PHP在Linux上不起作用 [英] Apache: Inline PHP not working on Linux

查看:78
本文介绍了Apache:内联PHP在Linux上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让PHP在我的Apache服务器上工作.我正在运行Oracle Linux,并使用yum install php + yum install httpd来获取我的PHP和Apache.我搜寻了互联网并做了几件事:

I am having trouble getting my PHP to work for my Apache server. I am running Oracle Linux, and used yum install php + yum install httpd to get my PHP and Apache. I have scoured the internet and done a couple of things:

首先,我进入了httpd.conf文件并添加了LoadModule php5_module modules/libphp5.so.我选择在我的php.conf文件中使用一个,这是完全相同的一个.此外,我已经完成了AddType application/x-http-php .php,所以现在我的.php文件可以正常加载.

Firstly, I have gone into my httpd.conf file and added LoadModule php5_module modules/libphp5.so. I have chosen to use the one in my php.conf file, which is the exact same one. Furthermore, I have done AddType application/x-http-php .php, so now my .php files are loading fine.

其次,我尝试运行我的Apache服务器,并且运行正常.它显示了我用DirectoryIndex设置的index.html文件.但是,当我尝试将php代码放入其中时,它会自动注释掉,我认为这是因为我没有将其设置为在服务器端正确执行.

Secondly, I have tried to run my Apache server, and it works fine. It displays my index.html file, which I set with DirectoryIndex. However, when I tried to put php code into it, it got automatically commented out, which I assume is because I haven't set it to properly execute on the server side.

现在,话虽如此,我想知道我还可能缺少什么.我有两个设置,一个在其中有一个.php文件,另一个在php与html内联的地方.

Now, with all that said, I am wondering what else I may be missing. I have two set-ups, one where I have a .php file, and one where the php is inline with the html.

index.html

<!DOCTYPE html>
    <body>
        <?php echo "Hello everybody."; ?>
    </body>
</html>

index.php

<?php phpinfo(); ?>

index.php文件可以很好地加载,但是index.html不会运行php代码.如何使内联版本的php工作?

The index.php file loads fine, but the index.html doesn't run the php code. How do I get the inlined version of php to work?

注意::我已经设置Mac OS可以正常处理.php文件,但是在Html文件中使用内联php也遇到了麻烦.我想念什么?

Note: I have set-up my Mac OS to work fine with .php files, but it is also having trouble with inline php within an Html file. What am I missing?

解决方案: html文件本身不能包含php.相反,该文件必须是.php扩展名,并且在.php文件中,您可以具有文本,html和JavaScript.

SOLUTION: Html files themselves cannot include php. Instead, the file must be a .php extension, and within a .php file, you can have text, html, and JavaScript.

推荐答案

我认为.html文件根本不通过php运行,所以< ;? ...?>被视为不可见的普通标签.

I do not think .html files are run through php at all so the <? ... ?> is treated as a normal tag which is invisible.

将扩展名更改为.php.

Change the extension to .php.

Php可以包含h​​tml.

Php can contain html.

如果您出于某种原因不能或不想使用php结尾,则可以配置一个选项,例如将Apache配置为将html文件解析为php.

There exists an option to configure for example Apache to parse html files as if they are php if you for some reason cannot or do not want to use php endings.

我认为,这不是一个好的解决方案,因为它掩盖了页面对于将来的维护者而言是动态的.

This, in my opinion, is not a good solution as it hides the fact that the page is dynamic to a future maintainer.

这篇关于Apache:内联PHP在Linux上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆