【问题标题】:How to set the right access right for local (apache) server?如何为本地(apache)服务器设置正确的访问权限?
【发布时间】:2014-04-30 12:30:53
【问题描述】:

我在我的笔记本电脑(macbook pro osx 10.9.2)上运行一个 apache 服务器,用于网络开发。当我安装了一个 Joomla 示例 Web 应用程序并尝试了一些功能(例如通过 joomla 管理员更改字体设置)时,我收到许多错误消息,表明它无法写入某些子文件夹。当我使用 mac 文件管理器手动将相关子文件夹的“所有人”的权限更改为“读写”时,问题就解决了。但我认为这不是正确的解决方案(每个人都可以访问)和优雅的解决方案(为了避免错误消息,我会为所有子文件夹这样做)。

如何正确设置访问权限?例如我应该向哪个实体分配什么样的访问权限(如您所见,我并不真正熟悉这些安全问题)。如果我要使用 mac 终端应用程序,正确的命令是什么?

感谢您的帮助。

【问题讨论】:

    标签: apache joomla


    【解决方案1】:

    你好,mac 用户 (':

    打开终端并查看 chmod 命令。

    使用 chmod 命令,您可以更改文件夹和子文件夹的权限。

    看看Chmod tutorial

    例如:

    chmod -R ugo
    u=permission for user that owns the file
    g=permission for groups that own the file
    o=permissions for others
    4=read
    2=write
    1=execute
    
    u=4 -> owner can read but cannot write or execute
    u=4 & g=3 -> owner can read | groups that own the file can write and execute but not read from it
    
    
    // This wil give all users read and write permissions.
    chmod -R 666 joomla/
    

    【讨论】:

    • 谢谢。但从安全角度来看,777 是否明智?
    • 不,它不是:P 这只是为了举例。在理想情况下,您应该确定哪些文件夹应该具有这些写入权限。
    【解决方案2】:

    如果您使用的是 Mac OS X 附带的内置 Apache,您将在 Apache 运行的默认用户和文件的所有权之间发生冲突。 Apache 可以访问它们,或者您可以读取和写入它们,但不能同时进行。

    例如,如果我在 cding 到我的主目录之后在终端中发出 ls -al,我可以看到 ~/Sites 目录具有以下权限和所有权:

    drwxr-xr-x+  18 cppl   staff    612  6 Apr 09:32 Sites
    

    默认情况下,Apache 在_www 组中以_www 运行。

    因此,您要么需要将您的用户添加到_www 组,要么以您的用户身份运行 Apache。

    如果您将自己添加到_www 组,您仍然需要摆弄文件和目录权限。

    如果您更改 httpd.conf 以便 Apache 以您的用户身份运行,您将需要找到并更改此部分:

    #
    # If you wish httpd to run as a different user or group, you must run
    # httpd as root initially and it will switch.  
    #
    # User/Group: The name (or #number) of the user/group to run httpd as.
    # It is usually good practice to create a dedicated user and group for
    # running httpd, as with most system services.
    #
    User _www
    Group _www
    

    具体来说,您需要将User 行设置为您的短用户名,例如对我来说是cppl,通常你会想要将组设置为staff,我猜是Mac OS X上用户的默认设置。例如

    User cppl
    Group staff
    

    当然,如果您这样做,您可能应该通过防火墙限制对 Apache 的访问到 localhost 或您的专用网络(不包括路由器)。

    【讨论】:

    • 嗨,cppl,thnx(抱歉回复晚了,我离开了一段时间)。当我按照您的指示更改 httpd 时,apache 服务器不再工作(webbrowser 找不到)(?)。关于您的 firstion 选项:如何精确地处理文件和目录权限?
    猜你喜欢
    • 2015-11-14
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 2020-07-19
    • 2013-11-18
    • 1970-01-01
    • 2021-07-01
    相关资源
    最近更新 更多