Skip to content
This repository was archived by the owner on Feb 13, 2023. It is now read-only.

Commit e9c5cef

Browse files
committed
Fixes #84: Make Drupal VM prod-ready (with a DigitalOcean guide).
1 parent 532ccf7 commit e9c5cef

File tree

7 files changed

+103
-18
lines changed

7 files changed

+103
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ config.yml
88
drupal.make.yml
99
Vagrantfile.local
1010
examples/prod/inventory
11+
examples/prod/bootstrap/vars.yml
1112
scripts/
1213
roles/

examples/prod/README.md

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
# Drupal VM Production Configuration Example
22

3+
> **Important**: This feature is currently in 'experimental' status, and the security of your servers is _your_ responsibility.
4+
35
This directory contains an example production configuration for Drupal VM which can be used to deploy Drupal VM to a production environment on a cloud provider like DigitalOcean, Linode, or AWS.
46

5-
This README file contains instructions for how you can use this configuration file to build a Drupal environment on DigitalOcean.
7+
This README file contains instructions for how you can use this configuration file to build a Drupal environment with Drupal VM on DigitalOcean.
68

7-
## Creating a DigitalOcean Droplet
9+
## Create a DigitalOcean Droplet
810

911
If you don't already have a DigitalOcean account, create one (you can use geerlingguy's [affiliate link](https://www.digitalocean.com/?refcode=b9c57af84643) to sign up, otherwise, visit the normal [DigitalOcean Sign Up form](https://cloud.digitalocean.com/registrations/new).
1012

1113
Make sure you have an SSH key you can use to connect to your DigitalOcean droplets, and if you don't already have one set up, or if you need to add your existing key to your account, follow the instructions in this guide: [How to use SSH keys with DigitalOcean Droplets](https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets).
1214

1315
Once you are logged into DigitalOcean and have added your SSH key, click the 'Create Droplet' button on your Droplets page. For the Droplet, choose the following options:
1416

15-
- **Hostname**: Choose a hostname for your site (e.g. `example.drupalvm.com`)
17+
- **Image**: Choose `Ubuntu 14.04.x x64`
1618
- **Size**: 1 GB / 1 CPU (currently $10/month; you can choose a higher plan if needed)
1719
- **Region**: Choose whatever region is geographically nearest to you and your site visitors
1820
- **Settings**: (Nothing here affects how Drupal VM works, choose what you'd like)
19-
- **Image**: Choose `Ubuntu 14.04 x64`
2021
- **Add SSH Keys**: Select the SSH key you added to your account earlier.
22+
- **Hostname**: Choose a hostname for your site (e.g. `example.drupalvm.com`)
2123

2224
Click 'Create Droplet', and wait a minute or so while the Droplet is booted. Once it's booted, make sure you can log into it from your local computer:
2325

24-
ssh root@[droplet-hostname]
26+
ssh root@[droplet-hostname-or-ip]
2527

26-
(Make sure you replace `[droplet-hostname]`) with the hostname or IP address of your Droplet!)
28+
(Make sure you replace `[droplet-hostname-or-ip]`) with the hostname or IP address of your Droplet!)
2729

2830
If you get a warning like "the authenticity of the host can't be established", answer yes to the prompt and hit enter. You should now be logged into the Droplet. Log back out by typing `exit` at the prompt and hitting return.
2931

3032
Your DigitalOcean Droplet is booted and ready to have Drupal VM installed on it.
3133

32-
## Customizing `config.yml` and `inventory` for production
34+
## Customize `config.yml` and `inventory` for production
3335

3436
Just like you would with the normal `example.config.yml`, you need to copy the file to `config.yml`, then go through `prod.overrides.yml` (in this directory), and make sure to update your `config.yml`, making sure all the variables are set to match `prod.overrides.yml`.
3537

@@ -38,18 +40,43 @@ The changes outlined in `prod.overrides.yml` disable development-environment too
3840
The only other thing you need to do is copy the inventory file `example.inventory` to `inventory` (so it is located at `prod/inventory`). By default, it reads:
3941

4042
[drupalvm]
41-
1.2.3.4 ansible_ssh_user=root
43+
1.2.3.4 ansible_ssh_user=my_admin_username
44+
45+
Change the host `1.2.3.4` to either the IP address or the hostname of your DigitalOcean Droplet. Remember that if you would like to use a hostname, you need to make sure the hostname actually resolves to your Droplet's IP address, either in your domain's public DNS configuration, or via your local hosts file.
46+
47+
## Initialize the server with an administrative account
48+
49+
> Note: This guide assumes you have Ansible [installed](http://docs.ansible.com/ansible/intro_installation.html) on your host machine.
50+
51+
The first step in setting up Drupal VM on the cloud server is to initialize the server with an administrative account (which is separate from the `root` user account for better security).
4252

43-
Change the host `1.2.3.4` to either the IP address or the hostname of your DigitalOcean Droplet. Remember that if you would like to use a hostname, you need to make sure that hostname actually resolves to your Droplet's IP address, either in your domain's public DNS configuration, or via your local hosts file.
53+
Inside the `examples/prod/bootstrap` folder, copy the `example.vars.yml` file to `vars.yml` and update the variables in that file for your own administrative account (make sure especially to update the `admin_password` value!).
4454

45-
## Provisioning Drupal VM on the Droplet
55+
Then, run the following command within Drupal VM's root directory (the folder containing the `Vagrantfile`):
4656

47-
Run the following command within this project's root directory (the folder containing the `Vagrantfile`):
57+
ansible-playbook -i examples/prod/inventory examples/prod/bootstrap/init.yml -e "ansible_ssh_user=root"
4858

49-
ansible-playbook -i examples/prod/inventory provisioning/playbook.yml --sudo
59+
Once the initialization is complete, you can test your new admin login with `ssh my_admin_username@droplet-hostname-or-ip`. You should be logged in via your existing SSH key. Log back out with `exit`.
60+
61+
## Provision Drupal VM on the Droplet
62+
63+
Run the following command within Drupal VM's root directory (the folder containing the `Vagrantfile`):
64+
65+
ansible-playbook -i examples/prod/inventory provisioning/playbook.yml --sudo --ask-sudo-pass
66+
67+
Ansible will prompt you for your admin account's `sudo` password (the same as the password you encrypted and saved as `admin_password`). Enter it and press return.
5068

5169
After a few minutes, your Drupal-VM-in-the-cloud Droplet should be fully configured to match your local development environment! You can visit your Droplet and access the fresh Drupal site just like you would locally (e.g. `http://example.drupalvm.com/`).
5270

53-
## Going Further
71+
## Known issues
72+
73+
- The `files` folder that is generated during the initial Drupal installation is set to be owned by the admin account; to make it work (and to allow Drupal to generate stylesheets and files correctly), you have to manually log into the server and run `sudo chown -R www-data:www-data /var/www/drupalvm/drupal/sites/default/files` after initial provisioning is complete.
74+
- You can't synchronize folders between your host machine and DigitalOcean (at least not in any sane way); so you'll need to either have Drupal VM install a site from a given Drush make file or composer.json, or deploy your site yourself.
75+
- The way you build a production Drupal VM instance (vs. a local instance) is a little bit of a kludge. Follow https://github.com/geerlingguy/drupal-vm/issues/455 to track progress on a more streamlined process.
76+
- Drupal VM doesn't include any kind of backup system. You should use one if you have any kind of important data on your server!
77+
78+
## Go Further
79+
80+
You can use Ubuntu 12.04, Ubuntu 14.04, CentOS 6 or CentOS 7 when you build the DigitalOcean Droplet. Just like with Drupal VM running locally, you can customize almost every aspect of the server!
5481

55-
You may want to customize your configuration further, to make sure Drupal VM is tuned for your specific Drupal site's needs, or you may want to change things and make the server configuration more flexible, etc. For all that, the book [Ansible for DevOps](http://ansiblefordevops.com/) will give you a great introduction to using Ansible to make Drupal VM and the included Ansible configuration do exactly what you need!
82+
You may want to customize your configuration even further, to make sure Drupal VM is tuned for your specific Drupal site's needs, or you may want to change things and make the server configuration more flexible, etc. For all that, the book [Ansible for DevOps](http://ansiblefordevops.com/) will give you a great introduction to using Ansible to make Drupal VM and the included Ansible configuration do exactly what you need!
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
admin_user: my_admin_username
3+
4+
# On RHEL/CentOS, 'wheel'; on Debian/Ubuntu, 'root'.
5+
admin_group: root
6+
7+
# IMPORTANT: Configure your own password for the admin user account. To generate
8+
# a password hash, use either of the following commands:
9+
# - `openssl passwd -1 [password]`
10+
# - `mkpasswd --method=SHA-512`.
11+
admin_password: $1$HgT69GsW$qZ8FUJHafZZWD76KXgAZO/
12+
13+
# Configuration for copying local public SSH key to admin's authorized_keys.
14+
admin_copy_ssh_pubkey: true
15+
admin_pubkey: ~/.ssh/id_rsa.pub

examples/prod/bootstrap/init.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
- hosts: drupalvm
3+
4+
vars_files:
5+
- vars.yml
6+
7+
tasks:
8+
- name: Create admin user account.
9+
user:
10+
name: "{{ admin_user }}"
11+
createhome: yes
12+
home: "/home/{{ admin_user }}"
13+
generate_ssh_key: yes
14+
ssh_key_comment: "ansible-{{ inventory_hostname }}"
15+
password: "{{ admin_password }}"
16+
groups: "{{ admin_group }}"
17+
shell: /bin/bash
18+
19+
- name: Add local SSH public key to admin account authorized_keys.
20+
authorized_key:
21+
user: "{{ admin_user }}"
22+
key: "{{ lookup('file', '{{ admin_pubkey }}') }}"
23+
manage_dir: yes
24+
25+
- name: Disable requiretty.
26+
lineinfile:
27+
dest: /etc/sudoers
28+
regexp: '^Defaults.+requiretty'
29+
line: 'Defaults !requiretty'
30+
state: present

examples/prod/example.inventory

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[drupalvm]
2-
1.2.3.4 ansible_ssh_user=root
2+
1.2.3.4 ansible_ssh_user=my_admin_username

examples/prod/prod.overrides.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ mysql_root_password: root
1111
# Only install extras that you will need/use on your site, and don't install
1212
# development-related software on production environments!
1313
installed_extras:
14-
- memcached
14+
# - memcached
15+
# - redis
1516
# - solr
1617
- varnish
1718

19+
# Disable the dashboard page. Also remove any unneeded virtualhosts.
20+
dashboard_install_dir: ''
21+
1822
# Enable a more hardened security configuration.
1923
extra_security_enabled: true
2024

@@ -23,7 +27,6 @@ firewall_allowed_tcp_ports:
2327
- "22"
2428
- "80"
2529
- "443"
26-
- "8983"
2730
firewall_log_dropped_packets: true
2831

2932
# Set Apache to listen on port 81 (internal only), and Varnish on 80.

provisioning/tasks/build-makefile.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@
99
file:
1010
path: "{{ drupal_core_path }}"
1111
state: directory
12+
recurse: yes
13+
mode: 0775
14+
when: drupal_site.stat.exists == false
15+
16+
- name: Ensure drupal_core_path directory is owned by ssh user.
17+
file:
18+
path: "{{ drupal_core_path }}"
19+
state: directory
20+
owner: "{{ ansible_ssh_user }}"
21+
group: "{{ ansible_ssh_user }}"
1222
mode: 0775
13-
become: no
1423
when: drupal_site.stat.exists == false
1524

1625
- name: Generate Drupal site with drush makefile.

0 commit comments

Comments
 (0)