Score:0

PHP has stopped working on Ubuntu and Apache

us flag

I am running Ubuntu 18.04. I have a LAMP setup. At some point, I realized that my PHP was no longer working. I haven't used it for a while, so unfortunately I can't say when it stopped working. It could well have been when I upgraded to Ubuntu 18.04 from 16.04.

I have scoured the Internet looking for answers to the problem and simply haven't been able to get it working. Here's information about the problem and what I have tried:

I reinstalled Apache2. Apache by itself is working, but PHP via Apache is not working: .php files display the code rather than execute it. Or sometimes the .php page is simply blank except for the html on the page. The page with the phpinfo(); function on it is blank.

I am testing by using a .php page with this code:

     <h1>My PHP Info Page</h1>


<?php 

    phpinfo(); 

?> 

I am accessing this page via the Chrome browser: http://localhost/~username/Testing/info.php

Only the phrase "My PHP Info Page" shows up. The rest of the page is blank.

I am using php7.2.

When I type "php -v" in the terminal, I get:

PHP 7.2.24-0ubuntu0.18.04.10 (cli) (built: Oct 25 2021 17:47:59) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.24-0ubuntu0.18.04.10, Copyright (c) 1999-2018, by Zend Technologies

I have run these commands in the terminal at various points:

sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7.2

sudo a2enmod php7.2 sudo a2dismod php7.0 sudo a2dismod php5

I've added the following code to the apache2.conf file:

<FilesMatch ".php$"> SetHandler application/x-httpd-php ​

I then changed it to:

<LocationMatch ".php$"> SetHandler application/x-httpd-php ​

(I then changed it back. Also, per one suggestion somewhere I manually typed this code in rather than copying and pasting it.)

Each time after making any changes to the apache2.config file, I have restarted the Apache service with this command:

sudo systemctl restart apache2

I'm at my wits end. Why is my PHP not working?

Score:0
us flag

I discovered the answer to my problems thanks to the answer to a previous question to this forum. The problem was that I needed to edit the php7.2.config file, which is found in the etc/apache2/mods-enabled folder, to allow me to store all my .php files in the public_html directory in the user (rather than root) space. So it was a permissions issue.

To allow that, you comment out the five lines that begin <IfModule at the end of the php7.2.config file. (You comment out by placing # at the beginning of the line you are commenting out.)

I had done this already several versions of php ago when I installed LAMP on my 16.04 computer. Apparently, it needed to be redone either because of the upgrade to php7.2 or the upgrade to 18.04 or perhaps an upgrade to Apache.

Once I made that change, my PHP was working again. Thanks ASK UBUNTU!

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.