1

I was able to mount my Google Cloud Storage using the command line below:

gcsfuse -o allow_other -file-mode=660 -dir-mode=770 --uid=<uid> --gid=<gid> testbucket /path/to/domain/folder

The group includes the user apache. Apache is able to write to the mounted drive like so:

sudo -u apache echo 'Some Test Text' > /path/to/domain/folder/hello.txt

hello.txt appears in the bucket as expected. However when I execute the below php script I get an error:

<?php file_put_contents('/path/to/domain/folder/hello.txt', 'Some Test Text');

PHP Error: failed to open stream: Permission denied

echo exec('whoami'); Returns apache

I assumed this is a common use for mounting with gcsfuse or something similar to this but, I seem to be the only one on the internet with this issue. I do not know if its an issue with the way I mounted it or the service security of httpd.

Syclone
  • 1,235
  • 13
  • 14
  • There are a lot of moving parts here. Are you able to reproduce the problem without PHP or even Apache? That would help a lot. Failing that, maybe you could use `strace` to see exactly what system call(s) PHP is making that fail. – jacobsa Jul 27 '16 at 02:51

1 Answers1

1

I came across a similar issue.

Use the flag --implicit-dirs while mounting the Google Storage bucket using gcsfuse. More on this here.

Mounting the bucket as a folder makes the OS to treat it like a regular folder which may contain files and folders. But Google Cloud Storage bucket doesn't have directory structures. For example, when you are creating a file named hello.txt in a folder named files inside a Google Storage bucket, you are not actually creating a folder and putting the file in it. The object is created in the bucket with the name as files/hello.txt. More on this here and here.

To make the OS treat the GCS bucket like a hierarchical structure, you have to specify the --implicit-dirs flag to the gcsfuse.

Note: I wouldn't recommend using gcsfuse in production systems as it is a beta quality software.

  • I do see the difference in behavior with the folders but, unfortunately that didn't fix the issue for me. I am still not able to save files with PHP. I will be using the API instead. Thanks for your help! – Syclone Jul 29 '16 at 22:55