I’ve installed Fedora 35, with Apache, MySQL 7.4 and PHP 8. PHP seems to work from the commandline, but it is not getting displayed within the browser. This code does not display the php info:
from the command line to show all the information, but it does not work either standalone or within html when viewing it in the browser. I tried Chrome with the same result. I’m not sure if it is because of a setting in php.ini.
Have you had a look at tutorials for embedding php in html? Such as this first search hit?
It suggests you need the php tag, <?php phpinfo.php ?>
or instead, browse to phpinfo.php, as the browser then runs your php script.
Following vgaetera’s link, this did not fix the issue. My default directory is /var/www/example_domain, from where HTML can be displayed in a browser but the PHP script does not seem to be executing in a browser.
In /etc/httpd/conf/httpd.conf I have set
I wonder if your setting ServerName 127.0.0.1 may not be contributing to the issue. That will always force the browser to use the loopback address and it could easily interfere. I also have never seen a config where the servername was set to an IP address.
IME it is always best to use the same name as you get with the output of ‘hostname’ and also set the listen address to the actual network IP the server uses. For example, my hostname is eagle and the IP is 192.168.2.111 so that is the ServerName and listen IP used in httpd.conf.
This is, of course, assuming that this is only for the local (primary) server IP and not an aliased (hosted) domain/server name where you may have a machine with multiple IPs and web servers running.
EDIT
I just reviewed the httpd.conf file on my system and I found this as the example.
# ServerName gives the name and port that the server uses to identify itself.
#ServerName www.example.com:80
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on a specific IP address, but note that if
# httpd.service is enabled to run at boot time, the address may not be
# available when the service starts. See the httpd.service(8) man
# page for more information.
#
#Listen 12.34.56.78:80
Listen 80
I reset the ServerName to 192.168.1.64 but ended up re-installing Fedora, generally following the guide at https://computingforgeeks.com/how-to-install-lamp-stack-on-fedora/ , except that I installed MySQL before PHP, and I have it working now. If my index.php page contains
<?php
phpinfo();
?>
and if it is called from the URL line as http://192.168.1.64/index.php or from localhost or from 127.0.0.1 , it pulls up the formatted display. The script does not seem to display if embedded into html, like:
If this not works you have to configure apache that it lets you use .php as your index file. Probably now it is just .htm & .html files allowed. Search for “configure index file for apache” in web.
Adding the DOCTYPE line at the top did not make a difference.
I created a .htaccess file, alternating these 2 lines, which also did not enable the php to be displayed: