php 写入权限 - 本地主机 - Mac OSX
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8035939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Write Privileges - localhost - Mac OSX
提问by Paul Mason
I'm new to the mac world and have just been setting up my webserver. I used the following guide: https://alan.ivey.dev/posts/2011/os-x-10.7-lion-development-native-mamp-with-mysql-installer/
我是 mac 世界的新手,刚刚设置了我的网络服务器。我使用了以下指南:https: //alan.ivey.dev/posts/2011/os-x-10.7-lion-development-native-mamp-with-mysql-installer/
I've transferred my sites and databases and everything is going pretty well. The only problem I have is with the writing permissions. For example there is a config file that needs to be written to, and I had to right click, go to Get Info then enable read & write for staff and everyone.
我已经转移了我的网站和数据库,一切进展顺利。我唯一的问题是写入权限。例如,有一个需要写入的配置文件,我必须右键单击,转到“获取信息”,然后为员工和所有人启用读写。
I can't manually go through and enable these write privileges for every file/folder. I didn't need to do this using WAMP and made development much quicker.
我无法手动检查并为每个文件/文件夹启用这些写入权限。我不需要使用 WAMP 执行此操作,并且使开发速度更快。
So wondering about 2 possible solutions: a) add my user account to a whitelist for the localhost so that 644 privileges are sufficient b) set the write privileges recursively
所以想知道 2 种可能的解决方案:a) 将我的用户帐户添加到 localhost 的白名单,以便 644 权限足够 b) 递归设置写入权限
回答by Paul Mason
I found the best solution was to change the apache user and group settings. The instructions can be found at: http://paulmason.name/item/change-apache-user-group-in-lion-os-x
我发现最好的解决方案是更改 apache 用户和组设置。说明可以在以下位置找到:http: //paulmason.name/item/change-apache-user-group-in-lion-os-x
Open Terminal and Enter
sudo nano /private/etc/apache2/httpd.conf
Find and change http.conf code from
User _www Group _www
To
User your_mac_username Group staff
Note: With earlier versions such as Leopard, capitalize staff to Staff. You can get your username and group by typing "id" and hitting enter in terminal
Restart Apache
sudo apachectl restart
打开终端并输入
sudo nano /private/etc/apache2/httpd.conf
查找并更改 http.conf 代码
User _www Group _www
到
User your_mac_username Group staff
注意:对于 Leopard 等早期版本,将人员大写为人员。您可以通过输入“id”并在终端中按回车来获取您的用户名和组
重启阿帕奇
sudo apachectl restart
回答by Alan Ivey
I'm the author of the mentioned blog post. For web server file permissions, you'll want to give write access to the _www user for files. For config.inc.php, you would set it a couple ways:
我是上述博客文章的作者。对于 Web 服务器文件权限,您需要授予 _www 用户对文件的写访问权限。对于 config.inc.php,您可以通过以下几种方式进行设置:
Have _www own the file and have write permissions:
_www 拥有该文件并具有写入权限:
$ sudo chown _www config.inc.php
$ chmod u+w config.inc.php
Have your user own the file, change the group to _www, and give group write permissions:
让您的用户拥有该文件,将组更改为 _www,并授予组写入权限:
$ sudo chgrp _www config.inc.php
$ chmod g+w config.inc.php
Or, if you feel comfortable allowing all users to write, which I would not recommend for security reasons, give all users the ability to write:
或者,如果您觉得允许所有用户编写(出于安全原因我不建议这样做),请让所有用户都可以编写:
$ chmod a+w config.inc.php
If an entire folder needs to be written by the _www user, it can own the folder and all files:
如果 _www 用户需要写入整个文件夹,它可以拥有该文件夹和所有文件:
$ sudo chown -R _www:_www folder/
or you can give the folder write and execute permissions by all:
或者您可以授予文件夹写入和执行权限:
$ chmod a+wx folder/
The reason why chmod 774
gave you forbidden errors was because the _www user fell under the '4' permission, which is 'read-only.' For directories, a user needs 'execute' in order to traverse into the folder. chmod 775
would allow user and group to rwx, and others to r-x. Here's more information on Unix file permissions.
之所以chmod 774
给您禁止错误是因为 _www 用户属于“4”权限,即“只读”。对于目录,用户需要“执行”才能遍历文件夹。chmod 775
将允许用户和组 rwx,其他人 rx。这里有更多关于 Unix 文件权限的信息。
Also, your user could retain full ownership and add certain permissions for the _www user instead of changing the level of access for ALL users by using Access Control Lists.
此外,您的用户可以保留完全所有权并为 _www 用户添加某些权限,而不是使用访问控制列表更改所有用户的访问级别。
$ sudo chmod -R +a '_www allow read,write,delete,add_file,add_subdirectory,file_inherit,directory_inherit' folder
$ sudo chmod +a '_www allow read,write' config.inc.php
If you're going to go the route of ACLs, I'd suggest doing some more reading to see what levels of access you really need to provide. Here is a great place to start.
如果您打算采用 ACL 的路线,我建议您多阅读一些内容,以了解您真正需要提供哪些级别的访问权限。这是一个很好的起点。
回答by Justin
I'm running Apache on OSX and this fixed it for me:
我在 OSX 上运行 Apache,这为我修复了它:
sudo chown -R _www:_www <mywebfolder>
sudo chmod -R 775 <mywebfolder>
Update #1:
更新 #1:
Syntax: sudo chown <user>:<group> <file-or-folder>
. The Apache user on OSX is _www
.
语法:sudo chown <user>:<group> <file-or-folder>
. OSX 上的 Apache 用户是_www
.
To keep ownership but give Apache r-w-x permissions:
要保留所有权但授予 Apache rwx 权限:
sudo chown -R <your-username>:_www <mywebfolder>
sudo chmod -R 775 <mywebfolder>
Update #2:
更新#2:
I like this method best. Set Apache to run as you.
我最喜欢这种方法。将 Apache 设置为像您一样运行。
In terminal type
id
to getuid=123(Myname)
.Open /etc/apache2/httpd.conf and edit it to use your username.
<IfModule unixd_module> User Myname Group staff </IfModule>
Back to terminal:
sudo apachectl restart
在终端类型
id
中获取uid=123(Myname)
.打开 /etc/apache2/httpd.conf 并编辑它以使用您的用户名。
<IfModule unixd_module> User Myname Group staff </IfModule>
回到终端:
sudo apachectl restart
回答by sascha
I recommend settings the Write privileges recursively for your web root.
我建议为您的 Web 根递归设置写入权限。
You can do this via the console / terminal using chmod -R 774 /my/web/root
. For me, the owner and group is set to: www-data:myUserName
, which can be set by using chown
. Don't forget to check who's your web user first.
您可以通过控制台/终端使用chmod -R 774 /my/web/root
. 对我来说,所有者和组设置为: www-data:myUserName
,可以使用chown
. 不要忘记首先检查谁是您的网络用户。
Edit:For better understanding, why you don't have access:
编辑:为了更好地理解,为什么您无权访问:
Chmod 774, each number stands for specific rights: user, group, others. If the user is set to www-data
and the group to www-data
(most users on a Unix system are in a group that's named by their username). So, if you're not in the group www-data
you either have to join it, or you have to change owner (chown) or you have to change the permissions (chmod). There are several tutorials out there, for more information.
chmod 774,每个数字代表特定的权限:用户、组、其他。如果用户设置为www-data
并且组设置为www-data
(Unix 系统上的大多数用户都在以用户名命名的组中)。因此,如果您不在组中www-data
,则必须加入该组,或者必须更改所有者 (chown) 或必须更改权限 (chmod)。那里有几个教程,以获取更多信息。