user3738338
user3738338

Reputation: 21

Mount EFS to wp-content on elastic beanstalk

So i'm having a problem setting up a Wordpress site on EB. I got the EFS to mount correctly on wp-content/uploads/wpfiles (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/php-hawordpress-tutorial.html) however this only allows the pages to be stored and not the plugins. Is it possible to mount the entire wp-content folder onto EFS, I've tried and so far failed

Upvotes: 1

Views: 2090

Answers (2)

Lawrence Gil
Lawrence Gil

Reputation: 415

I'm not sure if this issue was resolved and it passed silently. I'm having the same issue as you, but with a different error. My knowledge is fairly limited so take what I say with a grain of salt, according to what I saw in your log the problem is that your instance can't see the server. I think that it could be that your EB application is getting deployed in a different Availability Zone than your EFS. What I mean is that maybe you have mount targets for AZ a, b and d and your EB is getting deployed in AZ c. I hope this helps.

I tried a different approach (it basically does the same thing, but I'm manually linking each of the subfolders instead of the wp-content folder), for it to work I deleted the original folders inside /var/app/ondeck (that will eventually get copied to /var/app/current/ that is the folder which get served). Of course, once this gets done your Wordpress won't work since it doesn't have any themes, the solution here would be to quickly log in to the EC2 instance in which your ElasticBeanstalk app is running and manually copying the contents to the mounted EFS (in my case the /wpfiles folder). To connect to the EC2 instance (you can find the instance ID under your EB health configuration) you can follow this link and to mount your EFS you can follow this link. Of course, if the config works you won't have to mount it since it would be already mounted though empty. Here is the content of my config file:

option_settings:
  aws:elasticbeanstalk:application:environment:
    EFS_NAME: '`{"Ref" : "FileSystem"}`'
    MOUNT_DIRECTORY: '/wpfiles'
    REGION: '`{"Ref": "AWS::Region"}`'

packages:
  yum:
    nfs-utils: []
    jq: []

files:
  "/tmp/mount-efs.sh" :
    mode: "000755"
    content: |
      #!/usr/bin/env bash
      mkdir -p $MOUNT_DIRECTORY
      EFS_REGION=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.REGION')
      EFS_NAME=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_NAME')
      MOUNT_DIRECTORY=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.MOUNT_DIRECTORY')
      mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $EFS_NAME.efs.${EFS_REGION}.amazonaws.com:/ $MOUNT_DIRECTORY || true
      mkdir -p $MOUNT_DIRECTORY/uploads
      mkdir -p $MOUNT_DIRECTORY/plugins
      mkdir -p $MOUNT_DIRECTORY/themes
      chown webapp:webapp -R $MOUNT_DIRECTORY/uploads
      chown webapp:webapp -R $MOUNT_DIRECTORY/plugins
      chown webapp:webapp -R $MOUNT_DIRECTORY/themes

commands:
  01_mount:
    command: "/tmp/mount-efs.sh"
container_commands:
  01-rm-wp-content-uploads:
    command: rm -rf /var/app/ondeck/wp-content/uploads && rm -rf /var/app/ondeck/wp-content/plugins  && rm -rf /var/app/ondeck/wp-content/themes
  02-symlink-uploads:
    command: ln -snf $MOUNT_DIRECTORY/uploads /var/app/ondeck/wp-content/uploads && ln -snf $MOUNT_DIRECTORY/plugins /var/app/ondeck/wp-content/plugins && ln -snf $MOUNT_DIRECTORY/themes /var/app/ondeck/wp-content/themes

I'm using another config file to create my EFS as in here, in case you have already created your EFS you must change EFS_NAME: '`{"Ref" : "FileSystem"}`' to EFS_NAME: id_of_your_EFS.

I hope this helps user3738338.

Upvotes: 2

prasoon
prasoon

Reputation: 901

You can do following this link - https://github.com/aws-samples/eb-php-wordpress/blob/master/.ebextensions/efs-mount.config

Just keep a note it uses uploads, you can change it for wp-content.

Upvotes: -1

Related Questions