Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-21-2008, 08:01 AM   #1
Registered: May 2004
Location: India
Distribution: Ubuntu 9.04, Debian Lenny
Posts: 121

Rep: Reputation: 22
why .php files cant be opened in browser......

when we write a php file and save it in apache web folder it works well....
If it is outside the apache it doesnt works ...why?
Old 05-21-2008, 08:50 AM   #2
Registered: Feb 2004
Location: Upstate NY
Distribution: Slackware
Posts: 79

Rep: Reputation: 15
Keep in mind that it is Apache that is loading the php module(s) that will interpret and present content to your browser. A browser alone most likely wont know what to do with a php file.
Old 05-21-2008, 09:24 AM   #3
Registered: Jul 2006
Location: Italy
Distribution: Ubuntu 11.04, Debian, OS X
Posts: 71

Rep: Reputation: 16
It's exatly what happens if you try to open a bash script in your favourite editor: the script won't be executed, you'll just be able to edit it.
Old 05-21-2008, 09:30 AM   #4
LQ 5k Club
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2017 CentOS6.9 CentOS7.4 + 50+ other Linux OS, for test only.
Posts: 16,746

Rep: Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319
1)Some php files can be opened with a browser by renaming : mv 'file.php' 'file.html'
2)Opera is known to open some php files.
Old 05-21-2008, 12:08 PM   #5
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 31
Originally Posted by knudfl View Post
1)Some php files can be opened with a browser by renaming : mv 'file.php' 'file.html'
2)Opera is known to open some php files.
I think what the OP is referring to is that directly opening a .php file in a web browser gives you the PHP code, not the page as it looks when you request it from the server. Renaming or using Opera won't help with that.

Long story short, when you request a .php page through a web server, you're not seeing the .php file - you're seeing the output of an executed PHP program. When you request the file from Apache, it sees that the file is a PHP script, runs it through the PHP interpreter, and sends you the output. When you open the file in your browser, or request it from a server that doesn't have PHP installed, it's just treated as yet another text file. So it never actually gets executed and hence does not "work".
Old 05-24-2008, 03:38 PM   #6
Registered: Mar 2007
Distribution: Hardy (Gnome on Ubuntu 8.04) on Compaq N600c laptop
Posts: 323

Rep: Reputation: 30
Not sure what "it works" means or in what program or context it "works". But if not working means that visiting that page doesn't produce the expected output, perhaps www-data doesn't have execute or other necessary privileges on files "outside the apache."


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find out the number of files currently opened closet geek Linux - Kernel 5 05-19-2015 09:19 AM
how to know the files and directories which are opened? sridhar_yerram Linux - Newbie 1 01-11-2008 03:59 AM
apache logs files can't be opened? benrose111488 Linux - Software 14 06-26-2007 01:54 PM
Browser trys to download php files Sp@rticus Linux - Software 17 01-31-2006 05:28 AM
can a kconqueror browser be opened from a netscape window in client side cybercop12us Linux - Newbie 2 10-15-2001 07:19 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:06 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration