PHP apache2 LAMP 啟用 mod php 後停止運作
P粉627427202
P粉627427202 2024-01-10 17:40:23
0
1
439

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

sudo a2enmod rewrite
sudo systemctl restart apache2

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

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中的目錄-

<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 檔案-

<label>hey hey hey</label>
<?php
echo "bla bla bla";
?>

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

<label>hey hey hey</label>
<?php
echo "bla bla bla";
?>

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

這是會議-

<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 部分解決了我的問題-

a2enmod php8.2

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

P粉627427202
P粉627427202

全部回覆(1)
P粉677684876

我想你的libapache2似乎遺失了:

嘗試:

apt-get install libapache2-mod-php  -y

隨後:

sudo systemctl restart apache2
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!