If you are first time configuring php on the ubuntu you may see the php code if you open the site. It meant you missed the below module to execute the php code
sudo apt install php8.1 libapache2-mod-php8.1
It depends on the php version. In my case I was using 8.1