首页  >  问答  >  正文

PHP apache2 LAMP 启用 mod php 后停止工作

在启用 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粉627427202P粉627427202257 天前422

全部回复(1)我来回复

  • P粉677684876

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

    我想你的libapache2似乎丢失了:

    尝试:

    apt-get install libapache2-mod-php  -y

    随后:

    sudo systemctl restart apache2

    回复
    0
  • 取消回复