I'm on an EC2 instance and I wish to connect my PHP website with my Amazon S3 bucket, I already saw the API for PHP here: http://aws.amazon.com/sdkforphp/ but it's not clear.
This is the code line I need to edit in my controller:
thisFu['original_img']='/uploads/fufu/'.$_POST['cat'].'/original_'.uniqid('fu_').'.jpg';
I need to connect to Amazon S3 and be able to change the code like this:
$thisFu['original_img']='my_s3_bucket/uploads/fufu/'.$_POST['cat'].'/original_'.uniqid('fu_').'.jpg';
I already configured an IAM user for the purpose but I don't know all the steps needed to accomplished the job.
How could I connect and interact with Amazon S3 to upload and retrieve public images?
UPDATE
I decided to try using the s3fs as suggested, so I installed it as described here (my OS is Ubuntu 14.04)
I run from console:
sudo apt-get install build-essential git libfuse-dev libcurl4-openssl-dev libxml2-dev mime-support automake libtool
sudo apt-get install pkg-config libssl-dev
git clone https://github.com/s3fs-fuse/s3fs-fuse
cd s3fs-fuse/
./autogen.sh
./configure --prefix=/usr --with-openssl
make
sudo make install
Everything was properly installed but what's next? Where should I declare credentials and how could I use this integration in my project?
2nd UPDATE
I created a file called .passwd-s3fs
with a single code line with my IAM credentials accessKeyId:secretAccessKey
.
I place it into my home/ubuntu
directory and give it a 600 permission with chmod 600 ~/.passwd-s3fs
Next from console I run /usr/bin/s3fs My_S3bucket /uploads/fufu
Inside the /uploads/fufu
there are all my bucket folders now. However when I try this command:
s3fs -o nonempty allow_other My_S3bucket /uploads/fufu
I get this error message:
s3fs: unable to access MOUNTPOINT My_S3bucket : No such file or directory
3rd UPDATE
As suggested I run this fusermount -u /uploads/fufu
, after that I checked the fufu folder and is empty as expected.
After that I tried again this command (with one more -o):
s3fs -o nonempty -o allow_other My_S3bucket /uploads/fufu
and got this error message:
fusermount: failed to open /etc/fuse.conf: Permission denied
fusermount: option allow_other only allowed if 'user_allow_other' is set in /etc/fuse.conf
Any other suggestion?
4th UPDATE 18/04/15
Under suggestion from console I run sudo usermod -a -G fuse ubuntu
and sudo vim /etc/fuse.conf
where I uncommented mount_max = 1000 and user_allow_other
Than I run s3fs -o nonempty -o allow_other My_S3bucket /uploads/fufu
At first sight no errors, so I thought everythings fine but it's exactly the opposite.
I'm a bit frustrated now, because I don't know what happened but my folder /uploads/fufu
is hidden and using ls -Al
I see only this
d????????? ? ? ? ? ? fufu
I cannot sudo rm -r
or -rf
or mv -r
it says that /uploads/fufu is a directory
I tried to reboot exit and mount -a
, but nothing.
I tried to unmount using fusermount
and the error message is fusermount: entry for /uploads/fufu not found in /etc/mtab
But I tried sudo vim /etc/mtab and I found this line: s3fs /uploads/fufu fuse.s3fs rw,nosuid,nodev,allow_other 0 0
Could someone tell me how can I unmount and finally remove this folder /uploads/fufu
?