Middlebury

Difference between revisions of "Deploying a new Drupal 8 site"

Line 42: Line 42:
 
Update the cookbook version of web_drupal8 in metadata.rb
 
Update the cookbook version of web_drupal8 in metadata.rb
  
 +
 
  
 
==== web_drupal8/attributes/default.rb ====
 
==== web_drupal8/attributes/default.rb ====
Line 47: Line 48:
 
Use whichever install profile you picked when intializing the site for the value of ''':install_profile'''.
 
Use whichever install profile you picked when intializing the site for the value of ''':install_profile'''.
 
<pre>"SITE_URL" => {
 
<pre>"SITE_URL" => {
&nbsp; &nbsp; :database => "DATABASE_NAME",
+
&nbsp; &nbsp;&nbsp;:database => "DATABASE_NAME",
&nbsp; &nbsp; :install_profile => "middlebury_starter_profile",
+
&nbsp; &nbsp;&nbsp;:install_profile => "middlebury_starter_profile",
&nbsp; &nbsp; :config_sync_directory => '../config/SITE_NAME/sync',
+
&nbsp; &nbsp;&nbsp;:config_sync_directory => '../config/SITE_NAME/sync',
 
&nbsp; &nbsp; # Choose ONE of the following two lines as fits the needs of the site
 
&nbsp; &nbsp; # Choose ONE of the following two lines as fits the needs of the site
&nbsp; &nbsp; :file_public_base_url => 'https://www.middlebury.edu/SITE_NAME/sites/SITE_URL/files',
+
&nbsp; &nbsp;&nbsp;:file_public_base_url => 'https://www.middlebury.edu/SITE_NAME/sites/SITE_URL/files',
&nbsp; &nbsp; :file_public_base_url => 'https://SITE_NAME.middlebury.edu/sites/SITE_URL/files',
+
&nbsp; &nbsp;&nbsp;:file_public_base_url => 'https://SITE_NAME.middlebury.edu/sites/SITE_URL/files',
&nbsp; &nbsp; :file_public_path => 'sites/SITE_URL/files',
+
&nbsp; &nbsp;&nbsp;:file_public_path => 'sites/SITE_URL/files',
&nbsp; &nbsp; :trusted_host_patterns => [
+
&nbsp; &nbsp;&nbsp;:trusted_host_patterns => [
 
&nbsp; &nbsp; &nbsp; &nbsp; '^www\.middlebury\.edu$',
 
&nbsp; &nbsp; &nbsp; &nbsp; '^www\.middlebury\.edu$',
 
&nbsp; &nbsp; ]
 
&nbsp; &nbsp; ]
Line 60: Line 61:
 
</pre>
 
</pre>
  
 +
&nbsp;
  
 
==== web_drupal8/recipes/sites.rb ====
 
==== web_drupal8/recipes/sites.rb ====
Line 107: Line 109:
 
==== web_drupal8/files/update_all_drupal8_dbs ====
 
==== web_drupal8/files/update_all_drupal8_dbs ====
 
<pre>drush8 -r /var/www/drupal8/web --uri=SITE_URL updatedb</pre>
 
<pre>drush8 -r /var/www/drupal8/web --uri=SITE_URL updatedb</pre>
 +
 +
=== web_drupal Cookbook ===
 +
 +
Update the web_drupal cookbook version in metadata.rb.
 +
 +
==== web_drupal/recipes/sites.rb ====
 +
 +
Editing this file is only necessary for sites with the URL format www.middlebury.edu/SITE_NAME. Sites with the format SITE_NAME.middlebury.edu can skip to the cron.rb section.
 +
 +
Add a directory alias for /var/www/drupal8/web
 +
<pre># General Drupal8 settings.
 +
"/var/www/drupal8/web" => {
 +
    :directory_alias => [
 +
        "/institute",
 +
        "/bread-loaf-conferences/photos-and-bios",
 +
        "/SITE_PATH"
 +
    ],
 +
},</pre>
 +
 +
Add a site base to the section for drupal.htaccess.erb
 +
<pre>"etc/httpd/conf.d/drupal.htaccess.erb" => {
 +
&nbsp; &nbsp; :cookbook => "web_drupal8",
 +
&nbsp; &nbsp; :variables => ({
 +
&nbsp; &nbsp; &nbsp; &nbsp; 'rewrite_base' => '/',
 +
&nbsp; &nbsp; &nbsp; &nbsp; 'site_bases' => [
 +
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "/institute",
 +
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "/bread-loaf-conferences/photos-and-bios",
 +
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "/SITE_PATH",
 +
&nbsp; &nbsp; &nbsp; &nbsp; ],
 +
&nbsp; &nbsp; })
 +
},</pre>
 +
 +
Add a site header
 +
<pre>"etc/httpd/conf.d/drupal-site-header.erb" => {
 +
&nbsp; &nbsp; :cookbook => "web_drupal8",
 +
&nbsp; &nbsp; :variables => ({
 +
&nbsp; &nbsp; &nbsp; &nbsp; 'site_bases' => {
 +
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "/institute" => "www.middlebury.edu.institute",
 +
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "/bread-loaf-conferences/photos-and-bios" => "www.middlebury.edu.bread-loaf-conferences.photos-and-bios",
 +
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "/SITE_PATH" => "www.middlebury.edu.SITE_PATH_REPLACING_SLASHES_WITH_PERIODS",
 +
&nbsp; &nbsp; &nbsp; &nbsp; },
 +
&nbsp; &nbsp; })
 +
}</pre>
 +
 +
Add the following code to the end of the vhost_directories array, replacing values as appropriate
 +
<pre>"/var/www/drupal8/web/sites/SITE_NAME/files" => {
 +
  # Insert the Drupal rules from the .htaccess here so that they can be loaded at
 +
  # server-start rather than have the filesystem checked for every request.
 +
  :flags => {"AllowOverride" => "None"},
 +
  :partials => {"etc/httpd/conf.d/drupal-files.htaccess.erb" => {:cookbook => "web_drupal8"}}
 +
},</pre>
 +
 +
==== web_drupal/templates/default/etc/httpd/conf.d/drupal-general.rewrite.erb ====
 +
 +
Add a rewrite condition for the new sub-path.
 +
 +
Editing this file is only necessary for sites with the URL format www.middlebury.edu/SITE_NAME. Sites with the format SITE_NAME.middlebury.edu can skip to the cron.rb section.
 +
<pre style="margin: 0px;  padding: 0px;  color: rgb(9, 30, 66);  font-size: 14px;  font-style: normal;  font-variant-ligatures: normal;  font-variant-caps: normal;  font-weight: 400;  letter-spacing: normal;  orphans: 2;  text-align: left;  text-indent: 0px;  text-transform: none;  widows: 2;  word-spacing: 0px;  -webkit-text-stroke-width: 0px;  background-color: rgb(255, 255, 255);  text-decoration-style: initial;  text-decoration-color: initial">RewriteCond %{REQUEST_URI} !^/SITE_PATH/</pre>
 +
 +
==== web_drupal/recipes/cron.rb ====
 +
 +
In the drupal_purge_worker section
 +
<pre style="margin: 10px 0px 0px;  padding: 0px;  color: rgb(9, 30, 66);  font-size: 14px;  font-style: normal;  font-variant-ligatures: normal;  font-variant-caps: normal;  font-weight: 400;  letter-spacing: normal;  orphans: 2;  text-align: left;  text-indent: 0px;  text-transform: none;  widows: 2;  word-spacing: 0px;  -webkit-text-stroke-width: 0px;  background-color: rgb(255, 255, 255);  text-decoration-style: initial;  text-decoration-color: initial">"/var/www/drupal8/drush8 -q --root=/var/www/drupal8/web -l SITE_URL&nbsp;p-queue-work",</pre>
 +
 +
In the drupal_cron section
 +
<pre style="margin: 10px 0px 0px;  padding: 0px;  color: rgb(9, 30, 66);  font-size: 14px;  font-style: normal;  font-variant-ligatures: normal;  font-variant-caps: normal;  font-weight: 400;  letter-spacing: normal;  orphans: 2;  text-align: left;  text-indent: 0px;  text-transform: none;  widows: 2;  word-spacing: 0px;  -webkit-text-stroke-width: 0px;  background-color: rgb(255, 255, 255);  text-decoration-style: initial;  text-decoration-color: initial">"/var/www/drupal8/drush8 -q --root=/var/www/drupal8/web -l SITE_URL&nbsp;core-cron",</pre>
 +
 +
=== web_apache_config Cookbook ===
 +
 +
Increment the version in metadata.rb
 +
 +
==== templates/default/etc/httpd/conf.d/ssl-proxy_to_varnish-partial-midd.conf.erb ====
 +
 +
Add a rewrite condition for the new sub-path.
 +
<pre>RewriteCond %{REQUEST_URI} ^/SITE_PATH [NC,OR]</pre>
 +
 +
=== web_varnish_config Cookbook ===
 +
 +
Increment the version in metadata.rb
 +
 +
Block access to the site from off-campus while it is being built.
 +
 +
==== templates/default/etc/varnish/drupal.vcl.erb ====
 +
 +
Search for "# Block access to some hostnames from off-campus" and add the site path to the exclusion list.
 +
 +
=== Test the new Chef configuration ===
 +
<pre>knife cookbook upload web_apache_config
 +
knife cookbook upload web_drupal8
 +
knife cookbook upload web_drupal
 +
knife cookbook upload web_varnish_config
 +
 +
ssh drupaltest
 +
dzdo -s
 +
chef-client
 +
 +
ssh vole
 +
dzdo -s
 +
chef-client</pre>
 +
 +
Test the new site out by adding this to your HOSTS file.
 +
<pre>140.233.1.167 www.middlebury.edu</pre>
 +
 +
Load the nwe site in a browser and log in. Open the browser inspector and view your cookies. There will be one that looks like "SSESS0b011572177428d7211e023d0a5cb1f9", but with a different hash. Copy this into the place it belongs in the web_drupal8 sites.rb recipe and repeat the chef-client test.
  
 
== AzureAD Setup ==
 
== AzureAD Setup ==

Revision as of 16:55, 26 June 2019

Drupal Site Setup

Set up the varnish purger

  1. drush8 -y pm-enable purge purge_drush purge_queuer_coretags purge_tokens purge_ui varnish_purger varnish_purge_tags; drush8 -y cr;
  2. Go to /admin/config/development/performance/purge
  3. Click Add purger and add a Varnish purger
  4. Configure the varnish purger
    1. Name: Varnish
    2. Type: Tag
    3. Request
      1. Hostname: 140.233.1.178 140.233.1.177
      2. Port: 80
      3. Path: /
      4. Request Method: BAN
      5. Scheme: http
    4. Headers
      1. -
        1. Header: Cache-Tags
        2. Value: [invalidation:expression]
      2. -
        1. Header: host
        2. Value: www.middlebury.edu
      3. -
        1. Header: Drupal-Site
        2. Value: www.middlebury.edu.SITE_PATH
  5. Export your configuration. It will have an id which looks something like "dd61b69fad". This is the VARNISH_ID you will add to the Chef configuration below.

Configure Site Caching

Turn off gzip generation for CSS and JS files. Since varnish will be gzipping the files for us, Drupal does