LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-21-2008, 07:01 AM   #1
jestinjoy
Member
 
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, 07:50 AM   #2
bejiita
Member
 
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, 08:24 AM   #3
lucazorzi
Member
 
Registered: Jul 2006
Location: Italy
Distribution: Ubuntu 11.04, Debian, OS X
Posts: 70

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, 08:30 AM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 13,522

Rep: Reputation: 2503Reputation: 2503Reputation: 2503Reputation: 2503Reputation: 2503Reputation: 2503Reputation: 2503Reputation: 2503Reputation: 2503Reputation: 2503Reputation: 2503
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, 11:08 AM   #5
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 31
Quote:
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, 02:38 PM   #6
lumix
Member
 
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."
 
  


Reply


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
how to know the files and directories which are opened? sridhar_yerram Linux - Newbie 1 01-11-2008 02:59 AM
apache logs files can't be opened? benrose111488 Linux - Software 14 06-26-2007 12:54 PM
Find out the number of files currently opened closet geek Linux - Kernel 4 12-22-2006 01:45 PM
Browser trys to download php files Sp@rticus Linux - Software 17 01-31-2006 04:28 AM
can a kconqueror browser be opened from a netscape window in client side cybercop12us Linux - Newbie 2 10-15-2001 06:19 AM


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

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