Composer is now widely used for dependency management in PHP projects - and many projects now require the use of composer. In this post we will cover how to use composer to get Drupal 8 and it's dependencies for a specific platform's PHP version.
In this example, I will use Drupal 8, but this process can be modified to work with other CMSs. I will also use git, but those commands can be ignored if you don't use git for version control. These instructions use the command line in linux, and you may have to adapt them to match the environment on your computer. This post also assumes you have PHP and composer installed on your computer already.
Prerequisites:
- php5.6 or php7.0
- composer
Creating a new project
The first step is to create a new folder and initialize a new composer project in it. While using the hussainweb/drupal-composer-init tool is presentecd here, there are other ways of starting drupal projects.
composer global require hussainweb/drupal-composer-init mkdir mysite && cd mysite composer drupal-initadmin # Answer the questions, examples shown here: # Package name: koumbit/mysite # Author: Name <email> # Minimum stability: dev # License: GPLv2.0+ # Public web directory: websituation # Drupal core or distribution: drupal/core # Version for drupal/core: ^8.4 # Define dependencies: no # Define dev dependencies: no # Confirm generation: yes git init . && echo 'vendor/' >> .gitignore && git add . && git commit -m "Initial commit" # Only if you're using git VCS
Modifying composer.json to match HAG's environment
The web nodes for HAG are currently running PHP 5.6. We want to specify this in our composer.json so that composer can properly resolve all the dependencies and doesn't pick libraries which don't support 5.6. We're working on bringing PHP 7.0 nodes online for you to use - we'll post on koumbit.org when they are available.
To indicate to composer that our platform uses php 5.6, we need to enter this information in the config['platform']
. It will look something like:
"config": { "platform": { "php": "5.6" } }
Once this is in place, make sure the dependencies are re-installed:
composer update --with-dependencies git add . ; git commit -m "Changed PHP requirement to match HAG environment"
Making changes & uploading
You can use composer to download drupal modules and their dependencies now - eg. composer require drupal/search_api
. When using the drupal-init template, the modules are placed in web/modules/contrib/
. You can put your own custom modules in web/modules/custom/
or in a module directory for a specific site (if using multi-site).
Since HAG can only receive files via FTP or browser upload, I pack the files I need to deploy into a compressed tarball before upload. Drupal 8 and it's dependencies are around 200Mb in nearly 20, 000 files - this will take forever to upload via FTP (even with parallel connections).
tar czf site.tar.gz web/ vendor/
Note: It is important to use .tar.gz
instead of a .tgz
so that the compressed file can be expanded through the AlternC web interface at https://bureau.koumbit.net.
Upload site.tar.gz into your site folder and unpack through the web interface.
About Koumbit
Koumbit is a horizontally self-managed non-profit which offers self-managed hosting, mutualised drupal hosting (with automatic security updates, web consultation services, and more. Have any questions? Drop us a line.
If you're in an organisation promoting social justice and need web space, we have a soldarity hosting program which may let you access our services.