Help installing PHP on Ubuntu (Solved. Thank you!)

(I'm currently using Firefox 124.01 on Ubuntu 22.04.03 LTS) (My formatting is also givinge problems... I want to eat my own eyeballs out right now...)

I'm very new to Linux, and trying to get PHP installed, but it won't render anything...

Following this guide (https://ubuntu.com/server/docs/programming-php), I started with:

sudo apt update
sudo apt install apache2

Test Page Success!

So I continue with:

sudo apt install php libapache2-mod-php
sudo apt install php-mysql
sudo apt install php-cgi

Then:

sudo systemctl restart apache2.service

I write the following in /var/www/html/index.php:

<?php

phpinfo();

Test Text1

?>

Test Text2

I see "Test Text2" and nothing else. I see my PHP tags and their contents upon source inspection.

Then I perform the following:

apt list --installed | grep php
sudo apt purge php
apt list --installed | grep php (0 Results)

And try again:

sudo apt install php libapache2-mod-php
sudo apt install php-mysql
sudo apt install php-cgi

sudo systemctl restart apache2.service

No luck... Any ideas what's going on?

A little additional info:

~$ which php
/usr/bin/php
~$ php -v
PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.14, Copyright (c), by Zend Technologies
~$ apt list --installed | grep php

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libapache2-mod-php8.1/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed,automatic]
libapache2-mod-php/jammy,jammy,now 2:8.1+92ubuntu1 all [installed]
php-common/jammy,jammy,now 2:92ubuntu1 all [installed,automatic]
php-mysql/jammy,jammy,now 2:8.1+92ubuntu1 all [installed]
php8.1-cli/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed,automatic]
php8.1-common/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed,automatic]
php8.1-mysql/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed,automatic]
php8.1-opcache/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed,automatic]
php8.1-readline/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed,automatic]
php8.1/jammy-updates,jammy-updates,jammy-security,jammy-security,now 8.1.2-1ubuntu2.14 all [installed,automatic]
php/jammy,jammy,now 2:8.1+92ubuntu1 all [installed]
/etc/apache2/mods-enabled$ ls
access_compat.load  authz_core.load  deflate.load  mime.load         php8.1.load      status.load
alias.conf          authz_host.load  dir.conf      mpm_prefork.conf  reqtimeout.conf
alias.load          authz_user.load  dir.load      mpm_prefork.load  reqtimeout.load
auth_basic.load     autoindex.conf   env.load      negotiation.conf  setenvif.conf
authn_core.load     autoindex.load   filter.load   negotiation.load  setenvif.load
authn_file.load     deflate.conf     mime.conf     php8.1.conf       status.conf
8 points · 14 comments · view on lemmy.world

14 Comments

dbx12@programming.dev · 5 pts · 2y (2 replies)
[ removed ]
GardenVarietyAnxiety@lemmy.world · 2 pts · 2y (1 reply)

I wiped and reinstalled everything php and apache... It still didn't work, so I tried your suggestion and simply put

dbx12@programming.dev · 1 pts · 2y
[ removed ]
sloppy_diffuser@sh.itjust.works · 4 pts · 2y (1 reply)

I don't have a solution, but wanted to comment this is a reason to use docker. Instead of tinkering with your host system in ways you'll probably forget, declare all the steps in a nice containerized system that does one thing: hosts a php website as you develop.

Expose your project through a volume for a mostly seamless file sharing experience between the host and container.

GardenVarietyAnxiety@lemmy.world · 1 pts · 2y

I've seen a lot about docker, and it looks pretty awesome.

I'll definitely get to it eventually, I'm just trying to learn the basics for now.

littleme@infosec.pub · 3 pts · 2y (4 replies)
GardenVarietyAnxiety@lemmy.world · 2 pts · 2y (3 replies)

It returned: Module php8.1 already enabled

onlinepersona@programming.dev · 3 pts · 2y (2 replies)

Was that the output of sudo a2enmod php ?

GardenVarietyAnxiety@lemmy.world · 2 pts · 2y (1 reply)

I wiped and reinstalled everything php and apache... It still didn't work, so I tried to simply put

onlinepersona@programming.dev · 1 pts · 2y

😂 welcome to the wonderful world of computing.

If it shan't dance to your flute, reboot

::: spoiler Anti Commercial AI thingy CC BY-NC-SA 4.0 :::

hitmyspot@aussie.zone · 2 pts · 2y (3 replies)

Have you tried a html file to ensure Apache is ok? Or no files and Apache should show a server page.

Also, the test file can just be

GardenVarietyAnxiety@lemmy.world · 2 pts · 2y (2 replies)

I wiped and reinstalled everything php and apache... It still didn't work, so I tried to simply put

hitmyspot@aussie.zone · 2 pts · 2y (1 reply)

Lol, turn it off and back on!

GardenVarietyAnxiety@lemmy.world · 1 pts · 2y

Basically, lol

raoul@lemmy.sdf.org · 2 pts · 2y (1 reply)

Maybe there is a conflict between libapache2-mod-php and php-cgi?

According to your doc, it seems to be one or the other.

GardenVarietyAnxiety@lemmy.world · 2 pts · 2y

I wiped and reinstalled everything php and apache... It still didn't work, so I tried to simply put