PHP scripts don"t work in Xampp

Problems with the Linux version of XAMPP, questions, comments, and anything related.

PHP scripts don"t work in Xampp

Postby mateic_09 » 27. July 2021 11:31

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!
mateic_09
 
Posts: 5
Joined: 27. July 2021 11:14
XAMPP version: 8.0.8
Operating System: linux

Re: PHP scripts don"t work in Xampp

Postby Nobbie » 27. July 2021 16:37

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.
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Re: PHP scripts don"t work in Xampp

Postby mateic_09 » 27. July 2021 17:33

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.
mateic_09
 
Posts: 5
Joined: 27. July 2021 11:14
XAMPP version: 8.0.8
Operating System: linux

Re: PHP scripts don"t work in Xampp

Postby Altrea » 27. July 2021 20:15

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.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: PHP scripts don"t work in Xampp

Postby Nobbie » 27. July 2021 20:18

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.
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Re: PHP scripts don"t work in Xampp

Postby mateic_09 » 27. July 2021 20:49

You are right.Thanks!
mateic_09
 
Posts: 5
Joined: 27. July 2021 11:14
XAMPP version: 8.0.8
Operating System: linux


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 58 guests