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]