Hi! I'm struggling hard with installing Google AMP. After spending a couple months just to add the module (technical issues) I finally got it up and running and have been trying to get it to work for a while. Apparently this module requires something called Lullabot which needs to be installed through Composer Manager. Unless I am missing some very big step, it seems no instructions are provided anywhere to tell me how to use Composer Manager OR where to find Lullabot, haha.

When I open composer manager, this is what I see:

Package Installed Version Version Required by Module
lullabot/amp Not installed ^1.0.0
Required by: Accelerated Mobile Pages (AMP)

I'm guessing it's already loaded and ready to install, which probably came from the module. There's no install button, though, but there is a note saying " Composer's install command must be run to generate the autoloader and install the required packages.
Refer to the instructions on the Composer Manager project page for installing packages." I imagine this is the instructions for installing something, but clicking that link does not take me to anything helpful.

I tried googling information on how to use Composer Manager, but nothing clear is available. Mostly people talk about what it does, not how to use it. It sounds like it's something that runs itself in the background, but then here I am trying to install Lullabot.

What do I need to do at this point to get AMP working?

Sorry if this sounds like an odd question or a simple fix, but this is a huge roadblock for us. If it is, maybe there's something about Drupal I'm missing. It seems that these are elaborate modules which probably work very well, but are not usable because of a lack of instructions. Drupal's frustrating that way. Most applications are like that, though.

Thanks!

Comments

VM’s picture

Do you have composer installed in your environment? Without it's CLI you cannot utilize composer features nor will composer download required libraries.

https://www.drupal.org/docs/develop/using-composer/using-composer-to-man...

As an aside the lack of instruction/direction is also partly your fault as a member of this community. Many (if not most) users, like yourself, aren't taking the time to contribute back documentation to expand on what is already available. Developers most often develop code not docs. The rest of the community used to take the time to develop docs and put forth a contribution. New users were the best doc generators as they would often be the people that would often hit walls others wouldn't which put them in a perfect position to write documentation for other users (particularly of the same skill level).

q0rban’s picture

Hi @bdparker! It's a pleasure to meet you.

I'm guessing since you are mentioning Composer Manager that this is a Drupal 7 site. If I'm wrong and this is Drupal 8, let me know.

At any rate, I'm going to start by mentioning a few things that you likely already know but if not would be good to start with.

There are a few components interacting here and it might be confusing which is which.

  1. Composer is a PHP dependency manager. It's a command-line tool that helps manage the complexities of downloading various PHP packages and their dependencies. It's not something unique to Drupal (i.e., other PHP applications use it). With Drupal 8, it's become the standard and "best-practices" way to download and install modules, themes, or other PHP libraries.
  2. Composer Manager is a Drupal module to help Drupal 7 sites that want to use Composer to download modules.
  3. There is an AMP Drupal module and an AMP PHP library. The Drupal module needs the PHP library to work—or, put another way, the library is a dependency of the module. Composer is the glue used for the module to say "I need the AMP PHP Library", and Composer Manager is the glue to say "oh and by the way, I'm doing this in Drupal 7." (Apologies, I'm over-simplifying here).
  4. Lullabot is (among other things) a Drupal development company that worked with Google to create the AMP Drupal module and the AMP PHP Library. There's no "Lullabot" to install (although that would be really cool if there was!)—the reason you see Lullabot mentioned is because in "Composer-speak", lullabot is the "vendor" for the PHP library.

Now that we've established some of those things, my questions for you:

  • How have you normally downloaded and installed Drupal modules for your site in the past?
  • Do you have command-line access to your site?
  • If yes, how comfortable are you using the command-line?
  • Are you using version control for your site?

Good work on getting this far on installing the module!

Cheers, James

Pahkis’s picture

Hi,

Good basic information, but, still the same as can be found in the documentation and elsewhere. Yet - still no explanation as to download, install, initiate/initialise or otherwise activate Composer.

I am having the same troubles - the documentation is appalling and tends to go around in circles with all sorts of sudden unexpected twists and turns along the way as I explore the labyrinth.

I am working on a d7 site that was installed on GoDaddy shared hosting using their wonderful Installatron system. It does not, however, include Composer, so the basic site installation has been created pre composer installation. I have installed a CLI access using PuTTY after having set-up the ssh with public and private keys on a shared hosting service.

I followed the instructions and copied the set-up code with baited breath and trepidation, not knowing if the system would blow-up or not.

It seemed to work so I installed the Composer Manager module, autoload and a security module manually via the modules section, only to be told that I must run composer install first. However, I cannot do that because there is no aggregate composer.json file in the root directory of my drupal installation where I installed the composer.phar to get a global set-up. After enabling the modules, It (D7) then tells me that I have to create or install this composer.json file first, (Note: composerize module is in dev only for drupal 8).

I have a drupal 8 sandbox site that has its own version of the composer.json file, but obviously it contains a lot of stuff that is only relevant to that site with various references that I am not sure if they relate to drupal 8 or Composer which the module documentation sais " this is Drush extension that works across all versions of Drush, it doesn't need a different release for each different Drupal version. Hence this just being an 8.x project".  I also cannot use the D8 Composer because it apparently has to be initiated/initialised first, somehow, for which I also cannot find any information, let alone intelligible instructions. 

Could someone please explain to me in plain English how to install composer correctly and fully, without having to go around the Mulberry bush another 50 times.

At the very least, I need to know:

1.In D8 site: how to initiate/initialise composer so that I can use it.

2. In D7 site: how to create a composer.json file to sit alongside the phar file, so that I can run the composer install command. Is it enough to simply use notepad to create a file? - with the minimal contents of...?

{
    "require": {
       
    }
}

, and then rename it composer.json?

I look forward to hearing from someone :)

Kr, and Happy Valantine's (Friends) Day!

/ Chris

VM’s picture

note: I've not composer'd any D7 site.

my read of the docs @ https://www.drupal.org/docs/develop/using-composer/using-composer-to-man... has a section titled Managing existing sites using Composer which should aid. However, note that the docs was written for D8 though should apply also to D7. I arrived at the conclusion that you are correct in your assumption that you need to write your own composer.json file. Yes, you can do so in a text editor.

Pahkis’s picture

VM hi,

Thanks for the quick reply and the link.

The composer.json generator seems useful in that I generated a composer.json file with it, but, when I tried to run the composer install command afterwards, the system 'killed' it.

Perhaps something wrong with the specifications I gave, such as the drupal version number. The generated file looks something like this: 

  • { "name": "mindsets/drupal-composer",
  • "description": "MindSeTs Learning On-Line System D7 Sandbox",
  • "type": "project",
  • "require": { "php": ">=5.2.5", "ext-gd": "*", "ext-xml": "*", "ext-json": "*", "ext-openssl": "*", "ext-curl": "*", "ext-pdo": "*", "ext-pdo_mysql": "*", "cweagans/composer-patches": "^1.6.0", "hussainweb/drupal-composer-helper": "^1.0-beta3", "drupal-composer/preserve-paths": "^0.1", "drupal/drupal": "~7.0", "drupal/composer_autoloader": "^1.0", "drush/drush": "~8.0" },
  • "authors": [ { "name": "Chris Spencer", "email": "spensort@gmail.com" } ],
  • "repositories": [ { "type": "composer", "url": "https://packages.drupal.org/7" } ],
  • "minimum-stability": "dev",
  • "extra": { "drupal-composer-helper": { "web-prefix": "web", "set-d7-paths": true }, "enable-patching": true, "installer-paths": { "web/": [ "type:drupal-core" ] }, "preserve-paths": [ "web/sites/all/libraries", "web/sites/all/modules/custom", "web/sites/all/modules/features", "web/sites/all/themes/custom", "web/sites/all/translations", "web/sites/default" ] },
  • "prefer-stable": true,
  • "conflict": { "drupal/core": "8.*" },
  • "config": { "sort-packages": true, "optimize-autoloader": true }

I have bold typed all the data that looks dubious and in need of change.

I would guess that:

  1. the drupal version number needs to be updated to: 7.56
  2. the php require version needs to change to: 5.6
  3. The conflict line "drupal/core" presumably needs to be changed to "7"
  4. The path "web/" needs to be changed to public_html/mindsets/pedles"
  5. The paths "web/sites/all/translations" and "web/sites/all/modules/features"  do not exist and the "custom" directories are for homemade modules/features that are stored within the contrib mudules directory.

Note: This drupal site resides in a sub-domain called mindsets.eu that sits within the main domain of liikanjitsu.club - both of which sit within the public_html sub-directory of the main home/liikanjitsu directory. The D8 site lol-liikan is in the liikanjitsu.club domain directly under public_html.

The composer generator placed its .composer directory and programs in the home directory at home/liikanjitsu, which is above/outside both the drupal installations and even the public_html top directory. It is not clear to me how this affects the usage of composer for D7 and if it also makes it available automatically for the D8 site. When I installed this autoloader/generator, I was in the local D7 directory at public_html/mindsets.eu/pedles.

I also had a look at the composer.json file, that comes as part of the core installation inmy D8 site, with a view to copying it over to D7 and then adapting it. In D8 it uses the vendor directory instead of sites/all/modules, which to my understanding is correct. Other details such as version data are am very unclear about and also the existance of .json, .lock and .phar files in the D8 'root' directory and under the 'core' directory.. The file contents are:

{ "name": "drupal/drupal",

"description": "Drupal is an open source content management platform powering millions of websites and applications.", "type": "project", "license": "GPL-2.0+", "require": { "composer/installers": "^1.0.24", "wikimedia/composer-merge-plugin": "~1.4", "drupal/console": "~1.0" }, "replace": { "drupal/core": "~8.3" }, "minimum-stability": "dev", "prefer-stable": true, "config": { "preferred-install": "dist", "autoloader-suffix": "Drupal8" }, "extra": { "_readme": [ "By default Drupal loads the autoloader from ./vendor/autoload.php.", "To change the autoloader you can edit ./autoload.php.", "This file specifies the packages.drupal.org repository.", "You can read more about this composer repository at:", "https://www.drupal.org/node/2718229" ], "merge-plugin": { "include": [ "core/composer.json" ], "recurse": false, "replace": false, "merge-extra": false }, "installer-paths": { "core": ["type:drupal-core"], "modules/contrib/{$name}": ["type:drupal-module"], "profiles/contrib/{$name}": ["type:drupal-profile"], "themes/contrib/{$name}": ["type:drupal-theme"], "drush/contrib/{$name}": ["type:drupal-drush"], "modules/custom/{$name}": ["type:drupal-custom-module"], "themes/custom/{$name}": ["type:drupal-custom-theme"] } }, "autoload": { "psr-4": { "Drupal\\Core\\Composer\\": "core/lib/Drupal/Core/Composer" } }, "scripts": { "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump", "post-autoload-dump": [ "Drupal\\Core\\Composer\\Composer::ensureHtaccess" ], "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup", "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup" }, "repositories": [ { "type": "composer", "url": "https://packages.drupal.org/8" } ]

It seems to me that adapting the D8 preinstalled version of the root .json file could be even more arduous and perilous :(

If you or anyone else can confirm or correct my assumptions and presumptions, that would I am sure, be of great help.

Kr,

Chris

Pahkis’s picture

Hi again,

Just tried out the php composer.phar init command and seemed to get a result.

I also tried self-update on the D8 composer, whch seemed to work.

Then I tried to 'require'a couple of contrib modules, but, despite appearing to run through all processes correctly, after the last one relating to require of 'dev', they both ended  with the same result... "killed".

I also tried it in the D7 site and in every case got the result, package not found - check spelling etc..

The command I used was, for example:

php composer.phar require drupal/lexicon

I am completely at a loss as to what the problem now is!

Kr,

Chris

Pahkis’s picture

Hi again, 

No responses since VM's kind help, so after much reading and mucking about (testing), here is a run-down / summary instruction list for installing and using composer, as I understand it so far, that I hope will make life easier for other layman site builders such as myself:

Downloading the Composer Executable#

Composer offers a convenient installer that you can execute directly from the command line. Feel free to download this file or review it on GitHub if you wish to know more about the inner workings of the installer. The source is plain PHP.

There are in short, two ways to install Composer. Locally as part of your project, or globally as a system-wide executable.

Locally#

Installing Composer locally is a matter of just running the installer in your project directory. See the Download page for instructions.

Command-Line Installation code

To quickly install Composer in the current directory, run the following script in your terminal. To automate the installation, use the guide on installing Composer programmatically.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

This installer script will simply check some php.ini settings, warn you if they are set incorrectly, and then download the latest composer.phar in the current directory.  The .composer file directory is installed in your hosting service root/home directory (not necessarily the drupal site root directory if you have sub-sites and sub-domains).  The 4 lines above will, in order:

  • Download the installer to the current directory
  • Verify the installer SHA-384 which you can also cross-check here
  • Run the installer
  • Remove the installer

Now just run php composer.phar in order to run Composer.


NOte: You can install Composer to a specific directory by using the --install-dir option and additionally (re)name it as well using the --filename option. When running the installer when following the Download page instructions add the following parameters:

php composer-setup.php --install-dir=bin --filename=composer

Now just run php bin/composer in order to run Composer.

Globally#

You can place the Composer PHAR anywhere you wish. If you put it in a directory that is part of your PATH, you can access it globally. On unixy systems you can even make it executable and invoke it without directly using the php interpreter.

The global command allows you to run other commands like install, remove, require or update as if you were running them from the COMPOSER_HOME directory.

Type: php composer.phar global require drupal/module_name

After running the installer following the Download page instructions you can run this to move composer.phar to a directory that is in your path:

mv composer.phar /usr/local/bin/composer

Note: If the above fails due to permissions, you may need to run it again with sudo.

Note: On some versions of OSX the /usr directory does not exist by default. If you receive the error "/usr/local/bin/composer: No such file or directory" then you must create the directory manually before proceeding: mkdir -p /usr/local/bin.

Note: For information on changing your PATH, please read the Wikipedia article and/or use Google.

Now just run composer in order to run Composer instead of php composer.phar.

Running the composer installer

---composer.json contents & configuration example---

  • mindsets/drupal-composer
  • MindSeTs Learning On-Line System D7 Sandbox
  • Chris Spencer <spensort@gmail.com>
  • dev
  • web
  • drupal/drupal
  • ~7.56
  • no
  • no
  • yes

To initiate & update composer (D8):

Once the composer.json has been created

  1. Run [php composer.phar init] to initiate/create/generate a basic composer.json (essential for D7 sites, and D8 sites installed with hosting service programs such as GoDaddy's Installatron).
  • Run [composer install] if want to install drupal project
  • Run [php composer.phar help {command}] for help info
  1. Run [php composer.phar update] to update the composer.lock & In order to get the latest versions of the dependencies
  2. To update Composer itself to the latest version: [php composer.phar self-update]

Using Composer to manage Drupal site dependencies

Define the directories to which Drupal projects should be downloaded

If you initially created your Drupal website without Composer (for example by manually downloading and extracting a tarball / zip file), you will need to modify your composer.json by adding drupal.org as Composer repository and by defining the directory where modules should be downloaded.

D8 Composerize

In Drupal 8, You can use the Composerize Drupal plugin for Composer to automatically generate an updated composer.json for you. It will add contributed modules, themes, and profiles that it discovers in your existing site.

The Composerize module can "generate a composer.json from your installed Drupal code base, which can be used to regenerate that code base by running composer install."

D7 Composer Repositories and Depositories Specification

You can skip this section if you downloaded Drupal 8 core using 'drupal-composer/drupal-project' (Option A above) or 'hussainweb/drupal-composer-init' (Option C above).

By default, Composer will download all packages to the 'vendor' directory. Clearly, this doesn't jibe with Drupal modules, themes, profiles, and libraries. To ensure that packages are downloaded to the correct path, Drupal uses the composer/installers package and ships with configuration for the directories for your Drupal site. The 'drupal/drupal' template does not ship with drupal-libary configuration so you need to add it to your composer.json:

"extra": {
    "installer-paths": {
        "core": ["type:drupal-core"],
        "libraries/{$name}": ["type:drupal-library"],
        "modules/contrib/{$name}": ["type:drupal-module"],
        "profiles/contrib/{$name}": ["type:drupal-profile"],
        "themes/contrib/{$name}": ["type:drupal-theme"],
        "drush/{$name}": ["type:drupal-drush"],
        "modules/custom/{$name}": ["type:drupal-custom-module"],
        "themes/custom/{$name}": ["type:drupal-custom-theme"]
    }
}

Note

Custom modules and themes paths requires composer/installers package v1.0.24 and up.

Define the directories for arbitrary packages that do not have a "drupal-*" type

If you would like to place an arbitrary Composer package in a custom directory, you may use the Composer Installers Extender.

to place them in the same directory as other Drupal libraries, you would first composer require oomphinc/composer-installers-extender, then add the following configuration to your composer.json file:

"extra": {
    "installer-types": ["library"],
    "installer-paths": {
        "libraries/{$name}": [
            "type:drupal-library",
            "enyo/dropzone"
        ],
    }
}

Finally, you would composer require web/module

To download contributed Drupal modules or themes with composer:

  • Run [composer require drupal/<modulename> ]
  • For example: composer require drupal/token or, php composer.phar require drupal/token
  • This needs to be executed at the root of your Drupal install.

Composer will then automatically update your composer.json

If you just want to update a few packages and not all, you can list them as such:

  • php composer.phar update vendor/package vendor/package2

You can also use wildcards to update a bunch of packages at once:

  • php composer.phar update vendor/*

For updating a Drupal 8 core, contributed modules and themes using Composer, please refer to Update procedure in Drupal 8.

Patching projects using Composer

You can automatically apply patches to composer-built dependencies using cweagans/composer-patches. See the project's README.md file for specific instruction

Composer Commands

https://getcomposer.org/doc/03-cli.md#update

Kr,

Chris (Pahkis)

An Englishman in Helsinki, Balded but unbowed!

Learning, Education and Training Professional

*  Self-defence, kyusho,

Iltispuolustus iltapäiväkerhoja ja dynaamiset liikunnanopitukset

*  Security & risk management.

*  Education, teaching, training & eLearning.

*  Business organisation, processes, project leadership/management, concept & functionality development.

 Further Information

LinkedIn (chrissuli), Finnsec ry, eOppimiskeskus, Research Gate (Chris_Spencer2), Academia.edu (ChrisSpensort), Facebook (Chris at Spensort), Wordpress (Pahkis Blog)

VM’s picture

Wonderful write up. I suggest that you add it as a documentation page.

mdrummond’s picture

A few more things you can take a look at that might help:

- Documentation for the Drupal 7 version of the AMP module is available in the module's README file. Here's a direct link: http://cgit.drupalcode.org/amp/tree/README.md?h=7.x-1.x

- You might find some helpful tips in how to get started with this article, "How to try out AMP with Drupal": https://www.lullabot.com/articles/how-to-try-out-amp-with-drupal

- You can also view a recording of a session from DrupalCon New Orleans on "AMPing up Drupal": https://events.drupal.org/neworleans2016/sessions/amping-drupal

Hope those resources are helpful to you in getting things working.

Best regards,

Marc