"Warning: mkdir(): Permission denied in" while running as owner of parent - php

I'm running this script:
$dir = 'images';
if (!file_exists($dir) ) {
mkdir ($dir, 0644);
}
It returns this error:
Warning: mkdir(): Permission denied in
/opt/bitnami/apache2/htdocs/file.php on line xx.
Apperently i do not have the rights to create the folder. I found the following:
htdocs has chmod set to 755
The owner of htdocs is daemon (lrwxrwxrwx 1 daemon daemon 27 Aug 1 12:16 htdocs -> /opt/bitnami/apache2/htdocs)
I created a file with php while temp. using chmod 777 and then used this script: https://stackoverflow.com/a/7771686/1139465 to figure out the owner, that was daemon (Array ( [name] => daemon [passwd] => x [uid] => 1 [gid] => 1 [gecos] => daemon [dir] => /usr/sbin [shell] => /bin/sh ) done)
I have an intallation of the Bitnami LAMP solution.

Related

Permission denied when moving file

I am trying to move file to another folder but it gives Permission denied error. Here is the permission of that files.
-rwxrwxrwx 1 root www-data 394 Oct 11 14:40 namechange.xml*
-rwxrwxrwx 1 root www-data 395 Oct 11 14:40 namechange1.xml*
-rwxrwxrwx 1 root www-data 345 Oct 11 14:40 roomchange.xml*
and here id the code that I used to move files
rename("resources/xml_checkin/namechange.xml", "resources/xml_checkout/test.xml")
;
Follow these steps:
Please open your terminal
Login with ssh
locate to the destination file using cd /var/www/html
Give permission to the particular folder using command chmod -R 777 path/folder or command chmod -R 777 path/filename
First try to change the chmod to 775, if it doesn't work then use 777
then try to move your files and see the result.
If issue persists again, let me know.

PHP Exec sudo mount throwing fancy error message

I'm using Centos7 OS, I have this script that mount a folder from windows PC
exec('sudo mount -t cifs -o username="'.$user.'",password="'.$pass.'",dir_mode=0777,file_mode=0777
//'.$ip_address.'/c/kitpos/update /mnt 2>&1', $output, $results);
And I got this fancy error message that looks like a permission issue.
Array
(
[0] =>
[1] => We trust you have received the usual lecture from the local System
[2] => Administrator. It usually boils down to these three things:
[3] =>
[4] => #1) Respect the privacy of others.
[5] => #2) Think before you type.
[6] => #3) With great power comes great responsibility.
[7] =>
[8] => sudo: no tty present and no askpass program specified
)
My /mnt folder ownership and permission is root and 777 but even if I change it www-data:www-data which is my php running as, still got the same error.
777 drwxrwxrwx 2 root root 4096 mnt
I also have an Ubuntu server but it works fine in their with that same code. Does anyone have an Idea?

PHP doesnt have permission to change file name

I want to change file name in subdirectory under /usr/local/MyFolder/overlay.png to overlay2.png with php, but php raises Permission below Error:
( [type] => 2 [message] => rename(/usr/local/MyFolder/content/overlay.png,/usr/local/MyFolder/overlay2.png): Permission denied [file] => /var/www/html/2.php [line] => 6 )
How to solve it?
RUn the following command from Terminal:
You can get to the terminal by Pressing Ctrl+alt+T on your keyboard
Run the following code:
sudo chmod 777 "/usr/local/MyFolder/"
sudo chmod 777 "/usr/local/MyFolder/content/"
Now your script should have permissions to access those folders
Mind you, doing these gives permission to everyone and every programs to access and modify things in the folders above

move_uploaded_file reported that I haven't permission to move (PHP)

I have a script that handle uploading some files in "upload" directory.
So, in case of uploading I got that error:
move_uploaded_file(/var/www/some_dir/upload/8phMPmnoXOI.jpg): failed to open stream: Permission denied
my apache2 runs under www-data user (OS ubuntu linux).
#id www-data
uid=33(www-data) gid=1000(ubuntu) groups=1000(ubuntu),33(www-data)
#ls -la | grep upload
drwxrwxr-x 2 ubuntu ubuntu 4096 Apr 29 18:30 upload
If I try to "touch" new file into this directory it works!
Why I can't write to writeable directory?
P.S. chmod -R 777 upload resolves that problem, but I want to ubuntu:ubuntu owns upload directory.

Is_writeable fails but I am the owner

I have the below code running and will give the CHMOD and CHOWN values below. But for some reason is_writable keeps failing.
if (!is_writeable($this->path)) {
echo 'Current script owner: ' . get_current_user();
echo '<br />';
echo $this->path;
echo '<br />';
print_r(posix_getpwuid(fileowner($this->path)));
}
The CHMOD values of the directory is 775 and the owner is User1. The output from above is
Current script owner: User1
path/to/directory
Array ( [name] => User1 [passwd] => x [uid] => 111 [gid] => 111 [gecos] => [dir] =>
/path/to/user [shell] => /bin/false )
The only thing that doesn't match is the owner / group of the file is 111/1 so the groups might be different but the owner is identical.
Why would is_writeable fail?
Are you the owner or the webserver?
Everything you execute with the webserver should run as www, _www or www-data (depending on the configuration; default values for different OS). So the webserver user is not in your group which causes that the file is not writeable by the webserver.
(P.s.: get_current_user() is the script owner (e.g. what you set by chown), not the script running user. Current script running user data: var_dump(posix_getpwuid(posix_getuid()));)

Categories