Newer versions of PHP will disable PHP from working in user's public_html
directories.
Find which file needs editing: ls -l /etc/apache*/mods-enabled/*php*.conf
It should result in a specific file pointed by the symbolic link (e.g., /etc/apache2/mods-available/php7.4.conf
).
Inside that file, locate a section that looks like this:
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_flag engine Off
</Directory>
</IfModule>
And comment out the section that turns of PHP.
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
# <IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>
#</IfModule>
Then, restart the web server:
sudo apachectl restart
Looks like this happened to me a while back in late 2017, too.