PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 19th, 2010, 09:17 AM
agent47 agent47 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 161 agent47 User rank is Corporal (100 - 500 Reputation Level)agent47 User rank is Corporal (100 - 500 Reputation Level)agent47 User rank is Corporal (100 - 500 Reputation Level)agent47 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 15 h 42 m 16 sec
Reputation Power: 10
PHP5 - File_put_contents not working

I have a number of php scripts that use file_put_contents to create very basic text files.

These php scripts have been copied to a brand new dedicated server I am leasing and now they no longer seem to work.

Should I be checking permissions or php.ini or something else?

I am at a standstill with this and appreciate any points in the right direction.

Reply With Quote
  #2  
Old October 19th, 2010, 09:30 AM
simshaun's Avatar
simshaun simshaun is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2008
Location: North Carolina
Posts: 2,674 simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)  Folding Points: 59700 Folding Title: Beginner FolderFolding Points: 59700 Folding Title: Beginner FolderFolding Points: 59700 Folding Title: Beginner Folder
Time spent in forums: 4 Weeks 1 Day 20 h 35 m 37 sec
Reputation Power: 2673
Are the folders that you are saving the files to writable? (Try to CHMOD the folder to 0755, and if that doesnt work, 777. It depends on the server setup.)

Reply With Quote
  #3  
Old October 19th, 2010, 09:52 AM
agent47 agent47 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 161 agent47 User rank is Corporal (100 - 500 Reputation Level)agent47 User rank is Corporal (100 - 500 Reputation Level)agent47 User rank is Corporal (100 - 500 Reputation Level)agent47 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 15 h 42 m 16 sec
Reputation Power: 10
Quote:
Originally Posted by simshaun
Are the folders that you are saving the files to writable? (Try to CHMOD the folder to 0755, and if that doesnt work, 777. It depends on the server setup.)


Does it make sense that my old server had these files and folders at 0755 with no problem but this one seems to require 777?

Is there something I can change in my php.ini so that files that come from the old server will still work in this new environment?

Thanks in advance!

Reply With Quote
  #4  
Old October 19th, 2010, 10:10 AM
simshaun's Avatar
simshaun simshaun is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2008
Location: North Carolina
Posts: 2,674 simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)  Folding Points: 59700 Folding Title: Beginner FolderFolding Points: 59700 Folding Title: Beginner FolderFolding Points: 59700 Folding Title: Beginner Folder
Time spent in forums: 4 Weeks 1 Day 20 h 35 m 37 sec
Reputation Power: 2673
Quote:
Does it make sense that my old server had these files and folders at 0755 with no problem but this one seems to require 777?
Yes, since the server setup is different. Whether or not you need 755 or 777 is dependent on how Apache is setup and what modules you have installed.

Without getting too involved (I will if you ask), the folders on your new server are probably owned by a specific user (e.g. "johndoe"), whereas Apache is running as the user "nobody" or something similar. The easy way of allowing Apache to write data to the folder owned by johndoe is to chmod it to world writable (777).

Reply With Quote
  #5  
Old October 19th, 2010, 10:18 AM
agent47 agent47 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 161 agent47 User rank is Corporal (100 - 500 Reputation Level)agent47 User rank is Corporal (100 - 500 Reputation Level)agent47 User rank is Corporal (100 - 500 Reputation Level)agent47 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 15 h 42 m 16 sec
Reputation Power: 10
Feel free to get involved (or point me towards a link or article that does).

Should I be concerned about opening up my folders with a 777 permission?

Thanks for all your help so far!

Reply With Quote
  #6  
Old October 19th, 2010, 11:12 AM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 43 m 47 sec
Reputation Power: 7053
Quote:
Should I be concerned about opening up my folders with a 777 permission?

On a dedicated server not so much.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #7  
Old October 19th, 2010, 11:30 AM
simshaun's Avatar
simshaun simshaun is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2008
Location: North Carolina
Posts: 2,674 simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)simshaun User rank is General 25th Grade (Above 100000 Reputation Level)  Folding Points: 59700 Folding Title: Beginner FolderFolding Points: 59700 Folding Title: Beginner FolderFolding Points: 59700 Folding Title: Beginner Folder
Time spent in forums: 4 Weeks 1 Day 20 h 35 m 37 sec
Reputation Power: 2673
Being on a dedicated server, it's less of a risk.

Every folder and file on a Linux system has an owner. You can see this by logging in using a decent FTP client (FileZilla) or by cd'ing to your webroot and running ls -l (lowercase L) through the shell.

When you create or upload files, they are owned by whatever user you are logged in as. When logged in via the FTP user johndoe, files are going to be owned by johndoe. If you create a folder via FTP, its going to be owned by johndoe.

This is where things start to branch based on how Apache is configured.

- In a basic Apache setup (no additional modules that affect security), Apache typically runs as a "nobody" user and in a "nobody" group. This is important to know if PHP is running as an Apache module because it means that any file uploaded through PHP is going to be owned by the "nobody" user.

When you login to FTP as "johndoe", you won't be able to change or delete these files, since they are set to 644 and you don't own them. All you would be able to do is read them (which is what the last 4 means). The files must be CHMOD'd by PHP to 777 (typically after being uploaded) in order for you to rename or delete them via FTP.

- PHP can be installed as a CGI module, rather than being ran as an Apache module. In this instance, PHP can be ran as its own user/group. In these situations, many hosts typically resort to an Apache module such as phpSuExec or suPHP. These modules allow PHP to run with the same permissions as the hosting account.

In this manner, any files uploaded via PHP are owned by johndoe, the same as if you uploaded them yourself via PHP. At the same time, it also means that your files and directories no longer have to be world writable for PHP to write to them.

In fact, modules such as suPHP prohibit files/folders that are world writable (777). It will throw a 500 Internal Server error when you try to execute them.

I'm sure I'm missing a lot, but that should be enough to cover what you're wanting to know (I hope.)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - File_put_contents not working

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap