Home > Backend Development > PHP Tutorial > How to change the root permission directory of the Linux server to www:www in PHP

How to change the root permission directory of the Linux server to www:www in PHP

WBOY
Release: 2016-08-04 09:20:52
Original
2040 people have browsed it

When customer service uploads files through FTP, all files have ROOT user permissions by default, resulting in PHP files that cannot be read, written and created.

You can only set up each file by chown www:www.

Is there any way to operate it through PHP?

Reply content:

When customer service uploads files through FTP, all files have ROOT user permissions by default, resulting in PHP files that cannot be read, written and created.

You can only set up each file by chown www:www.

Is there any way to operate it through PHP?

You said: For their server, they like to use SFTP to transfer files directly, which causes the program to be unable to create directories, rewrite files, etc. This is inevitable. You can use usermod -aG www [username] to add the user who logs in to sftp to the www group. Add the www user to the group of the user to whom you are transferring files. In this way, www and the user who is transferring files will be added. It is a group, so the files must be given 664 permission. (This is the method I have used. I use syncthing and the atom editor (belonging to the users group) locally to synchronize files with the web server (nginx group). But I chown the web server to users)
Yes, bool chown (string $filename, mixed $user) can be changed. PHP seems to have chmod, but it is recommended to change it on the server,

chown -R www:www /path/

Generally, the folder permission is 755, and the file permission is 644. Use the following command to do it (the specific folder can be changed by yourself):

chown -R nginx.nginx /usr/share/nginx/html/ && find /usr/share/nginx/html/ -type d -exec chmod 755 {}; && find /usr/share/nginx/html/ -type f -exec chmod 644 {} ;

I wrote it into bashrc. I can’t type it again next time: alias webroot='chown -R nginx.nginx /usr/share/nginx/html/ && find /usr/share/nginx/html/ -type d -exec chmod 755 {} ; && find /usr/share/nginx/html/ -type f -exec chmod 644 {} ;'
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;-----&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div> Another server uses sftp to transfer files. The user belongs to aaa under the users group. Before I transfer the file, I open ssh and change all the file permissions to aaa belonging to users. I write alias in bashrc. It is not troublesome. Get it back after you're done, it's better to do the above. After all, you have to use stfp, and it's not safe to just let the root out for use)

If it’s convenient for you, just chown the folder -R 777

Can’t the ftp user set the permissions?

Don’t log in with root, just download it from win. Generally, ftp tools can change it, such as xftp. You can modify the permissions of the folder and file passed in, and keep the same permissions for subsequent incoming files

You can use this function boolchown(), but it is not very safe. It is best to change it directly on the server. This also requires root permissions to execute. It is best that the ftp account is consistent with the user of the php process

Using the chown command in shell, I have encountered this problem before when configuring lamp.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template