5 May 2024
I've been working on an interesting SaaS project, where users can upload photos and lots of them. Therefore I needed a storage solution and since I am already using Linode (not affiliated), that's what I'll be using. In this post I'll detail how I set it up in my project and how you too can get Linode's object storage integrated into your Laravel application.Object Storage
menu and from there click on Create bucket
. Give your bucket a suited name and select a region. Remember these values as they will be used later.
With your bucket created click over to the Access Keys
-tab and click Create Access Key
. In the menu select your newly created bucket and give it the desired permissions. This will give you your access key and access secret, which you'll also need later.
This concludes the setup at Linode and we can move on to the Laravel application.
flysystem
-package in Laravel. Use the following command to do so:
composer require league/flysystem-aws-s3-v3 ^3.0
Then we need to setup some environment variables in the .env
-file of your Laravel application.
LINODE_KEY=
LINODE_SECRET=
LINODE_ENDPOINT=eu-central-1.linodeobjects.com
LINODE_REGION=eu-central-1
LINODE_BUCKET=test
Fill in the information you got when setting up your bucket and access . Please note that the LINODE_ENDPOINT is comprised of the region and .linodeobjects.com (it doesn't include the bucket name).
config/filesystems.php
config file and add the following in the disks
array.
'disks' => [
'linode' => [
'driver' => 's3',
'key' => env('LINODE_KEY'),
'secret' => env('LINODE_SECRET'),
'endpoint' => env('LINODE_ENDPOINT'),
'region' => env('LINODE_REGION'),
'bucket' => env('LINODE_BUCKET'),
],
]
If you want to use the Linode storage as your default storage, you can now add the following to your .env
-file.
FILESYSTEM_DISK=linode
At this point I like to verify that my connection is working. You can do this by adding the following piece of code in your Laravel application and running it.
\Illuminate\Support\Facades\Storage::put('test.txt', '123');
If your connection is working, this should place a simple test.txt
file in the root of your storage.
'throw' => true
option in your config/filesystems.php
. The option (if set to true) throws an exception when write operations fail and gives you a bit of info as to why.
The Seven Restful Controller Actions in Laravel
Published 2024-05-05 — Updated 2024-05-16
Laravel
PHP
Web development
The seven RESTful actions and how you could implement them in Laravel
Read the post →Useful Laravel packages
Published 2024-05-05
Laravel
PHP
Web development
Learn what packages that can help you build even better websites in Laravel. We'll go trhough the must-haves and packages that are just nice to have.
Read the post →Getting title tag and meta tags from a website using PHP
Published 2024-05-14
PHP
Web development
Learn how to easily webscrape title and meta tags from a website using simple PHP commands.
Read the post →