Score:1

index.php displays as listing on Apache2 server

ca flag

My OS is Ubuntu 22.04

I started out by installing php 8.1

I then installed Apache/2.4.52 (Ubuntu) Server

Then I added the following:

sudo apt-get install -y php php-cli php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-bcmath libapache2-mod-php

The command: php -v, produces:

PHP 8.1.2-1ubuntu2.8 (cli) (built: Nov  2 2022 13:35:25) (NTS)

Then I modified:

/etc/apache2/mods-enabled/dir.conf: DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

I restarted the apache2 server.

I added an index.php file, but when I try to go to the web page, I only see the listing of index.php

<?php
echo 'This is a test';

I also have an index.html file in there:

<h1>This is a test</h1>

When I delete index.php, and I go back to the web page, I see

This is a test

In a large bold font, as expected.

The PHP manual (as well as the answer I found on this site) refers to an httpd.conf file, and wants me to add:

LoadModule php_module modules/libphp.so

but I don't have an httpd.conf on Ubuntu 22.04, I have an apache2.conf in the /etc/apaache2 folder, which is a skeleton file that loads everything from various subfolders.

When I tried:

sudo a2enmod php

I got:

ERROR: Module php does not exist!

Any ideas?

Edit:

I did:

cd /etc/apache2
grep -R php

And this is what I got:

sites-available/default-ssl.conf:       <FilesMatch "\.(cgi|shtml|phtml|php)$">
sites-available/default-ssl.conf.original:      <FilesMatch "\.(cgi|shtml|phtml|php)$">
mods-enabled/dir.conf:  DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
mods-available/dir.conf:    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

And doing:

sudo a2enmod php8.1

Produces the same error:

ERROR: Module php8.1 does not exist!

And grep'ing for the installed packages, I get:

libapache2-mod-php8.1/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed,automatic]
libapache2-mod-php/jammy,now 2:8.1+92ubuntu1 all [installed]
php-bcmath/jammy,now 2:8.1+92ubuntu1 all [installed]
php-cli/jammy,now 2:8.1+92ubuntu1 all [installed]
php-common/jammy,now 2:92ubuntu1 all [installed]
php-curl/jammy,now 2:8.1+92ubuntu1 all [installed]
php-gd/jammy,now 2:8.1+92ubuntu1 all [installed]
php-mbstring/jammy,now 2:8.1+92ubuntu1 all [installed]
php-mysql/jammy,now 2:8.1+92ubuntu1 all [installed]
php-xml/jammy,now 2:8.1+92ubuntu1 all [installed]
php-zip/jammy,now 2:8.1+92ubuntu1 all [installed]
php8.1-bcmath/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-cli/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-common/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-curl/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-gd/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-mbstring/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-mysql/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-opcache/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed,automatic]
php8.1-readline/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed,automatic]
php8.1-xml/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-zip/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 all [installed,automatic]
php/jammy,now 2:8.1+92ubuntu1 all [installed]
jabbson avatar
sb flag
can you show the outputs of `ls -la /etc/apache2/mods-available/ | grep php` as well as `sudo a2enmod php8.1`
ca flag
Please see edits to my question. I had already tried grep.
jabbson avatar
sb flag
you didn't execute the first command, the whole thing is one command, don't break it into pieces `ls -la /etc/apache2/mods-available/ | grep php`
ca flag
Your command tried to search for the word php in a single folder /etc/apache2/mods-available. The command I use searched for the word php in the entire /etc/apache2 folder and all its subfolders. Your command returns nothing.
jabbson avatar
sb flag
Only mine was to find files (alternatively `find /etc/apache2/ -name "*php*"`) and yours is to find text in files, right? Are you sure that the `libapache2-mod-php` package installed successfully? Because it doesn't look like you have php in mods-available, which you should.
ca flag
Yes, the command ran fine. I can also run php programs directly from that serve's command line and process MySQL data from a remote server, using PHP's MySQli.
jabbson avatar
sb flag
just to be on the safe side of things, can you show `apt list --installed | grep php` output?
ca flag
It's telling me the packages are installed. Please see edits.
jabbson avatar
sb flag
This is going to sounds a bit desperate, but since the files do not exist in `/etc/apache2/mods-available` (for whatever reason), try to uninstall the packages with `sudo apt purge libapache2-mod-php*` (with asterisk at the end) and then install again with `sudo apt install libapache2-mod-php libapache2-mod-php8.1` (leave both names in place) and see if you get the files back.
ca flag
You don't really need to do it twice. This is php 8.1, and ubuntu 22.04, so you can skip the 8.1, and the system knows what to do. My next step was going to be uninstall php altogether and then re-install from scratch.
jabbson avatar
sb flag
Did you try and it didn't work or you just discarded the idea?
ca flag
I mean that I already tried this and it did not work.
I sit in a Tesla and translated this thread with Ai:

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.