Page 1 of 1

PHP scripts don"t work in Xampp

PostPosted: 27. July 2021 11:31
by mateic_09
Hello!
I installed yesterday Xampp 8.0.8 on Linux.I made a PHP script in /opt/lampp/htdocs named q.php ,but it doesn't run.Instead of this,the file is downloaded in Downloads.
Please help me!

Re: PHP scripts don"t work in Xampp

PostPosted: 27. July 2021 16:37
by Nobbie
PHP Scripts work, i think you are doing anything wrong.

How do you start your PHP Script? Explain precisely, what you are doing. Do you start your browser or do you simply double click on the filename in an Explorer or what are you doing? And what do you enter into the Browsers URL Bar, if you started it before?

Can you start http://localhost on your PC? Do you see the so called "dashboard"? If yes, PHP runs fine, as this is already a PHP script.

Re: PHP scripts don"t work in Xampp

PostPosted: 27. July 2021 17:33
by mateic_09
Yes, I can start the localhost.I usually start the apache server. After that ,I write /opt/lampp/htdocs in the url bar of Chrome and press on the script I want to execute .Something odd is that even the PHP file preinstalled index.php doesn't run .Maybe I didn,t configure well the server.

Re: PHP scripts don"t work in Xampp

PostPosted: 27. July 2021 20:15
by Altrea
Ever typed in a file path to access google? No.
You cannot just type in a file path into your browsers address bar and expect that the browser knows, that this file need to get send through and php interpreter and where it can find this interpreter.

PHP files need to get requested from the server xampp is running on, like every other ressource on the internet.
For that the domain http://localhost/ exists. With that you can request files from your own computer.

http://localhost/ is mapped to /opt/lampp/htdocs/
http://localhost/foldernamexy/fileyz.php is mapped to /opt/lampp/htdocs/foldernamexy/fileyz.php
and so on.

Re: PHP scripts don"t work in Xampp

PostPosted: 27. July 2021 20:18
by Nobbie
mateic_09 wrote:After that ,I write /opt/lampp/htdocs in the url bar of Chrome and press on the script I want to execute


Actually its exactly what i thought. You are doing a severe error. You MUST NOT enter the local path to your scripts, you MUST enter the fully qualified URL to a webserver. And fully qualified URLs are starting with the protocoll, which is http: in your case, followed by the servername (domain name), which is "localhost" in your case.

Finally, you have to enter http://localhost/q.php into your browser in order to start your PHP script via your Apache webserver. if you simply enter /opt/lampp/htdocs/q.php, your script is NOT delivered and executed by your Apache server (and the built in PHP interpreter), but solely by your browser, which does not know anything about PHP. Therefore the browser simply downloads the source code, without knowing anything about it.

I recommend reading tutorials about webservers and how things are working, that may help you in understanding how webservers are working.

Re: PHP scripts don"t work in Xampp

PostPosted: 27. July 2021 20:49
by mateic_09
You are right.Thanks!