duanhui5344 2013-06-19 07:56
浏览 48
已采纳

Apache:内联PHP无法在Linux上运行

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:

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.

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.

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(); ?>

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?

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?


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.

  • 写回答

3条回答 默认 最新

  • dreljie602951 2013-06-19 12:22
    关注

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

    Change the extension to .php.

    Php can contain html.

    Edit: 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵