Before you yell DUPLICATE! and banish me into the abyss, hear me out. :)
I've been developing an intranet site for the company I work with, and originally I was developing it directly from my workstation running Windows 7 / IIS. As I've neared completion of the site/applications, I was given a Centos 7 box that's running Apache, so I've begun the process of migrating it over to that system. I've sorted out most of the minor issues, and got the site running now. However, there is a portion of the site that interacts with our database and creates a log directory/file based upon the person that's logged in. This portion utilizes the mkdir() function, but I'm getting permission issues with it.
mkdir(): Permission denied
Here is what I've already done:
- Since I'm using Centos 7, the Apache user/group is apache:apache. I've utilized chown and changed the owner of /var/www/html/ and the Logs folder to the apache user/group. To be on the safe side, I double checked the httpd.conf and also checked the running processes to ensure I had the correct user/group.
- I've attempted, just for testing purposes, to change the permissions of all of those folders to chmod 777, but getting the same error.
- Searched StackOverflow from top to bottom, and only getting answers for things that I've already tried, but to no avail.
So whether I use chmod or chown to change the permissions for the folders being accessed, I'm getting the same type of error. To be on the safe side, I checked the PHP user also, and it's using the apache user as well.
If anyone may have additional insight as to why it isn't working, even with the permissions changed, then please enlighten me. If I happened to miss the one article that explained this particular situation, then yell duplicate and banish me to the abyss. lol :)
EDIT Okay, so upon further testing, I've discovered 2 issues that seem to be causing this overall issue.
- PHP is trying to set permissions for the folder when it's created from the script, and it seems the server doesn't like that even if apache is the owner. Upon removing that portion of the code, the permissions error goes away, and I get an error with "no such file or directory."
- When testing creating directories with the user Apache through sudo, it was able to make a directory without a problem. However, my PHP script is creating 2 directories, and then a log file in the last one created. It seems that you can't create two directories at the same time?? For example, there is a Logs folder already created, and PHP is trying to create two directories under it, one for the user's ID and then another folder inside of that one with the date. So once the PHP script runs, it should create something like "Logs/5235/3-3-2015/"
Just to note, I've attempted to set the recursive value to true on mkdir in PHP, but that's when I get the permission issues originally noted. When recursive/mode is removed, it doesn't get the permission issue, but it isn't able to create nested directories.
EDIT2
To test my theories, I removed the nesting and tried to make mkdir create just 1 directory, and it's generating the same errors as before. Although it's owned by Apache, and even if I set it to 777, it throws back permission issues.