php not working on ubuntu 18.04
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).
Related videos on Youtube
pravin poudel
Don't treat everyone like they are doing well like you :)
Updated on September 18, 2022Comments
-
pravin poudel over 1 year
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 ...
-
Michal Przybylowicz over 4 yearsWhat server do You use (nginx, apache)? Easiest way is to go to the dir
/var/www/html/
and start build-in php server byphp -S localhost:80
? -
pravin poudel over 4 yearsi am using apache
-
-
pravin poudel over 4 yearsthanks for helping sir !!! it truly worked ... i am new on understanding ubuntu (linux) ... i am just trying to learn linux . I switched from windows to ubuntu . could you please explain me what did i just do ? and what solved the problem !!! again thanks for helping me out ...
-
Hi-Angel over 4 years@pravinpoudel as I said in the answer, apache does not know what to do with
.php
files by default, so it simply presents their content to you when you go to a "php page". What this answer does is basically telling apache that it has to preprocess.php
file withphp
, and then to display the output ofphp
execution (which is the html page). -
txducker almost 4 yearsThis worked for me on debian 10. PHP or Apache crashed the webserver. I did not need to edit /etc/apache2/apache2.conf and did not need that "SetHandler" statement for apache2 to work. Thanks!
-
Ibrahim.H almost 3 yearsGot the error:
Function not implemented: could not create accept mutex AH00015: Unable to open logs Action 'start' failed.
must re-enablempm_event
otherwiseapache2
won't start! and still doesn't parse*.php
files!