-1

PHP was working fine before enabling mods. I was trying to use rewrite mods. I enabled mods with-

sudo a2enmod rewrite
sudo systemctl restart apache2

Also restarted apache also restarted 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=$1 [L,QSA]

This is directory I added to 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 in browser page Result is -

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

It appears php code is not read by php preprocessor and directly served to browser. Also I have adjuscent folders with php code they have also stopped working not just the one with htaccess file. What might be the problem? Any ideas?

Here is conf-

<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

Update

I partially resolved my problem by enabling php with-

a2enmod php8.2

Now php is working fine. Javascript is working fine. CSS on the other hand is not working. Files are available and served but no effect can be seen.

8
  • Paste the entire .conf Commented Jun 6, 2023 at 12:34
  • TEST1: Rename your .htaccess file. Does PHP start working again? Commented Jun 6, 2023 at 13:51
  • NOTE: You might like to start using Apache 2.4 syntax, the 2.2 syntax you are using is bound to be removed soon I mean Order allow,deny allow from all which should be Require all granted in Apache 2.4 syntax Commented Jun 6, 2023 at 13:52
  • @RiggsFolly Php is not working even if I rename .htaccess. I think I broke something in apache but don't know what is problem. Commented Jun 7, 2023 at 5:10
  • @SachinBahukhandi Conf file is added. Commented Jun 7, 2023 at 5:29

1 Answer 1

0

I suppose your libapache2 seems to be missing:

Try:

apt-get install libapache2-mod-php  -y

Followed by:

sudo systemctl restart apache2
Sign up to request clarification or add additional context in comments.

4 Comments

No it is showing already installed
What's the php -v for your project?
originally php7.4 now php 8.2. All basic php code so versions should not make any difference.
Okay so it works for you now. Ideally what I can guess is libapache2-mod-php -y would install the ext for you with the current version php-cli.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.