Apache server running html code but not recognizing php code [duplicate] - php

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 3 years ago.
I just started to learn php. I am using lubuntu and that's why I don't want to install xampp, wamp, or similar programs because I have very limited resources.
I installed Apache server and php 7, which seems to be working fine because I can execute and visualize html code via localhost. The problem is when I run php code the web page shows blank. How can I fix this issue?
I have only one file on /var/www/html which is called index.php and can be visualize on localhost/index.php
php -v
php 7.2.19-0ubuntu0.18.10.1
apache2 -v
Server version: Apache/2.4.34 (Ubuntu)
The code I have on index.php is this:
<!DOCTYPE html>
<html>
<body>
something
<?php
echo "hello world";
?>
</body>
</html>
On localhost/index.php it only shows "something", which means apache server is running correctly and runs html code but I don't know why php doesn't run. If Instead I just run a file with php code like
<? php
phpinfo();
?>
it only shows a blank page.

If you see a blank page then normally something else is blowing up behind the scene. I suggest you check both Apache and PHP error logs. Normally you would find both in /var/log/*
It could very well be permission related or a module missing.

Related

php file isn't working properly, I can't open it on browser, it opens the text editer instead [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
So I'm just starting to learn php, and when trying " Hello World" the file isn't executing properly. I have Bitnami MAMP Stack 5.6.31 .
I'm pretty sure it's not something wrong with the code, possibly with the install of the AMP stack, but this is the code anyway :
<?php echo "Hello World"; ?>
You can't just "open" PHP files on XAMPP/MAMP/LAMPP/etc.
Make sure your apache service is started in your MAMP console
Make sure your file is saved in the document root of MAMP, which by default is 'MAMP/htdocs'
If your file, say is stored like this: 'MAMP/htdocs/learningPHP/hello.php' then you would go to your web browser and type in localhost/learningPHP/hello.php
The script will then run.

php loop is not working in a .php file [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
I am trying to create a php loop as follows:
<?php
for ($i= 0; $i < 18; $i++)
{
echo "hello World";
echo "</br>";
}
?>
when I run it I get this as an output:
"; } ?>
However when I used http://www.writephponline.com/ I get the expected output.
I'm using notepad++ and chrome. The file has a .php ext.
Is there something missing?
Surely it is a silly mistake but can't figure it out. I appreciate your help.
You need to be running a web server with php installed. You appear to be loading the file directly from a server with no php installed, or as a file directly, without a server.
Your file is being interpreted as HTML not PHP
you are missing the php interpreter....
As you are using windows, you can take a look to WAMP to setup a working php enviroment http://www.wampserver.com/en/
browser can't run your php code.
here is a way that you could run your php code :
1. open terminal
2. go to the directory where your file exist
3. type this command "php -S localhost:8000"
now open your browser and goto http://localhost:8000/YOUR_FILE_NAME.php" or just http://localhost:8000/ if the file name is index.php
NOTE : you should have php installed in your computer

embedding php in html using apache on a raspberrypi [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
I am pretty new at this so please bear with me.
I have a raspberrypi that I am trying to set up as a server to remotely monitor with. I cannot seem to get php embedded in html to work. My simple code is:
<!DOCTYPE html>
<head>
<title>A test</title>
</head>
<body>
<?php echo "hello world"; ?>
hello joe -----
</body>
</html>
When I access the server on the Pi from my laptop what I see in the browser is the 'hello joe-----' but not the 'hello world'. when I turn on the F12 debugger window it tells me html:1406 invalid tag start: ?> question marks do not start tags.
When I execute a similar file directly from the command line on the Pi in a terminal window [e.g. php5 test.php] it seems to run fine.
Could this be a php configuration issue?
thx
What official guide would that be?
In any event I solved the problem. I purged php5 from the Pi and reinstalled. That seems to have fixed it. Now it all works.

Echo doesn't print what I want on the browser [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
Simple, I had a html that echo from php (saven in .php) but not even a simpe code as
<?php echo"ggg"; ?>
works, I tried with xammp and Wamp either chrome and firefox but doesn't work.
What can I do?
edit: already solved, I forgot to run it from localhost, thank you all.
Any of these (or more) could be your answer why it is not working
Is there actually PHP running on your computer? Check it with <?php echo phpinfo(); ?>
Are you accesing the file through your browser doing something like http://localhost/myfile.php
If it is on a remote server, is there PHP installed?
https://stackoverflow.com/a/43129028/2151290
Put your file inside c:/xampp/htdocs for xampp or c:/wamp/www for wamp
// Note that drive name may vary depending where you install c: or d:

issue with PHP on IIS 7.5

So I've done a bunch of research and tried a bunch of things that it'll be difficult to try and explain everything i've already done but here's my issue.
My website isn't interpreting PHP code, whether I try to use an include 'file.php'; or just input the code directly into the HTML it doesn't matter.
I'm running Windows 7 with IIS 7.5 with PHP installed from php.iis.net. I'm going to keep it simple rather than go into the specifics of exactly what I'm trying to do, and hopefully once I get the simple things working the more complex stuff I'm working on will work.
Here's the HTML piece:
Weather condition is currently <?php echo '<p>Hello world</p>'; ?>
The output is
Weather condition is currently Hello world '; ?>
The beginning bracket of the PHP is hidden, after World its showing the rest on a new line under the text.
I also have
<?php
phpinfo();
phpinfo(INFO_MODULES);
?>
That returns nothing on the webpage, and if you look at the source code you see the full PHP code. Same with the Hello world example, the text doesn't show the ?php portion but viewing the page source you see the full php.
There's something I'm missing somewhere in the IIS config or the PHP config and I'm just not finding it.
Any insights or ideas I'm open to try. This is a fresh IIS and fresh PHP install, I installed IIS on this workstation specifically to get this PHP script to work so it is doing nothing else but hosting this web page.
thanks!

Categories