php not working on ubuntu 18.04
I am trying to install wordpress and for that to work i tried to install php and mysql . PHP doesnot seems to be working .
When i write this into /var/www/html/info.php file:
<?php
phpinfo();
?>
localhost/info.php just print out above as a string .Here is an image of output screen of localhost/info.php
.
when i enter php -version command in Terminal , it gives :
PHP 7.2.19-0ubuntu0.18.04.2 (cli) (built: Aug 12 2019 19:34:28) ( NTS
)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.19-0ubuntu0.18.04.2, Copyright (c) 1999-2018,
by Zend Technologies
How can i solve this ?
Thanks in advance ...
Funnily, recently I was having a similar problem after upgrading our mantis + gitlab server at work.
It has nothing to do with php, and in fact you can check that php is working by running php /var/www/html/info.php
. This article says that wordpress is using apache, and apache by default does not recognize php files, i.e. it doesn't know it has to preprocess with php
them before displaying. To fix this I was following this article with small modifications for current ubuntu.
I'll attach the steps at the bottom, but here's a little catch: given apache is not listed in installation requirements for Wordpress, it's possible that Wordpress is using some local version of apache instead of the system one. So you may need to make modifications to steps below, e.g. to find apache2.conf
in the list of wordpress files.
Anyway the steps (that you may want to modify per previous paragraph):
- Edit file
/etc/apache2/apache2.conf
with your favorite editor, and add at the bottom:# enable executing php files <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
- run
sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7.0
(replacephp7.0
with whatever version you has) - Restart apache2 with
sudo systemctl restart apache2
(or just reboot, because if wordpress is using local version of apache2, systemctl obviously won't work).