在自动创建的目录上写入文件的权限问题

I'm trying to add generated config files into an automatic generated directory. I'm using PHP 5.4, Apache and Debian 7.8 on this virutal box.

So, as i said in topic, i have no problems, to create new directories, but when i'm trying to add files into this fresh generated directory, it won't work (Warning: fopen (PATH) failed to open stream: Permission denied in (FreshGeneratedDirectoryPath)). I'm curios, because if permissions are really bad, why the apache process is able to create a directory, but no file inside? I mean, he's the owner from the directory.

How i create my directory:

mkdir(PROJECT_PATH . '/tmp/' . session_id(), 0777);

I've tried with the mods 0755, 0775, 0777, 1755, 1775, 1777 so far.

And how i try to create files:

fopen(PROJECT_PATH . '/tmp/' . session_id() . '/' . $configType . '.conf', "wb");

I've tried "a" instead "wb", but that changes nothing.