# php, apache, and permissions

## BoBB

Im trying to get php to create a file in a sub directory of htdocs, the directory is owned by apache.apache and has permissions 755. No matter what I set the permissions to php cant create a file, anywhere within the htdocs directory or sub directories, does anyone know how I can change/fix this?

----------

## slartibartfasz

please provide the php error msg and anything relevant u find in the apache logs.

----------

## BoBB

The error message is pretty straight forward, it says i dont have permission to write to that file, which doesnt exist, trying to fopen() it

Warning: fopen(/home/httpd/htdocs/movies/graphics/poster/13.jpg): failed to open stream: Permission denied in /home/httpd/htdocs/movies/add_frame.phtml on line 84

permissions on htdocs and movies and subdirs of that are currently

drwxr-xr-x    3 bob      apache       4.0K Oct 11 21:20 movies/

drwxr-xr-x   16 bob      apache       4.0K Oct 11 21:20 htdocs/

I can read the directories just fine, and I can write to them outside of the script, but im sure there is something special I need to do to allowe php to write to those directories, if anyone can help please pelase please do  :Smile: 

----------

## professorn

Which are the permission for the folder/file?

----------

## BoBB

They are all the same

----------

## slartibartfasz

 *BoBB wrote:*   

> 
> 
> permissions on htdocs and movies and subdirs of that are currently
> 
> drwxr-xr-x    3 bob      apache       4.0K Oct 11 21:20 movies/
> ...

 

the php gets executed as user/group apache - but the owner of the dir is bob and the group is apache - so the group rights on the dir are 'r-x' which is obviously not enough to write to it. do 'chmod g+w htdocs' and it should work

----------

## professorn

1. Sorry, didn't see the part in your post where you hade posted the permissions

2. Another way to solve the problem is to change group owner to "apache" and add the users you want to be able to write files in "htdocs" to "apache" too

----------

## BoBB

I knew there was someththing stupid i was forgetting, thats what sleep deprivation yields  :Razz:  Thanks a bunch  :Smile: 

----------

## slartibartfasz

 *BoBB wrote:*   

> I knew there was someththing stupid i was forgetting, thats what sleep deprivation yields 

 

hehe - yeah - i had my share of it too   :Rolling Eyes: 

----------

## HeXiLeD

[SOLVED]

I had similar problem and chmod/chown the files and directories did not help

```
 php warning fopen failed to open stream
```

In the same box i had 2 mediawikis. 

One other box with 2 mediawikis too.

For both boxes: 

Both which it own domain

Both installed the same way under different users 

Both with the same set of permissions

I only had this error in one for the domains/user and not the other one which had no apache/php permissions set to try to override this behaviour.

I tried to apply new permissions as suggested and the problem remained.

However i noticed that the user/domain who did not have this error; also did not have the directory /tmp

Deleting /tmp from mediawiki solved the problem without any extra needs.

The only question now i have is if that directory is really needed.

Additional notes: user/domain without this issue does not have uploaded files onto the wiki.

```
MediaWiki   1.18.2

PHP   5.3.10-pl0-gentoo (apache2handler)

MySQL   5.1.61-log
```

----------

