File Gateway does not write user files to the S3 bucket.

0

"I have an Ubuntu installation with WordPress, an S3 bucket, and a File Gateway. I connect the File Gateway to the S3 bucket and mount the S3 bucket through the File Gateway. The mounted directory works normally for the 'nobody' user. However, when I try to write files from WordPress to the upload directory, it doesn't allow me. I can't change the owner on the bucket, so the Apache user can't write to S3. How should I set this up?"

2 Answers
0

To set up WordPress to write files to the S3 bucket through the File Gateway, you need to ensure the Apache user has permissions.

Please check the following:

  • Verify the IAM role used by the File Gateway has the necessary permissions to access the S3 bucket, such as s3:PutObject.
  • Check that the mounted directory permissions allow the Apache user to write files. You may need to change ownership of files/folders to the Apache user.
sudo chown -R apache:apache /path/to/mounted/directory
  • Consider using a group that both the Apache user and File Gateway IAM role belong to for shared access to files.
  • As an alternative, you can write files to a local directory first then sync to S3 later using a cron job or tool like rsync as the File Gateway IAM role.
profile picture
EXPERT
answered a month ago
  • We have an Ubuntu instance running WordPress using AWS File Gateway. We have an S3 bucket mounted, and communication works. We can read and write files from S3 within the local filesystem using the mount. We created a symlink to the WordPress uploads directory. We can read data without problems.

    The problem occurs when we want to write a file to S3. We don't know if S3 or File Gateway is rejecting it. We were unable to write the files under the Apache web-data user to S3.

    Therefore, we agreed to create a script that will write the file to a local directory and then send it to the mounted S3 directory using the classic copy command.

    We need to solve the problem that WordPress also reads from this directory. So, we need some kind of conditional redirection for storing files to the local directory with the web-data owner for storing data in the upload directory. After the file is written, copy will be run on the S3 bucket, i.e. on its local mount, and after copying, it will be deleted in the local directory.

    And it will be preserved in the directory - the symbolic link uploads, where reading works without problems. So the problem is to convince WordPress to store files in a different directory and read them from a different directory.

0

We have an Ubuntu instance running WordPress using AWS File Gateway. We have an S3 bucket mounted, and communication works. We can read and write files from S3 within the local filesystem using the mount. We created a symlink to the WordPress uploads directory. We can read data without problems.

The problem occurs when we want to write a file to S3. We don't know if S3 or File Gateway is rejecting it. We were unable to write the files under the Apache web-data user to S3.

Therefore, we agreed to create a script that will write the file to a local directory and then send it to the mounted S3 directory using the classic copy command.

We need to solve the problem that WordPress also reads from this directory. So, we need some kind of conditional redirection for storing files to the local directory with the web-data owner for storing data in the upload directory. After the file is written, copy will be run on the S3 bucket, i.e. on its local mount, and after copying, it will be deleted in the local directory.

And it will be preserved in the directory - the symbolic link uploads, where reading works without problems. So the problem is to convince WordPress to store files in a different directory and read them from a different directory.

Janos
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions