Strange error with folder permissions (mkdir) - php

I am running a nginx server and php5, but I am not able to get mkdir in php working. I always get a permission denied error.
The user, who is running nginx is www in group www, the same applies for php and my folder where I want to create a new one is also hold by www.
It only works when I set the folder permissions to 777, with 775 I can't get it working.
The curious thing is, when I try to create a folder in the terminal as www user it works without any issues.
Any help would be really appreciated, because I have been struggling with this error for 2 days.

That's probably because problem with PHP module configuration. You have to set correct user there, too.
Check this documentation.

Related

php functions file_exits, copy, shell_exec not working on one machine but same code working on different machine

I am a Centos 7 machine on which I have configured PHP with Apache and Slim Framework.
The simple code to check if the file exists and copy the code into a directory is working fine on one of the machine but not working on another machine. Its really weird.
Actually I am accessing the API through Apache to trigger this function.
Functions like shell_exec alaways return 0
copy function is also not workingg
file_exists also not working.
Any help or clue why this is wrong or debug this issue.
Thanks all for the help.
Problem was file permission issue.
The reason was all of the above function I was performing was on the file. Since the files has different permission for different user.
So If I hit the URL from browser it was through "Apache" user which does not have execute permission on the folder to access the file and read permission on the file.
In short
sudo chmod +rx file
sudo chmod +x "All the directory structure"

Yii - Application runtime path "{path}" is not valid. Please make sure it is a directory writable by the Web server process

I'm very new to Yii, so please bear with me. I've an existing XAMPP setup on my MacBook, and an existing project I need to take a look at. At first the project was looking for a yii.php, so I downloaded the appropriate version (1.1.17), and extracted that to /htdocs/.
I renamed it to yii, and set the yii directory in my index.php to:
$yii=dirname(__FILE__).'/../../yii/framework/yii.php';
For reference, the project has the following directory: htdocs/cdforum/web/index.php
With everything in place, or so I think, I started up XAMPP, and loaded http://localhost/cdforum/web/index.php only to encounter the following error:
throw new CException(Yii::t('yii','Application runtime path "{path}"
is not valid. Please make sure it is a directory writable by the Web
server process.'
I have seen some people get past this by setting the yii folder's ownership via chown to their own, or apache, but the first option didn't work for me, and apache apparently is an illegal user name.
Anything else I can try?
Change your username:group in httpd.conf file of Apache:
About line ~181-182:
To your user in your Mac.
Don't change the Apache User and Group. There are very good reasons why Apache has it's own user and group. Here's a simple example of what can go wrong...
While developing you make a mistake in your app and delete files
recursively in a directory, this directory has a sym link that you
follow into your home directory and you delete everything in your home
directory. This cannot happen if the users are different.
In production if you changed the owner of the user/group to a real user account the you'd almost certainly incur the wrath of the OPS department ie you're creating a security hole, a bad one.
The correct thing to do is to do what it asks ie make the directory writable by the apache process ie use chown or chmod. If you are developing then use this, in production this is also bad...
chmod 777 ./path/to/directory
In prod the directories apache need to write to would either have group write permissions for the apache user or be be owned by the apache user. Only those directories that it requires write access to, nothing else.

Server unable to read htaccess file

Hosted a new website. But when ever I open my website in the browser it is throwing the below error. Tried changing the .htaccess ReWriteRule but could not resolve it.
You don't have permission to access / on this server. Server unable to
read htaccess file, denying access to be safe Additionally, a 403
Forbidden error was encountered while trying to use an ErrorDocument
to handle the request.
This most likely means that apache doesn't have permission to read the directory where your .htaccess is located. Check the permissions on the folder where the file is located.
Ok, so I was facing this issue as well. Now keep in mind, the location of my application was a folder being shared with the Guest OS. Now what I had forgotten to do is to check, and make sure all permissions were enabled on said file on the HostOS.
So what I recommend is that you check the file permissions on the HostOS. Might be nothing you did, just something you forgot to do. Here is a screen shot of what I'm talking about.
Correct file permissions on left, zend skeleton displaying on right
I was unable to restart apache using my ID. So I restarted it using root user and hence this error. Later I changed access permission of httpd folder to 755 and restarted using my ID. The issue was resolved.
hello I think you have some problem with permission like it's was mentioned on your hosting you will find some number near your file like 755 those are the privilege of your file if there wasn't on that number 7 maybe 5 or 4 change it to 7 and like that your application could get the access and lunch your application

Can't mkdir or open files on server, even with 777 permissions

I see that similar questions have been answered on Stack Overflow, but the solutions haven't fixed my particular problem, so I have to ask...
I have an app that needs to make directories and modify files outside the site directory. This works find on the production server.
After spinning up a test server with the exact same version of Ubuntu and PHP, I'm getting errors on the staging server when it tries to open files or create directories.
Here are the errors:
mkdir() [http://php.net/function.mkdir]: Permission denied
fopen(/root/Dropbox/Backend/Booth-01/settings.sh) [http://php.net/function.fopen]: failed to open stream: Permission denied
Things I have tried:
checking the username running the application (it's www-data)
changing the owner of the external directory recursively to www-data
changing permissions on the directory to 777 (I know, this is a bad idea, but I was just trying it to see if that would help until I figured out what the issue was and will change the permissions to something more restrictive once I get it working)
checking the umask value. It was set to 0002, which shouldn't give me problems. Just for kicks, I tried changing it to 0000 and it didn't help.
checking to make sure PHP's safe mode wasn't enabled.
checking to make sure that nothing was specified in open_basedir. In any case, if that was the issue, it would throw a different error message.
I can't think of what to try next and I'm hoping that someone else is seeing something that I'm not.
Ubuntu 12.04.5 x64
PHP 5.3.10
It's not only the folder itself you have to have permissions on. You should also check the parent folders. I think, if you check this, this will fix your problem.
If this is an external drive (see if it shows up in mount) then you may have to remount it. An auto-mounted external drive can thwart permissions
sudo umount <moint-point>
sudo mount /dev/<device> <new-moint-point>

PHP and Permissions

I recently moved my website to a new host and now am experiencing some broken code..
I have an uploading script that is now returning this:
move_uploaded_file() failed to open
stream: Permission denied in *..
I've set the upload directory to 777 which worked fine, but my script is needed to have top level permissions..
(As the script itself sets permission to directories, does lots of copying etc)
Is there a way in apache I can set the PHP script to the owner of all the folders on my server?
Thanks
Also
When looking in phpInfo()
Under
apache2handler
User/Group nobody(99)/99
Is this related?
I wouldn't go that route, just give it permissions to the defined upload_tmp_dir, or define upload_tmp_dir to be a directory you have access to. If it is that directory you have problems with. If the target is the problem, and you've 777'ed it, something fishy is going on.
Do you have ssh access to your new host? The reason I ask is that it's probably not best to use the username/group as nobody, as most other services would use this too. I would change it to something like apache
You can then update httpd.conf, adding in these two lines (reloading the config after):
User apache
Group apache
Then, run chown apache:apache -R dir_name to make apache own it.
well,
When you are trying to set the permission like "0777", you must be running on same authority.
What I mean is.
For example, your script tells to change a folder/file permission to 0777, but the folder or file already has a permission and that is '0755' so you are not authorised to make that change. as the user have only 5 authority.
Either, you need to login to FTP and change the folder permission to 0777 and then you have full control over it or you have to stick with using 0755 or similar.

Categories