2

I installed php services and Apache2 on my raspberry pi without errors. But, when I opened a browser and entered my page URL, it wrote

<?php echo "Hello";?>

instead of Hello.

I have tried reinstalling and have checked that the Apache PHP module is installed and enabled with a2enmod, the script runs fine when run directly with php on the terminal.

Anyone know how to fix that? Thanks for any help

Roger Jones
1,4848 silver badges14 bronze badges
asked Feb 24, 2019 at 17:35
4
  • 1
    What web server are you using and what's the name of the file containing your PHP script? You may need to configure your web server to execute the file with php and send the output to the browser rather than send the contents to the browser as-is. Commented Feb 24, 2019 at 18:13
  • webserver is apache2 and how can i configure webserver? Name of file is index.php Commented Feb 24, 2019 at 18:22
  • 1
    Can you add the extra information to your question about using Apache2, confirming the libapache2-mod-php is installed and configured and that you can run the script from the terminal without errors. Maybe also add the installation steps you've followed to get to this point? Commented Feb 26, 2019 at 11:28
  • If i knew how to confirm it, i would do it Commented Feb 26, 2019 at 18:38

2 Answers 2

1

Fact assumption table Fact assumption table

Solution 1

Try your script without the tags. It's possible that Apache automatically runs the script through PHP only and not HTML with PHP. This will mean that it sees echo 'Hello' only if it understands the rest of the code. If it is only running PHP it might not understand the tags and just print out the whole thing. There's a slim chance but try it out just in case. See if that will help.

Solution 2

Your web browser may not support PHP. You should check what web browser you're using. If you're using Midori, it might not support it. Try doing this on a different device and accessing another browser like Google Chrome.

Solution 3

Make sure that your file extension is not .txt - This might be the reason for it not seeing and not compiling your code.

Solution 4

Taken from this stackoverflow question

Make sure that Apache's httpd.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php . This tells Apache to run .php files as PHP.

IF ALL ELSE FAILS, TRY TO USE PHP WITH A DIFFERENT COMPILER.

Possible links that may help:

Another stack overflow question . PHP.net . If your HTTPS.config file is wrong

I hope this helps.

Regards

answered Feb 27, 2019 at 14:17
15
  • At first i wanna say thanks for help, and for the second none of solutions helped, i removed php tags and tried on other browsers and different devices and it showed echo "Hello"; istead of Hello Commented Feb 27, 2019 at 18:54
  • This seems like a problem for Apache and not Raspberry Pi then, here are some links for a question that is similar: stackoverflow.com/questions/5121495/… ••• Here's another link as well: php.net/install Commented Feb 27, 2019 at 19:09
  • I know that too, but that page didnt helped me Commented Feb 27, 2019 at 19:38
  • Ok, I'll sketch up a fact - assumption sheet and get back to you soon Commented Feb 27, 2019 at 20:03
  • P.S. is it possible that the file extension is not .php? That could be the cause of all this. Commented Feb 27, 2019 at 20:08
0

I reinstalled the whole RPI and installed all things again, not sure what caused the problem but it worked

answered Jul 3, 2020 at 18:59
1
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. Commented Jul 10, 2020 at 9:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.