Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Deploy Your Own S3 Server

This tutorial is way out of date, and needs updating to use the "zenko" cloudserver docker image. MiniIO looks like another possible alternative.

One of my biggest issues with using AWS S3 is the feeling that I'm tying myself in and possibly getting bitten if AWS increase their prices or suddenly decides to no longer provide or support the service. The Scality S3 server resolves this issue for me, giving me the freedom to change provider (self-hosting) without having to change my codebase. This also means that you can use S3 to begin with, and switch to self-hosting later to save money at scale, or possibly improve performance.

This tutorial aims to get you set up as quickly as possible with your own object storage server, by using docker and your server's local file storage. There are other storage configuration possibilities, and you don't have to use docker, but we will cover that in later tutorials.

Minimum Requirements

  • 1 vCPU
  • 1 GB of RAM

Steps

Run the following commands to create a local are where your data will be stored, and deploy the application.

mkdir -p $HOME/s3-data/data
mkdir -p $HOME/s3-data/metadata

docker run -d \
  --name s3server \
  --restart=always \
  -e SCALITY_ACCESS_KEY_ID=myKeyID \
  -e SCALITY_SECRET_ACCESS_KEY=mySecretKey \
  -v $HOME/s3-data/data:/usr/src/app/localData \
  -v $HOME/s3-data/metadata:/usr/src/app/localMetadata \
  -p 8000:8000 \
  scality/s3server

You will want to change the SCALITY_ACCESS_KEY_ID and SCALITY_SECRET_ACCESS_KEY values to something else, but make sure to take this into account in the future sections of this tutorial.

Congratulations, you now have a self-hosted S3-compatible object storage server.

Testing

Now let's demonstrate how to use your S3 server in PHP, using the AWS SDK to prove that it is compatible and you don't have to change your existing codebase.

Create a folder on your laptop or client server. We will work in here.

Use composer to install the SDK. We need to use version 3.

composer require "aws/aws-sdk-php:3.31.*"

Then copy/paste the following script in that folder.

<?php

require_once(__DIR__ . '/vendor/autoload.php');

# Specify the IP of the S3 server you deployed
# You cannot use a hostname (yet)
define('S3_SERVER_IP', '192.168.1.x');

$client = Aws\S3\S3Client::factory([
    'region' => 'us-east-1',
    'version' => 'latest',
    'use_path_style_endpoint' => true,
    'endpoint' => 'http://' . S3_SERVER_IP . ':8000',
    'credentials' => [
        'key' => 'myKeyID',
        'secret' => 'mySecretKey'
    ]
]);

$client->createBucket(array(
    'Bucket' => 'bucketphp',
));

Execute the script and you will have created your first bucket.

Conclusion

You now have working S3 server. Unfortunately, it is currently limited to the storage capacity of your one server for now and you cannot use a hostname to identify your S3 server. We will address those issues in future.

References and Useful Links

Last updated: 26th October 2021
First published: 16th August 2018