Amazon EFS:将Wordpress上传目录更改为外部根目录 [英] Amazon EFS: Changing Wordpress upload directory to outside root

查看:114
本文介绍了Amazon EFS:将Wordpress上传目录更改为外部根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个AWS EC2实例,这些实例是通过CodeDeploy从Git存储库中更新的.但是,由于将 wp-content/uploads 文件夹保存在Git中比较麻烦且难以维护,因此我试图将所有上载内容移至已作为EFS文件系统挂载的目录中.这样,我应该能够在多个EC2实例之间共享上传.

I have multiple AWS EC2 instances which are updated from a Git repository via CodeDeploy. However, since keeping the wp-content/uploads folder in Git is messy and hard to maintain, I'm instead trying to move all uploads to a directory which I have mounted as an EFS filesystem. That way I should be able to share the uploads between multiple EC2 instances.

但是,现在我遇到了一个新问题;我无法将WP上载文件夹设置为WP根目录之外.

However, now I'm running into a new problem; there's no way for me to set the WP uploads folder to be outside of the WP root.

WordPress位于以下位置:/opt/bitnami/apps/wordpress/htdocs .EFS系统已安装到/home/bitnami/efs .由于EFS目录位于WP根目录之外,因此我无法链接到该目录.

WordPress is located at /opt/bitnami/apps/wordpress/htdocs, which is also where our domain points. The EFS system is mounted to /home/bitnami/efs. Since the EFS directory is located outside of the WP root there's no way for me to link to it.

我已经使用符号链接将默认的 wp-content/uploads 文件夹定向到我想要的路径,从而可以正常工作;但是,这并不能真正解决我的问题,因为我不能依靠符号链接在CodeDeploy部署期间不会被覆盖.

I have gotten this to work using a symlink directing the default wp-content/uploads folder to my desired path; however, this doesn't really solve my issue since I can't rely on the symlink to not be overwritten during CodeDeploy deployments.

所以我的问题如下:

  1. 是否可以在不使用符号链接的情况下进行此设置,所以我可以进行部署而不必担心上载会受到影响吗?

  1. Is it possible to have this setup work without using a symlink, so I can make deployments without worrying about by uploads being affected?

如果符号链接是实现此功能的唯一/最佳方法,是否有任何方法可以将符号链接添加到git存储库中,或者可以通过其他任何方法来确保它在CodeDeploy部署期间持久存在?

If a symlink is the only/best way to make this work, is there any way to add the symlink to the git repository, or any other way to make absolutely sure it persists during CodeDeploy deployments?

推荐答案

您可以将EFS直接挂载到/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads 以避免符号链接

You can directly mount your EFS to /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads to avoid symlinks.

在您的 appspec.yml 中添加两个钩子:

In your appspec.yml add two hooks:

hooks:
    BeforeInstall:
      - location: /deploy/BeforeInstall.sh
        timeout: 3000
        runas: root
    AfterInstall:
      - location: /deploy/AfterInstall.sh
        timeout: 3000
        runas: root

然后创建目录 deploy 和其中的两个文件 BeforeInstall.sh AfterInstall.sh

Then create directory deploy and two files in it BeforeInstall.sh and AfterInstall.sh

BeforeInstall.sh 如果已安装EFS,则将其卸载

BeforeInstall.sh unmount the EFS if its mounted

#!/bin/bash
if mount | grep /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads > /dev/null; then
    sudo umount /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
fi

然后在部署后通过 AfterInstall.sh 再次挂载EFS

Then mount EFS again via AfterInstall.sh after deployment

#!/bin/bash
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-fxxxxxx.efs.us-west-2.amazonaws.com:/ /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads

注意:您还可以挂载整个 wp-contents 目录,而不仅仅是 uploads 文件夹,以便在 themes 中进行更新.插件也会自动反映在其他EC2中.

Note: You can also mount entire wp-contents directory, not just uploads folder, so that update in themes and plugins also get reflected in other EC2s automatically.

而且,symlink是更好的解决方案,因此,如果 umount 失败,则不必担心在部署过程中意外删除EFS挂载.您可以在部署后使用 AfterInstall 钩子再次重新创建符号链接,并在文件 AfterInstall.sh

Also, symlink is a better solution, so you don't have to ever worry about accidentally removing the EFS mount during deployment if umount ever fails. You can just recreate symlink again after deployment using AfterInstall hook and add code in file AfterInstall.sh

#!/bin/bash
ln -s /home/bitnami/efs /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads

这篇关于Amazon EFS:将Wordpress上传目录更改为外部根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆