10

I have a php script uploading files to a certain folder, currently they are uploading as a 'psacln' group, so that I can delete the files via FTP. This was all working fine when PHP was running as FastCGI, I had to change PHP to run as Apache Module in order to get a php extension to work. But now I can't delete files via PHP script because permission is denied. I assume because now the group 'Apache' is trying to delete the file that belongs to 'psacln'. How do I allow apache to delete those files?

EDIT: ls -alF

drwxr-xr-x   2 fugitiveink psacln 4096 Nov 13 14:05 92/
drwxr-xr-x   2 fugitiveink psacln 4096 Nov 13 06:57 93/
drwxr-xr-x   2 fugitiveink psacln 4096 Nov 13 14:12 95/
drwxr-xr-x   2 fugitiveink psacln 4096 Dec 21 18:56 96/
drwxr-xr-x   2 fugitiveink psacln 4096 Dec 21 08:30 97/
drwxr-xr-x   2 fugitiveink psacln 4096 Nov 13 14:26 98/
drwxr-xr-x   2 fugitiveink psacln 4096 Nov 13 14:28 99/
2
  • at least you have to grant rights to "Apache" group with root / sudo Commented Jan 2, 2013 at 4:05
  • You have to have parent folder to have apache user group and it must be executable. Commented Jan 2, 2013 at 4:40

2 Answers 2

17

I assume that you have shell and root access to this system. If so, you can try adding the apache user (typically apache or www-data) to the /etc/group file.

The proper way to do this is to use usermod, though I typically just edit the file directly.

In short if your apache user is apache, try:

sudo usermod apache --append --groups psacln

This basically gives the apache user access to any files & directories that are owned by the psacln group.

If this doesn't work, post an example of your directory with the file permissions (ls -alF) and we can work from that.

EDIT:

To directly edit the groups file using nano (substitute with whichever editor you're comfortable with):

sudo nano /etc/groups

and find the psacln group and add the apache user:

psacln:x:130:apache

Note that the gid (130) will undoubtedly be different.

Sign up to request clarification or add additional context in comments.

9 Comments

didn't work, php is running as apache:apache getting usermod: user psacln does not exist
What do you get when you run sudo groups psacln? Also can you include the . directory in your directory listing edit.
'id: psacln: No such user'
What flavor of linux are you using?
Linux 2.6.18-028stab092.1 / psa v10.3.1_build1013110726.09 os_CentOS 5
|
-4

Set the permissions on the upload directory to 777 (wrx for all users). Can you still upload new files? If you can, you should be able to delete files.

2 Comments

You need to have recursive permission set up. Parent folder also should have permission.
If you do not share the server with other users, then 777 would be safe permissions. Since you have child directories, they will have to have 777 permission too. chmod -R a+w . from the directory shown. You can always change it back if it does not work. If you add apache to the psacln group you will need to set group write permission, chmod -R g+w .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.