Linux 瀏覽器下訪問 localhost/index.php,文件中的 php 代碼被註釋

index.php

<html>
<body>
<?php  echo 'a'; ?>
</body>
</html>

打開瀏覽器後,在控制檯看到的是 (並未執行 php 代碼)

<html>
<body>
<!--?php  echo 'a'; ?-->
</body>
</html>

實質上這是在 httpd.conf 配置不全的問題

vi /etc/httpd/conf/httpd.conf // 具體目錄看實際情況,可用 find / -name httpd.conf 查找
/AddType // 找到 addtype 具體位置

在原本 AddType 後加上

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php3
    AddType application/x-httpd-php .html  // 這個可以忽略
systemctl restart httpd // 重啓 apache

再訪問 localhost/index.php 就可以了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章