|
1 | | -# eb-php-drupal |
2 | | -Configuration files for installing Drupal securely and running it in a load balanced AWS Elastic Beanstalk environment. |
| 1 | +# Deploying drupal on Elastic Beanstalk |
| 2 | +These instructions were tested with Drupal 8.2.2 |
| 3 | + |
| 4 | +## Install the EB CLI |
| 5 | + |
| 6 | +The EB CLI integrates with Git and simplifies the process of creating environments, deploying code changes, and connecting to the instances in your environment with SSH. You will perform all of these activites when installing and configuring Drupal. |
| 7 | + |
| 8 | +If you have pip, use it to install the EB CLI. |
| 9 | + |
| 10 | +``` |
| 11 | +$ pip install --user --upgrade awsebcli |
| 12 | +$ export PATH=~/.local/bin:$PATH |
| 13 | +``` |
| 14 | + |
| 15 | +If you don't have pip, follow the instructions [here](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html). |
| 16 | + |
| 17 | +## Download and extract Drupal and the configuration files |
| 18 | + |
| 19 | +``` |
| 20 | +~$ curl https://ftp.drupal.org/files/projects/drupal-8.2.2.tar.gz -o drupal.tar.gz |
| 21 | +~$ curl https://github.com/awslabs/eb-php-drupal/releases/download/v1.0/eb-php-drupal-v1.zip -o eb-php-drupal.zip |
| 22 | +~$ tar -xvf drupal.tar.gz && mv drupal-8.2.2 drupal-beanstalk && cd drupal-beanstalk |
| 23 | +~/drupal-beanstalk$ unzip ../eb-php-drupal.zip |
| 24 | +
|
| 25 | +## Create an environment |
| 26 | +~/drupal-beanstalk$ eb init --platform php5.6 --region us-east-2 |
| 27 | +(specify a different region if you have a preference) |
| 28 | +~/drupal-beanstalk$ eb ssh --setup |
| 29 | +~/drupal-beanstalk$ eb create drupal-beanstalk --sample --database |
| 30 | +(choose database username/password, CTRL+C to exit once create is in-progress) |
| 31 | +
|
| 32 | +## Networking configuration |
| 33 | +Modify the configuration files in the .ebextensions folder with the IDs of your [default VPC and subnets](https://console.aws.amazon.com/vpc/home#subnets:filter=default), and [your public IP address](https://www.google.com/search?q=what+is+my+ip). |
| 34 | +
|
| 35 | + - `.ebextensions/efs-create.config` creates an EFS file system and mount points in each Availability Zone / subnet in your VPC. |
| 36 | + - `.ebextensions/ssh.config` restricts access to your environment to your IP address to protect it during the Drupal installation process. |
| 37 | +
|
| 38 | +## Deploy Drupal to your environment |
| 39 | +Deploy the project code to your Elastic Beanstalk environment. |
| 40 | +
|
| 41 | +First, confirm that your environment is `Ready` with `eb status`. Environment creation takes about 15 minutes due to the RDS DB instance provisioning time. |
| 42 | +
|
| 43 | +``` |
| 44 | + $ eb status |
| 45 | + $ eb deploy |
| 46 | +``` |
| 47 | +
|
| 48 | +### NOTE: security configuration |
| 49 | +
|
| 50 | +This project includes a configuration file (`loadbalancer-sg.config`) that creates a security group and assigns it to the environment's load balancer, using the IP address that you configured in `ssh.config` to restrict HTTP access on port 80 to connections from your network. Otherwise, an outside party could potentially connect to your site before you install Drupal and configure your admin account. |
| 51 | +
|
| 52 | +You can [view the related SGs in the EC2 console](https://console.aws.amazon.com/ec2/v2/home#SecurityGroups:search=drupal-beanstalk) |
| 53 | +
|
| 54 | +## Install Drupal |
| 55 | +
|
| 56 | +Open your site in a browser. |
| 57 | +
|
| 58 | +``` |
| 59 | +~/drupal-beanstalk$ eb open |
| 60 | +``` |
| 61 | +
|
| 62 | +You are redirected to the Drupal installation wizard because the site has not been configured yet. |
| 63 | +
|
| 64 | +Perform a standard installation with the following settings for the database: |
| 65 | +
|
| 66 | + - Database name: `ebdb` |
| 67 | + - Database user and password: values that you entered during `eb create` |
| 68 | + - Advanced > database endpoint: The RDS endpoint listed in the [Beanstalk console](https://console.aws.amazon.com/elasticbeanstalk/home#/application/overview?applicationName=drupal-beanstalk) under `drupal-beanstalk` > `Configuration` > `Data Tier`, not including the port number. |
| 69 | +
|
| 70 | +Installation takes about a minute to complete. |
| 71 | +
|
| 72 | +# Save the site settings to source |
| 73 | +
|
| 74 | +The installation process created a file named `settings.php` in the `sites/default` folder on the instance. You need this file in your source code to avoid resetting your site on subsequent deployments, but the file currently contains secrets that you don't want to commit to source. |
| 75 | +
|
| 76 | +The project includes a settings file that uses environment variables to provide secrets to the application. Create a copy of this file named `settings.php`. |
| 77 | +
|
| 78 | +``` |
| 79 | +~/drupal-beanstalk$ cp beanstalk-settings.php sites/default/settings.php |
| 80 | +``` |
| 81 | +
|
| 82 | +This file reads variables for the database connection, which are provided by Elastic Beanstalk when you create a database instance inside your environment. It also reads variables named `HASH_SALT` and `SYNC_DIR`. |
| 83 | +
|
| 84 | +The hash salt can be any value but shouldn't be stored in source control. Use `eb setenv` to set this variable directly on the environment. |
| 85 | +``` |
| 86 | +~/drupal-beanstalk$ eb setenv HASH_SALT=randomnumbersandletters89237492374 |
| 87 | +``` |
| 88 | +
|
| 89 | +The sync directory is not a secret but is randomly generated when you install Drupal. Connect to the instance to find the value for this variable. Then, replace the placeholder value in `.ebextensions/drupal.config` with the correct value. |
| 90 | +``` |
| 91 | +~/drupal-beanstalk$ eb ssh |
| 92 | +[ec2-user ~]$ tail /var/app/current/sites/default/settings.php |
| 93 | +[ec2-user ~]$ exit |
| 94 | +``` |
| 95 | +
|
| 96 | +Remove the custom load balancer configuration to open the site to the Internet. |
| 97 | +``` |
| 98 | +~/drupal-beanstalk$ rm .ebextensions/loadbalancer-sg.config |
| 99 | +~/drupal-beanstalk$ eb deploy |
| 100 | +``` |
| 101 | +
|
| 102 | +Finally, scale up to run the site on multiple instances for high availability. |
| 103 | +``` |
| 104 | +~/drupal-beanstalk$ eb scale 3 |
| 105 | +``` |
| 106 | +
|
| 107 | +When the configuration update completes, open the site. |
| 108 | +``` |
| 109 | +~/drupal-beanstalk$ eb open |
| 110 | +``` |
| 111 | +
|
| 112 | +Refresh the site several times to verify that all instances are reading from the EFS file system. Create posts and upload files to confirm functionality. |
| 113 | +
|
| 114 | +# Backup |
| 115 | +
|
| 116 | +Now that you've gone through all the trouble of installing your site, you will want to back up the data in RDS and EFS that your site depends on. See the following topics for instructions. |
| 117 | +
|
| 118 | + - [DB Instance Backups](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.BackingUpAndRestoringAmazonRDSInstances.html) |
| 119 | + - [Back Up an EFS File System](http://docs.aws.amazon.com/efs/latest/ug/efs-backup.html) |
0 commit comments