Page 1 of 1

Browser Downloads .php Files Instead of Displaying

PostPosted: 29. April 2016 18:22
by miss9
I'm running Linux Mint 17.20 32-bit as a guest on VirtualBox. Host machine is Windows 10. After downloading Xampp for Linux and starting up the Apache server, I am still unable to make .php files run. I tried testing that PHP was correctly installed by opening the htdocs/index.php in my browser, but my browser (latest FireFox & Opera) tries to download the document instead. I've also tried creating a test.php file in my system's var/www directory, and then directing my browser to that directory, but it says the file does not exist. I've tried installing Xampp/PHP two different ways now: downloading straight from Apache Friends site and installing apache & php packages via command line. What could possibly be wrong? How do I get .php files to render on my browser?

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 30. April 2016 05:28
by Altrea
How exactly did you try to "open" the file in your browser?
Which URL did you use to test the dashboard and your own file?

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 30. April 2016 05:32
by miss9
http://localhost/test.php typed in the browser. I also tried changing the file permissions as well.

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 30. April 2016 10:48
by Nobbie
What happens when you simply enter http://localhost in your browser? You may also simply click on that link.

Also, your description contains a certain contradiction, on the hand you say, that you opened "htdocs/index.php" in your browser, on the other hand, you say that you entered http://localhost/index.php in your browser. Which of these two is correct?

Also confusing is this one:

miss9 wrote:and then directing my browser to that directory


What do you mean by "directing" your browser to that directory?? There is no way to open files in /var/www with Xampp Apache configuration.

Finally, in which environment did you install Xampp (in Windows10 or in Linux Mint?) and in which environment did you run the browser?

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 30. April 2016 14:26
by miss9
http://localhost takes me to a welcome to Xampp-Apache Friends page.

Sorry, yes, initially I was opening the htdocs/index.php file through the directory, selecting Firefox to open it with, which caused the download. But I later realized that was wrong (after my OP). Anyway, when I directly type in localhost/index.php the page is not found (though Apache IS up & running with no errors and index.php IS located in htdocs directory).

In my last comment I'm actually referring to the test.php file which I created after my second attempt at installing Apache/PHP (which I mentioned in my OP, but I see now I probably wasn't very clear). I put the test.php file (which just calls for the php version) in the var/www directory. After realizing I couldn't open the php file by double clicking it, I tried directing my browser to its location, localhost/test.php which also didn't work. It couldn't find the file, even though the file is there and again, Apache is up & running with no errors.

Finally, Xampp is installed in Linux Mint and the browsers were run in the Linux Mint environment. Thanks!

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 01. May 2016 14:55
by Nobbie
miss9 wrote:http://localhost takes me to a welcome to Xampp-Apache Friends page.


That means, PHP and everyting else is running perfectly.


miss9 wrote:Anyway, when I directly type in localhost/index.php the page is not found (though Apache IS up & running with no errors and index.php IS located in htdocs directory).


No, and no, and no! This simply CANNOT be true. Because the Xampp Welcome Page (it is called "dashboard") works only and only if index.php is working, because the index,php installed by Xampp redirects to the dashboard ("Welcome Page") and NOTHING ELSE!

I dont know, what you are doing actually, and i also dont know, what you are doing wrong. But i definately DO NOT believe in your error description, as you would not see any Welcome Page if loading of localhost/index.php fails!

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 01. May 2016 18:12
by miss9
I know! It's why it's been driving me crazy because I kmoq it should work. Later when I'm infront of my computer I'll see if I can get some screenshots. Thank you for your help so far.

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 02. May 2016 18:02
by miss9
I figured it out. As I went to go get some screenshots today, I realized I had placed test.php in the wrong folder. The tutorials I had followed had me place it in var/www instead of var/www/html. When I put it in var/www/html is works just fine. I think it's really weird that the tutorials didn't specify this...maybe they were outdated, or maybe I'm still doing something wrong. Maybe there's a way to designate var/www as the default location for localhost? I don't know, but at least it's working. Thanks for your help anyway @Nobbie.

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 02. May 2016 18:37
by Nobbie
miss9 wrote:When I put it in var/www/html is works just fine. I think it's really weird that the tutorials didn't specify this


"Weird" is, that you definately do NOT work with Xampp. I dont know if you even installed it, but you definately do NOT use it. Xampp is installed into /opt, the files are installed into /opt/lampp/htdocs. You are working with a standard Linux installation, you never started Xampp, you never saw a "Xampp" Welcome screen (i do not believe into your description, in fact you never ever have seen a "Xampp" welcome page). You never ever started Xampps Apache.

Forget about Xampp, forget everything you are thinking about Xampp: you dont use it!!

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 02. May 2016 18:46
by miss9
I did. In fact, I uninstalled/reinstalled it a few times before I even thought to look for a tuturial on the standard Apache/PHP installation. I even ran into the issue of having to change the port the Xampp Apache was using, via Xampp, so that it wouldn't interfere with my standard installation. I just reinstalled Xampp (after uninstalling it for the 100th time) and ran it again. Localhost got me the Xampp page. But still couldn't "find" the test.php file (which I had made a copy of and put in htdocs directory). I cleared my browser's cache and now it works. At least it all works now, but I still don't know exactly what I was doing wrong before.

Re: Browser Downloads .php Files Instead of Displaying

PostPosted: 02. May 2016 21:08
by Nobbie
miss9 wrote:At least it all works now, but I still don't know exactly what I was doing wrong before.


And i still dont know what you are doing and at least i dont know, which Apache you are running. I give up.