LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 09-03-2008, 02:05 PM   #1
Snouser
LQ Newbie
 
Registered: Feb 2006
Posts: 21

Rep: Reputation: 15
Why doesn't chmod -R 777 works?


I've a script that's suppose to change somethins in a folder.
The only problem is that the script don't 've writing wrtites to the folder.

Just to be clear.

First I've a .sh file thats start when the computer goes on. The script look like this.

Code:
while true; do
/var/www/script/script.php
sleep 60
done
It runs the script every 60 sec.
The script it self starts with this line:
#!/usr/bin/php5

Does this mean that the php5 binary runs the script?

The problem is that none of the scripts 've writing writes to the folder.

I've tried to chmod -R 777 on the folder, but it doesn't mater.

What rights should I give the folder?
 
Old 09-03-2008, 02:29 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 31
Looks like you're trying to run shell code through the php interpreter which won't work.
Try replacing the #!/usr/bin/php5 with
Quote:
#!/usr/bin/sh
or
#!/usr/bin/bash
Also, why not use cron to run your script every 60 seconds?
 
Old 09-03-2008, 02:46 PM   #3
Snouser
LQ Newbie
 
Registered: Feb 2006
Posts: 21

Original Poster
Rep: Reputation: 15
Thanks for the replay.

I just notest that when the user www-data (apache2) creates a folder, then the php5 binary can't write to it. So I've to manual run chmod -R 777 on the folder.

How do I change the rights so that php5 can write to a folder apache has created? Is it possible to add them to the same grope, how if so?

OffT: Why I don't use cron is because the cript doesn't take <60 sec to run so if I run is as cron more then one script will be running at the same time. With my solution it will wait 60 seconds after it's finish. Maybe there is a better way, but this works fine for now.

EDIT: The script I'm trying to run is written in php. So the top line should be correct. If I run the script as root in a terminal it works perfect.

Last edited by Snouser; 09-03-2008 at 02:54 PM.
 
Old 09-04-2008, 02:15 AM   #4
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,895

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
Since it's a shell script it should start with
Code:
#!/bin/sh
or whatever your shell is.
Now to run the php script from inside the shell script you should use the php command:
Code:
php /var/www/script/script.php
You can su to www-data before running the command above, or you can chown/chmod the folder created.
 
Old 09-04-2008, 03:04 AM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
To solve permissions problems, you need to know:

1) the UID/GID of the process that wants access
2) the UID, GID, and permissions of the file/directory that (1) will be accessing

Please provide answers to (1) and (2).
 
Old 09-04-2008, 03:10 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,482

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Php being an interpreter like shells are and php accepting # as a comment character, I think it is valid to insert the following header to a php source file in order to have it being a php executable:
Code:
#!/usr/bin/php5
 
Old 09-04-2008, 03:43 AM   #7
John VV
Guru
 
Registered: Aug 2005
Posts: 12,665

Rep: Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683
you Never,Never,never chmod -r 777 www-data (apache2) you just gave EVERY PERSON ON THE WEB FULL READ/WRIGHT/EXECUTE PERMISION to your server .
 
Old 09-04-2008, 03:55 AM   #8
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Quote:
Originally Posted by John VV View Post
you Never,Never,never chmod -r 777 www-data (apache2)you just gave EVERY PERSON ON THE WEB FULL READ/WRIGHT/EXECUTE PERMISION to your server .
And what permissions do you advise for web applications that upload data? Apache needs write permission for such activities.

Access controls are generally used at a higher layer, but the underlying file system permissions must be set such that the web server can write if writing is to be allowed..
 
Old 09-04-2008, 10:59 AM   #9
John VV
Guru
 
Registered: Aug 2005
Posts: 12,665

Rep: Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683
chown -R apache:apache www-data
chmod -R 755 www-data
 
Old 09-04-2008, 05:39 PM   #10
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
John VV - since you've given apache ownership to the files/directories, you get exactly the behavior you said to avoid in post #7. Removing group write permission here serves no purpose with respect to apache, as it already owns the files so group ownership is unimportant. Removing access for Other users only prevents LOCAL users from making changes to the files.

Thus, your suggested permissions and ownership do not meet your stated criteria.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
chmod 777 and 7777 presarioch Linux - Newbie 4 06-17-2008 01:24 PM
chmod 777 664 zerocool22 Linux - Server 7 06-03-2008 06:58 AM
Is it safe to chmod 777 Navaboy Slackware 4 03-24-2005 06:54 AM
CHMOD in shell : chmod 777 /usr/ <---is that right? cpanelskindepot Programming 5 07-16-2004 05:37 AM
chmod 777 /* ziggamon Linux - Newbie 2 09-25-2003 11:40 AM


All times are GMT -5. The time now is 07:35 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