This article describes how to install Varnish 4 with Drupal 7 on Ubuntu 16.04. The procedure is similar to installing Varnish 3 in my Drupal recipe, but the update to Varnish 4 requires a few changes. These are described below. Installing Varnish 4 Run apt-get install varnish. Then ensure your /etc/default/varnish has the correct startup […]
Tag: Drupal
Installing Drush 8
Previously I discussed how to install Drush 6.x for use with Drupal 7. Here we’ll install Drush 8 for Drupal 8, specifically using Ubuntu 16.04 Server. The recommended method is to install using PHP’s Composer. First we install Composer itself: Then, install unzip to speed things up: Installing and Testing Drush 8 Install Drush 8.x: […]
Ubuntu 16.04 Web Server with Nginx, MariaDB, Redis, and Drupal 8
As mentioned in my Ubuntu 16.04 and Drupal 7 article, the Ubuntu 16 LTS version has some nice upgrades, including PHP 7, MySQL 5.7, Nginx 1.10, Apache 2.4.18, and MariaDB 10.0.x. Let’s see if we can make it work with Nginx, PHP-FPM, MariaDB, and Drupal 8, using the Redis key-value store as the backend cache […]
Drupal 7: Display Page Elements Conditionally
In Drupal you often need to show page elements conditionally, usually based on variables like the URL or user identity. Fortunately, the Drupal API offers several functions that can help: hook_html_head_alter() template_preprocess_page() template_preprocess_html() drupal_match_path() drupal_get_http_header() user_is_logged_in() or user_is_anonymous() Modify the Page Header To add a tag to the header on every page, use hook_html_head_alter() in […]
Using jQuery UI with Drupal 7
Like jQuery, the jQuery UI user interface library (version 1.8.7) is already included and registered by the system module of Drupal 7. All you need to do is enable it. You can include jQuery UI in the PHP editor of a single node or module: If you add an individual effect, Drupal will add the […]
Ubuntu 16.04 Web Server with Nginx, MariaDB, Redis, and Drupal 7
The Drupal 8 version of this article can be found here. As of today, April 21, 2016, Canonical has released Ubuntu 16.04 Server, supported until 2021. Ubuntu 16.04 has some nice enhancements, and some changes that will affect sysadmins and developers: it ships with Python 3 as the default Python, plus PHP 7, MySQL 5.7, […]
Drupal 7 Search Engine Optimization (SEO)
So I recently migrated my web site to Drupal after running it in WordPress for several years. Not surprisingly for a redesign where all the URLs changed and much content was added, my traffic numbers cratered, but after some tinkering they’ve gone back up again. After this little experiment with SEO, here are some things […]
Drupal: Programmatically Create a Block
So you want to add a block to your module in Drupal 7. First, define its internal name and human-readable title (for the Blocks UI) with hook_block_info(): /** * Implements hook_block_info(). */ function YOUR-MODULE_block_info() { $blocks = array(); $blocks[’YOUR-BLOCK-NAME’] = array( ‘info’ => t(‘MY BLOCK TITLE’), ‘cache’ => DRUPAL_NO_CACHE ); return $blocks; } Then, give […]
Customize the Drupal Search Form
Here’s an easy one: you want to customize the Drupal search form provided by the Search module in your Drupal 7 site. Fortunately, Drupal provides an easy way to do this, via hook_form_alter(). Put something like this in your theme’s template.php: /** * Alter the search block form. */ function YOUR-THEME-NAME_form_alter(&$form, &$form_state, $form_id) { if […]
Drupal Module Development Tutorial
On my Drupal 7 site here, I wanted to create a method of automatically injecting my Google Ad banners on all content pages before the Disqus comments thread. You could do this manually, say by adding a text field to your basic page content_type with a default value of all the Google Ads JavaScript, but […]