When you switch to a production environment, the web application crashes. What server permissions do I need?

I developed a small web application.

This application allows users to upload images. It also creates text files with the names of these images (the names are stored and retrieved to / from the MySQL database.)

I developed this application using MAMP. To create uploaded image files, I use the PHP function

imagejpeg('my/path/name.jpg')

and to delete files I use the PHP function

unlink('folder1/folder2/name.jpg')

to write to a text document I use the function

fopen('folder1/folder2/name.txt', 'w')

all three of these functions cause permissions errors - the site has now been moved to a live hosting environment.

Why is this? and what permissions do I need to set for the folder folder1and folder2for?

, 777 , . , , 777 . - ?

+3
3

777, , .

, .

, , , // , -. -, sudo .

read - .
write - . (: unlink())
- .

:

chown -R www-data: folder1/
chmod 700 folder1/ folder1/folder2/

, - www-. FTP bash sudo, , ​​ wwwusers, , , - :

chown -R www-data:wwwusers folder1/
chmod 770 folder1/ folder1/folder2/

, , , root , ACL POSIX - grsecurity. ACL - setfacl -mu:www-data:rwx /path/to/dir. , , -.

, unix unix- . , man chmod, man chown. UNIX .

+1

, , , , :) www- 775.

chown -R :www-data folder1
chmod -R 775 folder1
+1

Instead of just changing permissions, have you looked at folder permissions? The web server acts as another user who develops and deploys scripts and folders. A simple fix would be to change the owner of the folder to the web server user.

0
source

Source: https://habr.com/ru/post/1749411/


All Articles