Home  >  Q&A  >  body text

PHP apache2 LAMP stopped working after enabling mod php

Before enabling the mod, PHP was working fine. I'm trying to use the rewrite mod. I enabled mods-

sudo a2enmod rewrite
sudo systemctl restart apache2

Also restarted apache and restarted the computer. This is my htaccess file-

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]

This is the directory I added to the 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>

This is my php file-

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

When I run this command in the browser page, the result is -

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

It seems that the php code is not read by the php preprocessor and served directly to the browser. Additionally, I had adjacent folders with php code that also stopped working, not just the folder with the htaccess file. What could be the problem? Any ideas?

This is a meeting-

<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

renew

I partially solved my problem by enabling php -

a2enmod php8.2

Now php is working fine. JavaScript works fine. CSS, on the other hand, doesn't work. The file is available and served, but no effect is visible.

P粉627427202P粉627427202306 days ago467

reply all(1)I'll reply

  • P粉677684876

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

    I think your libapache2 seems to be missing:

    try:

    apt-get install libapache2-mod-php  -y

    Then:

    sudo systemctl restart apache2

    reply
    0
  • Cancelreply