【问题标题】:Swapping the public_html folder for quick website change交换 public_html 文件夹以快速更改网站
【发布时间】:2013-07-11 21:00:03
【问题描述】:

我有两个版本的网站,我必须非常快速地多次交换。

在我的主目录中,我有:

drwxr-x---  8 lorem  nobody      4096 Jul 12 20:50 public_html/
drwxr-x---  3 lorem  nobody      4096 Jul 13 12:59 public_html_3.0/

public_html 保存当前网站,public_html_3.0 保存新网站。

我希望通过以下方式替换两者:

//move the complete current site to another tmp location
mv public_html public_html_2.0 
//move the new site in place
mv public_html_3.0 public_html 

在测试帐户上尝试后,我收到 Forbidden You don't have permission to access / on this server. 错误。

我已确保 public_html_* 文件夹具有相同的权限,但我猜这是符号链接问题?我是在尝试做一些不可想象且极不推荐的事情吗?

在 CentOs 5.9 上使用具有 root 权限的 VPS WHM/Cpanel。

编辑

经过一些网络阅读后,我删除了public_html(移至临时)并符号链接public_html -> public_html_3.0,结果:

lrwxrwxrwx  1 lorem nobody           15 Jul 13 14:11 public_html -> public_html_3.0/
drwxr-x---  3 lorem nobody      4096 Jul 13 12:59 public_html_2.0/
drwxr-x---  2 lorem nobody      4096 Jul 13 14:02 public_html_3.0/
lrwxrwxrwx  1 lorem lorem            11 Jul  9  2012 www -> public_html/

还是一样的结果。

【问题讨论】:

    标签: cpanel vps whm public-html


    【解决方案1】:

    如上所述移动 public_html 并不是什么大问题。

    mv public_html public_html_2.0 mv public_html_3.0 public_html

    如果您知道自己在做什么,这些都是无害的命令。

    确保两个目录都拥有 750 权限。

    chmod 750 public_html*

    然后确保两个目录中的文件都具有正确的权限。

    找到 /home/user/public_html/ -type f -exec chmod -R 644 {} \; 查找 /home/user/public_html_3.0/ -type f -exec chmod -R 644 {} \;

    找到 /home/user/public_html/ -type d -exec chmod -R 755 {} \; 查找 /home/user/public_html_3.0/ -type d -exec chmod -R 755 {} \;

    还要确保所有权也正确。递归地改变那些

    chown -R lorem: /home/user/public_html/* chown -R lorem: /home/user/public_html_3.0/*

    如果您使用的是 suphp 处理程序,您也可以使用 lorem:nobody。让我们知道这是否对您有所帮助。

    【讨论】:

    • 谢谢伙计,这肯定行得通。我在学习 => 试用 => 错误周期中花费了数小时,并自己提出了类似的工作流程。将在下面发布我的解决方案,但您的解决方案更深入地了解正在发生的事情,这很棒。
    【解决方案2】:

    我遇到的错误(禁止您无权访问此服务器上的 /。) 是新站点的根文件夹放错了位置,而不是文件系统问题。新站点实际上位于~/public_html_3.0/public_html/,因为我解压错了。我放置的新符号链接 public_html => public_html_3.0 现在指向一个没有索引文件的文件夹,因此出现了错误。


    替代解决方案

    Leo Prince 的回答是正确的,但我将提供一个带有单命令开关的替代解决方案,这也适用于我(解释为像我这样的新手):

    此解决方案要求您为服务器或此特定虚拟主机启用 FollowSymlinks,并假设您的虚拟主机指向 /home/user/public_html (~/public_html)。有关许可/所有权说明,请参阅已接受的答案。

    假设您的旧网站位于~/public_html,而您的新网站位于~/app2。

    -public_html
       -index.html
       -other.html
    -app2
       -index.html
       -other_new.html
    

    首先,将旧站点复制到新目录:

    # mkdir app1
    # cp -a public_html/. app1/.
    // -a option copies recursively with permissions/owners/groups 
    // but doesn't follow symbolic links
    

    然后将 public_html 移动(重命名)到一个临时目录,然后创建一个从 public_html 到旧应用程序的符号链接。

    # mv public_html public_html_bak
    // moves the public_html "out of way"
    # ln -s app1 public_html
    // creates a symbolic-link
    # ls -l
    drwxr-x---  user nobody app1/
    drwxr-x---  user nobody app2/
    lrwxr-x---  user nobody public_html -> app1/
    drwxr-x---  user nobody public_html_bak/
    

    这使得 ~/public_html 指向 ~/app1。 Read more on symbolic links。服务器看到 public_html,但文件来自 app1。

    如果不起作用,请返回之前的状态:

    # rm public_html 
    //// use rm, NOT rmdir, since it's a symlink, not a dir
    # mv public_html_bak public_html
    // return backup to previous location
    

    如果可行,当您希望切换到新站点 (app2) 时,您需要将符号链接更改为指向 app2 目录:

    # rm public_html; ln -s app2 public_html
    // remove existing link, create new link with a single line (instant change)
    # ls -l
    drwxr-x---  user nobody app1/
    drwxr-x---  user nobody app2/
    lrwxr-x---  user nobody public_html -> app2/
    drwxr-x---  user nobody public_html_bak/
    

    虽然这与连续重命名两个文件夹大致相同,但它可以清晰地审查应用程序版本,这是我想要实现的目标:

    # ls -l
    drwxr-x---  user nobody app2.3/
    drwxr-x---  user nobody app3.0/
    drwxr-x---  user nobody app3.1/
    drwxr-x---  user nobody app3.2b/
    lrwxr-x---  user nobody public_html -> app3.0/ <- the current active version
    
    # rm public_html; ln -s app3.1 public_html
    /// a one-line switch to a different app version
    /// first remove the symbolic link; then create new
    

    当然,所有应用程序目录都必须具有适当的权限,如上面接受的答案中所述,并且目录的所有者:组必须与原始 public_html 相同。此外,符号链接必须属于具有相同权限的同一用户:组,以防您的服务器配置仅允许来自同一用户的符号链接。

    请注意,要删除符号链接,您应该使用rm,而不是rmdir,因为如果您尝试删除实际目录,它将失败。

    我还在学习 *NIX,所以这个解决方案可能存在一些我不知道的问题。但是对于频繁的版本更改,这就像魔术一样 :)

    【讨论】:

    • Vanj​​a 解释得很好。一次编辑可能有用。使用“cp -a public_html/app1/”而不是“cp -r public_html/app1/”。因为 -a 选项完成了 -r(递归)和 -p(保留权限和所有权)的工作
    猜你喜欢
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 2019-10-06
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多