Drupal S3

broken image


Drupal 9 The next generation of Drupal is here. The most powerful Open Source CMS just got stronger. With best-in-class flexibility, speed and scale, Drupal 9 takes the platform to the next level. CDN Drupal CDN & Static File Server - The Amazon S3 Way by Quinton Figueroa on December 1st, 2008 If you build quality sites that attract a large number of visitors and interaction there eventually will come a point when you have to start looking for ways to offload your files and bring down your server overhead.

  1. Drupal S3 Plugin
  2. Wordpress S3 Upload

Drupal Environment Variables

In our hosting environment we use a core Drupal 8 Docker container replicated across Amazon EC2 instances with Elastic Container Service. Each of these sites is technically a fully functional independent site with its own domain name, 3 seperate environments, and independent Drupal 8 configuration. So how do we achieve these different site requirements with a single Drupal 8 core Docker container? We can start by using environment variables.

File

Docker Compose

Docker Compose allows us to launch a docker container from an image using a .yml file to define the configuration.

Here's a sample docker-compose.yml used to launch a website in our environment. Specifically see the drupal -> environment section to see environment variables.

docker-compose.yml
version: '2.1' services: drupal_db: image: mysql:5.7 container_name: drupal_db environment: MYSQL_ROOT_PASSWORD: drupal drupal: image: drupal_core:latest container_name: drupal ports: - 8088:80 environment: DB_NAME: 'drupal' DB_USER: 'root' DB_PASS: 'drupal' DB_HOST: 'drupal_db' S3_BUCKET: ' S3_ROOT_FOLDER: 'local' S3FS_ACCESS_KEY: ' S3FS_SECRET_KEY: ' SITE_NAME: 'Drupal Core - LOCAL' API_KEY: ' links: - drupal_db

When the docker container is lauched via docker-compose these variables will be avaialbe as ENV variables in your hosting environment. These can be accessed in PHP via getenv('env_var').

Consuming ENV with settings.php

Include a local.settings.php to extend settings.php. use getenv() to pull the ENV variables into PHP and then apply to Drupal configuration.

Drupal S3 Plugin

Database Settings
//Database$dbName=getenv('DB_NAME');$dbUser=getenv('DB_USER');$dbPass=getenv('DB_PASS');$host=getenv('DB_HOST');//apply those variables$databases['default']['default'] = array ( 'database' => $dbName, 'username' => $dbUser, 'password' => $dbPass, 'prefix' => ', 'host' => $host, 'port' => ', 'namespace' => 'DrupalCoreDatabaseDrivermysql', 'driver' => 'mysql',);

Drupal

S3 Settings
//S3$s3Bucket=getenv('S3_BUCKET');$s3RootFolder=getenv('S3_ROOT_FOLDER');$s3AccessKey=getenv('S3FS_ACCESS_KEY');$s3SecretKey=getenv('S3FS_SECRET_KEY');//apply those variables$config['s3fs.settings']['bucket']=$s3Bucket;$config['s3fs.settings']['root_folder']=$s3RootFolder;$settings['s3fs.access_key']=$s3AccessKey;$settings['s3fs.secret_key']=$s3SecretKey;$settings['s3fs.use_s3_for_public'] = TRUE;

Site Specifics
$config['system.site']['name'] = getenv('SITE_NAME');

Environment Variables Breakdown

The follow table lists and describes each environment variable we use to customize Drupal 8.

Environment VariablePurpose
DB_NAMEThe database name this site uses
DB_PASSThe password for the database
DB_HOSTThe hostname for the database. If running locally typically this is a linked docker container. If hosting in the cloud (AWS) use the host name
DB_HOSTThe hostname for the database. If running locally typically this is a linked docker container. If hosting in the cloud (AWS) use the host name
S3_BUCKETThe s3 bucket where your images and assets will be stored
S3_ROOT_FOLDERThe folder inside S3_BUCKET. This is typically environment specific, DEV/STG/PROD
S3FS_ACCESS_KEYThe AWS access key used to upload files to S3_BUCKET. This is required along with the S3FS_SECRET_KEY
S3FS_SECRET_KEYThe AWS secret used to upload files to S3_BUCKET. This is required along with the S3FS_ACCESS_KEY
SITE_NAMEThe name of the site. Visible via the Drupal template
API_KEYUsed to connect to AWS API Gateway
Drupal S3

Docker Compose

Docker Compose allows us to launch a docker container from an image using a .yml file to define the configuration.

Here's a sample docker-compose.yml used to launch a website in our environment. Specifically see the drupal -> environment section to see environment variables.

docker-compose.yml
version: '2.1' services: drupal_db: image: mysql:5.7 container_name: drupal_db environment: MYSQL_ROOT_PASSWORD: drupal drupal: image: drupal_core:latest container_name: drupal ports: - 8088:80 environment: DB_NAME: 'drupal' DB_USER: 'root' DB_PASS: 'drupal' DB_HOST: 'drupal_db' S3_BUCKET: ' S3_ROOT_FOLDER: 'local' S3FS_ACCESS_KEY: ' S3FS_SECRET_KEY: ' SITE_NAME: 'Drupal Core - LOCAL' API_KEY: ' links: - drupal_db

When the docker container is lauched via docker-compose these variables will be avaialbe as ENV variables in your hosting environment. These can be accessed in PHP via getenv('env_var').

Consuming ENV with settings.php

Include a local.settings.php to extend settings.php. use getenv() to pull the ENV variables into PHP and then apply to Drupal configuration.

Drupal S3 Plugin

Database Settings
//Database$dbName=getenv('DB_NAME');$dbUser=getenv('DB_USER');$dbPass=getenv('DB_PASS');$host=getenv('DB_HOST');//apply those variables$databases['default']['default'] = array ( 'database' => $dbName, 'username' => $dbUser, 'password' => $dbPass, 'prefix' => ', 'host' => $host, 'port' => ', 'namespace' => 'DrupalCoreDatabaseDrivermysql', 'driver' => 'mysql',);

S3 Settings
//S3$s3Bucket=getenv('S3_BUCKET');$s3RootFolder=getenv('S3_ROOT_FOLDER');$s3AccessKey=getenv('S3FS_ACCESS_KEY');$s3SecretKey=getenv('S3FS_SECRET_KEY');//apply those variables$config['s3fs.settings']['bucket']=$s3Bucket;$config['s3fs.settings']['root_folder']=$s3RootFolder;$settings['s3fs.access_key']=$s3AccessKey;$settings['s3fs.secret_key']=$s3SecretKey;$settings['s3fs.use_s3_for_public'] = TRUE;

Site Specifics
$config['system.site']['name'] = getenv('SITE_NAME');

Environment Variables Breakdown

The follow table lists and describes each environment variable we use to customize Drupal 8.

Environment VariablePurpose
DB_NAMEThe database name this site uses
DB_PASSThe password for the database
DB_HOSTThe hostname for the database. If running locally typically this is a linked docker container. If hosting in the cloud (AWS) use the host name
DB_HOSTThe hostname for the database. If running locally typically this is a linked docker container. If hosting in the cloud (AWS) use the host name
S3_BUCKETThe s3 bucket where your images and assets will be stored
S3_ROOT_FOLDERThe folder inside S3_BUCKET. This is typically environment specific, DEV/STG/PROD
S3FS_ACCESS_KEYThe AWS access key used to upload files to S3_BUCKET. This is required along with the S3FS_SECRET_KEY
S3FS_SECRET_KEYThe AWS secret used to upload files to S3_BUCKET. This is required along with the S3FS_ACCESS_KEY
SITE_NAMEThe name of the site. Visible via the Drupal template
API_KEYUsed to connect to AWS API Gateway
reference deployment

Deploy Drupal using Amazon RDS, Amazon S3, and other AWS services

This Quick Start deploys a highly available Drupal architecture on the Amazon Web Services (AWS) Cloud.

Drupal is an open-source, content management platform written in the PHP server-side scripting language. Drupal provides a backend framework for many enterprise websites. Deploying Drupal on AWS makes it easy to use AWS services to further enhance the performance and extend functionality of your content management framework.

Wordpress S3 Upload

The deployment uses Amazon Elastic Compute Cloud (Amazon EC2), Amazon Virtual Private Cloud (Amazon VPC), Amazon Relational Database Service (Amazon RDS), Amazon Elastic File System (Amazon EFS), Amazon ElastiCache, Amazon CloudFront, and Amazon Route 53.

This reference architecture is automated by AWS CloudFormation templates that deploy the Drupal environment on AWS in about 30 minutes. You can customize the templates to meet your specific requirements.

This Quick Start was developed by
AWS solutions architects.

  • What you'll build
  • Use this Quick Start to set up the following Drupal environment on AWS:

    • A virtual private cloud (VPC) that is configured across two Availability Zones. For each Availability Zone, this Quick Start provisions one public subnet and one private subnet, according to AWS best practices.*
    • In the public subnets, Linux bastion hosts in an AWS Auto Scaling group to provide secure access to allow inbound Secure Shell (SSH) access to Amazon EC2 instances in the private subnets.*
    • In the public subnets, managed network address translation (NAT) gateways to provide outbound internet connectivity for instances in the private subnets.*
    • In the private subnets, a web server instance (Amazon Machine Image, or AMI) in an AWS Auto Scaling group to host the Drupal servers and Amazon Aurora database instances.
    • AWS Auto Scaling, which allows the Drupal cluster to add or remove servers based on use.
    • Integration of AWS Auto Scaling with Elastic Load Balancing, which automatically adds and removes instances from the load balancer. The default installation sets up low and high CPU-based thresholds for scaling the instance capacity up or down.
    • Amazon Elastic File System (Amazon EFS), which provides simple, scalable file storage for use with Amazon EC2 instances.
    • An AWS Identity and Access Management (IAM) role to enable AWS resources created through the Quick Start to access other AWS resources when required.*
    • Amazon ElastiCache for caching database queries and Drupal sessions.
    • Amazon CloudFront as the content delivery network to speed up distribution of static and dynamic content from Drupal to end users.
    • Amazon Route 53 as your public Domain Name System (DNS) for resolving the domain name of your Drupal site.

    * The template that deploys the Quick Start into an existing VPC skips the tasks marked by asterisks and prompts you for your existing VPC configuration.

  • How to deploy
  • You can build your Drupal environment on AWS in about 30 minutes, by following the instructions in the deployment guide. The deployment process includes these steps:

    1. If you don't already have an AWS account, sign up at https://aws.amazon.com.
    2. Launch the Quick Start. You can choose from two options:
    3. Log in to the Drupal administrator site to test your deployment.
    4. Use the Drupal administrator site to create content.

    The Quick Start includes parameters that you can customize to best meet your business, IT, and security requirements.

    Amazon may share user-deployment information with the AWS Partner that collaborated with AWS on the Quick Start.

  • Cost and licenses
  • This deployment launches Drupal 7 or Drupal 8 automatically into a configuration of your choice. Drupal is open-source software. It is licensed under GNU GPL version 2. For additional details about Drupal's licensing, see the Drupal website.

    You are responsible for the cost of the AWS services used while running this Quick Start reference deployment. There is no additional cost for using the Quick Start. See the pricing pages for each AWS service you will be using for cost estimates.

    The AWS CloudFormation templates for this Quick Start include configuration parameters that you can customize. Some of these settings, such as instance type, will affect the cost of deployment. See the pricing pages for each AWS service you will be using for cost estimates.





broken image