php not working on ubuntu 18.04

12,570

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):

  1. 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>
    
  2. run sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7.0 (replace php7.0 with whatever version you has)
  3. Restart apache2 with sudo systemctl restart apache2 (or just reboot, because if wordpress is using local version of apache2, systemctl obviously won't work).
Share:
12,570

Related videos on Youtube

pravin poudel
Author by

pravin poudel

Don't treat everyone like they are doing well like you :)

Updated on September 18, 2022

Comments

  • pravin poudel
    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

    enter image description here.

    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
      Michal Przybylowicz over 4 years
      What server do You use (nginx, apache)? Easiest way is to go to the dir /var/www/html/ and start build-in php server by php -S localhost:80 ?
    • pravin poudel
      pravin poudel over 4 years
      i am using apache
  • pravin poudel
    pravin poudel over 4 years
    thanks 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
    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 with php, and then to display the output of php execution (which is the html page).
  • txducker
    txducker almost 4 years
    This 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
    Ibrahim.H almost 3 years
    Got the error: Function not implemented: could not create accept mutex AH00015: Unable to open logs Action 'start' failed. must re-enable mpm_event otherwise apache2 won't start! and still doesn't parse *.php files!