How to use Vultr Object Storage with Laravel 8

Elijah Cruz
3 min readNov 9, 2020

--

With Vultr’s S3 compatible object storage, you can store all the static assets you need for your Laravel site in one place in a very simple way.

First, you need to head to your Vultr dashboard and click on Objects.

Click on Objects to view the object storage.

You then want to click on the blue + button to be able to create a new Object Storage Instance.

Then Select the region (might only give you New Jersey), give it a label, and click “Add”

Now just wait for the object storage you created to change from “Installing” to “Ready” so you can click the label you gave it and access the storage.

You now want to click on the Buckets tab and click where it says Create Bucket.

Now you can go ahead and name your bucket whatever you wish. Keep in mind that the name has to be unique to the region you are in, so for example, there can not be two “test” Buckets in New Jersey. They can also have only lowercase letters, numbers, and dashes. They cannot start or end with a dash.

Now that you have your bucket, let’s finally head to the Laravel side of things.

The first thing you need to do is make sure you have the S3 Flysystem Package.

composer require league/flysystem-aws-s3-v3

This will give you the package you need to use S3 buckets.

You will now need to head to your config/filesystems.php file. You will need to enter the following code into the file inside of the disks array:

'vultr' => [
'driver' => 's3',
'key'=> env('VULTR_ACCESS_KEY'),
'secret' => env('VULTR_SECRET_KEY'),
'region' => env('VULTR_REGION'),
'bucket' => env('VULTR_BUCKET'),
'endpoint' => env('VULTR_ENDPOINT'),
],

So the file should look something like this:

<?php
return [
//..
'disks' => [
//..
'vultr' => [
'driver' => 's3',
'key'=> env('VULTR_ACCESS_KEY'),
'secret' => env('VULTR_SECRET_KEY'),
'region' => env('VULTR_REGION'),
'bucket' => env('VULTR_BUCKET'),
'endpoint' => env('VULTR_ENDPOINT'),
],
],
];

You can now add the environment variables you need into your .env file

VULTR_ACCESS_KEY=myaccesskey
VULTR_SECRET_KEY=shhthisisasecret
VULTR_REGION=ewr1
VULTR_BUCKET=myfirstbucket
VULTR_ENDPOINT=https://ewr1.vultrobjects.com

You can now use your object storage from Vultr on your site.

Storage::disk('vultr')->putFile('uploads', request()->file, 'public');

Note that vultr is considered the disk because that’s what was set in the filesystems.php file.

For any more info, refer to the Laravel Documentation on File Storage.

--

--

Elijah Cruz
Elijah Cruz

No responses yet