Installing Drupal 7 with Composer
There are many roads that lead to Rome, and there are as many ways to install Drupal.
You can use the command line and Drush, download it separately, use an installation profile and now use Composer to install. The main benifit is that you can incorporate any number of command line tools.
In this example I'll combine installation through an installation profile with Composer.
What is Composer?
"Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you."
http://getcomposer.org/doc/00-intro.md
What is a dependency manager?
Using a dependency manager, you can download third party libraries in your project. The Symphony framework uses this extensively with e.g. Doctrine, Twig, Swiftmailer, etc. The dependency manager checks compatible versions and downloads the right ones. It'll also check if there are other components (dependencies) that need to be downloaded when installing a component or module.
Composer isn't really used as a dependency manager in this example, but more as a useful tool to simplify installation.
Installing Composer
The easiest way to download Composer is using curl:
curl -sS https://getcomposer.org/installer | php
If you don't have curl installed, you could also use:
php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
After executing the curl command the terminal displays:
#!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: /Users/MacBookPro/Sites/www.patrickkannekens.nl/composer.phar Use it: php composer.phar
And that's it. Composer is now installed.
Composer JSON
The next step is to create a composer.json file. This contains all the command that we want to execute.
The JSON I use is as follows:
{ "name":"Installation profile", "description":"Install", "scripts": { "pre-install-cmd":[ "drush make --no-cache /var/www/html/installation-profile/installation-profile.make -y", "mkdir sites/default/files", "cp sites/default/default.settings.php sites/default/settings.php", "chmod 777 sites/default/files", "chmod 777 sites/default/settings.php", "drush site-install installation-profile --db-url=mysql://[db-username]:[db-password]@[servername]/[databasename] --account-name=[admin-account] --account-pass=[admin-account-password] --site-name='[site-name]' -y", "rm sites/default/default.settings.php", "chmod 444 sites/default/settings.php" ] } }
In the JSON file you can define commands that need to be executed prior to or after the installation of Drupal.
Step by step
drush make --no-cache /var/www/html/installation-profile/installation-profile.make -y
Execute the installation profile. With this the latest version of Drupal and predefined modules will be downloaded.
mkdir sites/default/files
Create a folder for the files.
cp sites/default/default.settings.php sites/default/settings.php
Copy the default.settings.php to settings.php
chmod 777 sites/default/files
chmod 777 sites/default/settings.php
Change the file permissions so they'll be writeable during installation.
drush site-install installation-profile --db-url=mysql://[db-username]:[db-password]@[servername]/[databasename] --account-name=[admin-account] --account-pass=[admin-account-password] --site-name='[site-name]' -y
Installing the site with drush..
chmod 444 sites/default/settings.php
After completing the installation, the settings file is set read only.
Uitvoeren
Executing is easy as pie; run "composer install" (or "php composer.phar install") and let it run.