Portal Home > Knowledgebase > Articles Database > PHP Include
|Posted by ManXP, 06-25-2007, 07:21 AM|
I have some problems using include function on all my servers. For example, there is a file (file.php) on website1.com which looks like:
As you see, it just includes content from file of other account.
Now if I enter cronjob "php -q /home/website1/public_html/file.php", I get this warning from cron:
Warning: main(/home/other_account/public_html/file.php) [function.main]: failed to open stream: Permission denied in /home/website1/public_html/file.php
php open_dir protection and safe mode is DISABLED on server, and if I open website1.com/file.php from browser, erverything is just fine - file from other account is included very well and no errors are displayed. Why I get these errors fropm cron then?
|Posted by theBleeber, 06-25-2007, 07:26 AM|
|I am surprised that it works either way but the reason its not working from cron is you are likely running it as one of the account owners. They personally cannot travel into the other users directory.
|Posted by ManXP, 06-25-2007, 07:28 AM|
|Is it possible to overcome this somehow? I have 100+ websites on server and all these sites use exactly same files, so I want just to place main files on single account and then include these files from other websites (because it really takes lots of time to re-upload files to 100+ websites after making some changes)
|Posted by Mxhub, 06-25-2007, 07:29 AM|
|wrong path been use.
if it is user account 'user1'
make sure the script is using correct path with 'user1' , not any obsolete old username.
|Posted by ManXP, 06-25-2007, 07:33 AM|
|MxHub - actually, I do not want to include file from same user, I want to include file from other user.
I just placed PHP files with functions on "/home/other_account/public_html/file.php" and then I simply call from ALL other accounts.
Like I said, everything works fine via browser, but now via PHP cron itself.
|Posted by Engelmacher, 06-25-2007, 11:01 AM|
|Put your files somewhere outside any user's document root and include from there. I have a "global_includes" directory for exactly this purpose.
|Posted by ManXP, 06-25-2007, 11:08 AM|
|Engelmacher - nice tip, I'll try it.
But I'm really interested why oh why file gives no errors when launched via browser. I believe there is something wrong in my php configuration then?
|Posted by Engelmacher, 06-25-2007, 11:20 AM|
|I imagine there are a lot of things wrong with both your code and your understanding of the Unix permissions model. What's in this cron job and who is running it?
|Posted by Codelphious, 06-26-2007, 12:23 AM|
|PHP is executing the script as nobody since it is being fetched through http, anyone can access files (that have read permission set) in the public_html directory.
My guess is, your cron configuration is set to run crons called by their owner *only*.
You have 2 possible solutions:
1. Change the permissions on file.php to owned by "nobody".
chown nobody file.php
2. Or set your cron to be called using wget() instead.
Add to Favourites Print this Article
PHP Mail Help (Views: 247)
Cloud Hosting (Views: 261)