搜尋

首頁  >  問答  >  主體

PHP apache2 LAMP 啟用 mod php 後停止運作

在啟用 mod 之前,PHP 工作正常。我試圖使用重寫模組。 我啟用了 mods-

1

2

sudo a2enmod rewrite

sudo systemctl restart apache2

也重新啟動了apache也重新啟動了電腦。 這是我的 htaccess 檔案-

1

2

3

4

5

6

7

8

RewriteEngine On

 

#Accept loading of actual files and folders

RewriteCond %{REQUEST_FILENAME}% !-f

RewriteCond %{REQUEST_FILENAME}% !-d

 

#send everything else to index page

RewriteRule ^(.*)$ index.php?url= [L,QSA]

這是我加入conf中的目錄-

1

2

3

4

5

6

7

8

9

10

11

12

<Directory /var/www/html/folderwithhtaccessfile>

                    Options Indexes FollowSymLinks MultiViews

                    AllowOverride All

                    Order allow,deny

                    allow from all

    </Directory>

    <Directory /var/www/html/otherfolder>

                    Options Indexes FollowSymLinks

                    AllowOverride None

                    Order allow,deny

                    allow from all

    </Directory>

這是我的 php 檔案-

1

2

3

4

<label>hey hey hey</label>

<?php

echo "bla bla bla";

?>

當我在瀏覽器頁面中執行此命令時,結果是 -

1

2

3

4

<label>hey hey hey</label>

<?php

echo "bla bla bla";

?>

看來 php 程式碼沒有被 php 預處理器讀取並直接提供給瀏覽器。另外,我還有一個帶有 php 程式碼的相鄰資料夾,它們也停止工作,而不僅僅是帶有 htaccess 檔案的資料夾。可能是什麼問題?有什麼想法嗎?

這是會議-

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

<VirtualHost *:80>

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/html

 

    <Directory /var/www/html/folderwithhtaccessfile>

                    Options Indexes FollowSymLinks MultiViews

                    AllowOverride All

                    Order allow,deny

                    allow from all

    </Directory>

    <Directory /var/www/html/otherfolder>

                    Options Indexes FollowSymLinks

                    AllowOverride None

                    Order allow,deny

                    allow from all

    </Directory>

 

 

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

 

</VirtualHost>

 

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

更新

我透過啟用 php 部分解決了我的問題-

1

a2enmod php8.2

現在 php 工作正常了。 JavaScript 運作良好。另一方面,CSS 不起作用。文件可用並已提供,但看不到任何效果。

P粉627427202P粉627427202445 天前583

全部回覆(1)我來回復

  • P粉677684876

    P粉6776848762024-01-11 11:49:35

    我想你的libapache2似乎遺失了:

    嘗試:

    1

    apt-get install libapache2-mod-php  -y

    隨後:

    1

    sudo systemctl restart apache2

    回覆
    0
  • 取消回覆