PHP files displayed as text
Solution 1:
Usually, when I do installations of apache and PHP on ubuntu it works for me seamlessly but this time I had to use this before my PHP files stopped appearing as plaintext.
sudo apt install libapache2-mod-php7.4
Solution 2:
There are a couple of reasons why your PHP may not get interpreted.
- You may not have the PHP module for Apache installed or running.
To check the PHP packages installed, type: dpkg -l | grep php
To check which apache modules are installed, type: a2query -m
. There should be a PHP module listed and it should be enabled.
You should see libapache2-mod-php
listed among the packages. It could be named libapache2-mod-php7.2
or something similar to match your version of PHP.
If it is not present, you will have to install it.
- Apache may need to be configured to execute .php files. To quickly check your Apache configuration, type:
grep -r php /etc/apache2/*
.
You should see SetHandler application/x-httpd-php
somewhere, and be sure it is not commented.