Welcome Guest, Not a member yet? Register   Sign In
Message: mkdir(): Permission denied
#11

(09-30-2015, 09:28 AM)jLinux Wrote:
Code:
man chmod
Code:
chmod -R 755 /path/to/folder
or if you're SURE this is ok..

Code:
chmod -R 777 /path/to/folder

I run
Code:
chmod -R 777 /opt/lampp/htdocs/www/my-app/public/uploads

and worked! the script created the posts folder.

However I tried 755 or 775 instead but didn't work, the warning popped up again. Is there a way I can make this work with 755 or 775 permissions, because 777 is not so secure.
Reply
#12

(This post was last modified: 09-30-2015, 11:43 AM by Lykos22.)

Ok, I did
PHP Code:
echo exec('whoami'); 
right bellow my script and I got "daemon", but if I do ls -lah on my models folder the Post_model.php has as user my usrname, i.e. Lykos (!!!)
Reply
#13

(This post was last modified: 09-30-2015, 11:52 AM by jLinux.)

(09-30-2015, 11:36 AM)Lykos22 Wrote:
(09-30-2015, 09:28 AM)jLinux Wrote:
Code:
man chmod
Code:
chmod -R 755 /path/to/folder
or if you're SURE this is ok..



Code:
chmod -R 777 /path/to/folder

I run


Code:
chmod -R 777 /opt/lampp/htdocs/www/my-app/public/uploads

and worked! the script created the posts folder.

However I tried 755 or 775 instead but didn't work, the warning popped up again. Is there a way I can make this work with 755 or 775 permissions, because 777 is not so secure.


Just make sure that the folder is either owned by whatever is running the web service..

If you dont know what the user is, then use the lsof command to check it out. heres an example (assuming that its port 80)
Code:
[root@server ~]# lsof -i:80
COMMAND   PID       USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
httpd    4588     apache    3u  IPv4 4164112702      0t0  TCP *:http (LISTEN)
httpd    4592     apache    3u  IPv4 4164112702      0t0  TCP *:http (LISTEN)
httpd    8170     apache    3u  IPv4 4164112702      0t0  TCP *:http (LISTEN)
httpd    8171     apache    3u  IPv4 4164112702      0t0  TCP *:http (LISTEN)
httpd   24021     apache    3u  IPv4 4164112702      0t0  TCP *:http (LISTEN)

So I can see that my user is apache. But if that somehow confuses you, then run this:
Code:
[root@server ~]# lsof -i:80 | sed 1d | awk '{print $1}' | sort -u
httpd
That will tell you what user is working. It may come up with more than 1 user if multiple services are listening on port 80.


So either chown the folder and its contents to apache (or whatever user)..
Code:
chown -R apache /opt/lampp/htdocs/www/my-app/public/uploads
You might need to elevate your access to do this, by adding sudo before the chown in the command.

If you cant change the owner for the folder, then try the group, just make sure its a group that you and the apache/web user have in common:
Code:
chown -R :groupname /opt/lampp/htdocs/www/my-app/public/uploads

Then change the perms to 775, so both the owner and group have all perms, but everyone else just has read/exec
Code:
chmod -R 775 /opt/lampp/htdocs/www/my-app/public/uploads

You can try to set the group owner of the uploads file to the web user, see if that works... havent tried that before.


P.S. If this wasnt clear from the above. ALL of those commands are via the shell, meaning the command line.. NOT via PHP scripts running exec(). I cant imagine that would work out.
Reply
#14

I have to start the procedure from the begining. When the page loads for first time in my Post_model I have this script
PHP Code:
// set up the folder for storing images and thumbnails
$dir FCPATH 'uploads' DS 'posts';
if (!
is_dir($dir)) {
    
mkdir($dir0755true);
    
mkdir($dir DS 'thumbnails'0755true);

the posts folder and the thumbnails sub-folder are created but they belong in daemon user and daemon group (which I honestly don't know where they come from). By this I mean user and group of the os. So any images that I try as a member user of the site are uploaded having this user and group name, see:
Code:
/opt/lampp/htdocs/www/my-app/public/uploads/posts$ ls -lah

drwxr-xr-x 3 daemon    daemon    4,0K Sep  30 22:41 .
drwxrwxrwx 3 lykos     lykos     4,0K Sep  30 22:40 ..
-rw-r--r-- 1 daemon    daemon    738K Sep  30 22:41 post-img-11.png
-rw-r--r-- 1 daemon    daemon    738K Sep  30 22:41 post-img-12.png
-rw-r--r-- 1 daemon    daemon    738K Σεπ  30 22:41 post-img-1.png
drwxr-xr-x 2 daemon    daemon    4,0K Σεπ  30 22:40 thumbs

which pretty much doesn't allow me to delete them. If it do

Code:
sudo chown -R lykos /opt/lampp/htdocs/www/my-app/public/uploads
sudo chown -R :lykos /opt/lampp/htdocs/www/my-app/public/uploads

drwxr-xr-x 3 lykos lykos 4,0K Sep  30 22:41 .
drwxrwxrwx 3 lykos lykos 4,0K Sep  30 22:40 ..
-rw-r--r-- 1 lykos lykos 738K Sep  30 22:41 post-img-11.png
-rw-r--r-- 1 lykos lykos 738K Sep  30 22:41 post-img-12.png
-rw-r--r-- 1 lykos lykos 738K Sep  30 22:41 post-img-1.png
drwxr-xr-x 2 lykos lykos 4,0K Sep  30 22:40 thumbs

Then I can easily delete images and the folders if I want to. But if I try to upload another image the upload library shows me the error that the folder is not writeble and doesn't let me upload.

I really don't understand what's going on .. do I have to set the hole php script that creates the folders and uploads images to a user (lykos) or some group and change some permissions too ?? I 'm completely confused..
Reply
#15

(This post was last modified: 09-30-2015, 03:46 PM by jLinux.)

What does $_ENV["USER"]; say?

Did some research, are you on a shared server? I doubt it, or else you couldn't run the commands you have ran, unless you are in a jailshell

If you aren't on a shared server, try disabling safe mode..
Reply
#16

(09-30-2015, 03:43 PM)jLinux Wrote: What does $_ENV["USER"]; say?

Did some research, are you on a shared server? I doubt it, or else you couldn't run the commands you have ran, unless you are in a jailshell

If you aren't on a shared server, try disabling safe mode..

null

no I'm on my local machine
Reply
#17

(This post was last modified: 09-30-2015, 03:50 PM by jLinux.)

P.S.

You seem surprised by the fact that when YOU run some commands (chmod) via the command line, it works, as opposed to when you run the commands via PHP exec(), which dont work.

You realize the commands you run via shell are being ran as a totally different user, right?

Im just saying that because your "It worked!" statement seemed like you were surprised, but you shouldnt be.
Reply
#18

(This post was last modified: 09-30-2015, 03:54 PM by jLinux.)

(09-30-2015, 03:48 PM)Lykos22 Wrote:
(09-30-2015, 03:43 PM)jLinux Wrote: What does $_ENV["USER"]; say?

Did some research, are you on a shared server? I doubt it, or else you couldn't run the commands you have ran, unless you are in a jailshell

If you aren't on a shared server, try disabling safe mode..

null

no I'm on my local machine

Can you provide me a phpinfo by any chance?

And maybe the output of:
Code:
lsof -i:80
Reply
#19

(09-30-2015, 03:49 PM)jLinux Wrote: P.S.

You seem surprised by the fact that when YOU run some commands (chmod) via the command line, it works, as opposed to when you run the commands via PHP exec(), which dont work.

You realize the commands you run via shell are being ran as a totally different user, right?

Im just saying that because your "It worked!" statement seemed like you were surprised, but you shouldnt be.

Yes it seems like that, but in this case which is the correct one ??? What user and what permissions should have my uploads, my posts and my thumbnails folders to work properly ???
Reply
#20

(This post was last modified: 09-30-2015, 04:00 PM by jLinux.)

(09-30-2015, 03:56 PM)Lykos22 Wrote:
(09-30-2015, 03:49 PM)jLinux Wrote: P.S.

You seem surprised by the fact that when YOU run some commands (chmod) via the command line, it works, as opposed to when you run the commands via PHP exec(), which dont work.

You realize the commands you run via shell are being ran as a totally different user, right?

Im just saying that because your "It worked!" statement seemed like you were surprised, but you shouldnt be.

Yes it seems like that, but in this case which is the correct one ??? What user and what permissions should have my uploads, my posts and my thumbnails folders to work properly ???

Well I guess its not as important that the web user not be the same as your local user when running locally, but I still highly recommend against it... So lets debug it and fix it the right way!

Ill help you debug it.

Can you provide me a phpinfo() output by any chance?


And maybe the output of: 

Quote:lsof -i:80

as well as:

Quote:ps aux |grep -i [h]ttp

And this is Apache were working with right? not nginx or anything else?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB