0

can't get PHP running on apache, having run these commands to set up apache with php

I have an ubuntu machine, and have been trying to get PHP running..

As you can see the PHP isn't running

root@ubuntu:/etc/apache2# cat /var/www/html/index.php
<?php
echo 4+3;
?>
xyz
root@ubuntu:/etc/apache2#

root@ubuntu:/etc/apache2# curl 127.0.0.1/index.php <?php echo 4+3; ?> xyz root@ubuntu:/etc/apache2#

I tried apt-get update , apt-get upgrade, apt-get purge apache2 , apt-get install apache2, apt-get install php libapache2-mod-php , systemctl restart apache2

Still same result.

barlop
  • 125
  • 1
  • 9
  • What's the result? What version of Ubuntu are you running? At a glance, I would question whether Apache is configured to default to .php instead of the default .html –  Jan 03 '21 at 15:56
  • @Matigo can't you see the curl command I showed there? It references index.php – barlop Jan 03 '21 at 16:01

1 Answers1

1

PHP must be enabled in Apache. Run

sudo a2enmod php7.4  # or whatever version of libapache2-mod-php7.X is installed

and restart Apache.

FedKad
  • 10,515
  • 1
    thanks.. that gave ERROR: Module php7 does not exist! but combined with https://askubuntu.com/questions/912638/error-module-php7-0-does-not-exist Rodgers-Ategyeka's answer of apt-get install libapache2-mod-php7.4 worked. – barlop Jan 03 '21 at 19:30
  • 1
    strange that quite a few webpages on installing php on ubuntu don't mention that a2enmod e.g. .https://linuxize.com/post/how-to-install-php-on-ubuntu-18-04/ or https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04 Maybe it's a newer thing? – barlop Jan 03 '21 at 19:49
  • @barlop looks like by default php enables itself(tested on fresh ubuntu installation) so it's a mystery what disabled it but that command enables it. – barlop Jan 08 '21 at 22:28