Installation, Composer and Git!

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Hello Drupal people! I'm Ryan, and I come from the magical world of Symfony, full of gumdrops, rainbows, interfaces, services, dependency injection and lollipops. Along with a few other oompa loompas, I lead the Symfony documentation team, so I may not seem like the most obvious person to be teaching you about Drupal 8. But Drupal 8 has taken a huge leap forward by using common coding patterns and libraries. This makes Drupal a lot easier and more accessible to a lot of people.

This series is meant for developers who have used Drupal before. Instead of learning how to use it, we're going to rip apart the layers and see how this machine runs. That's going to make you more dangerous and uncover possibilities you wouldn't otherwise know about.

Download D8

Start by downloading Drupal 8, which at this moment isn't quite released, but it will very soon! This unzips the file to my Downloads directory. I'll move it to a drupal8 directory. We can see all of our shiny new files here in my shiny PhpStorm editor.

The Built-in PHP Web Server

Move into the drupal8 directory. We need a webserver! But I'm not going waste time setting up Apache or Nginx locally. Instead, I'll use the built-in PHP web server. Start it by running php -S localhost:8000:

php -S localhost:8000

This serves files from this directory and will hang there until you stop it. I highly recommend using this to develop.

In the browser, navigate to http://localhost:8000. Hello Drupal 8 install screen! Pick the standard installation to get a few more features.

Fixing php.ini problems

On the next step, I have a problem: the xdebug.max_nesting_level setting in php.ini is set too low. Wah wah.

Bah, it's easy to fix. Go back to the terminal and open a new tab. Run php --ini:

php --ini

This will tell you where the php.ini file lives. Open it with your favorite editor. I like vim, because it gives me street cred.

Tip

In some setups (I'm looking at you OSX), there will be no value for "Loaded Configuration File". Usually, there is a file in the "Configuration File (php.ini) Path" directory, but it's named something like php.ini.development. Rename this file to php.ini and run php --ini again.

Search for the setting! It already exists in my file, so I'll set it to 256. If it doesn't exist in your file, just add at the bottom:

xdebug.max_nesting_level = 256

For this change to take effect, restart your web server. For us, hit control+c to kill the PHP web server and then start it again:

php -S localhost:8000

That fixes it! Type in your database details: I'll call my database d8_under_hood and pass root with no password for my super secure local computer.

Now go grab some coffee or a sandwich while Drupal does it's installation thing.

Ding! Give your site a clever name and an email address. Um, but enter your email, not mine. The super-secret and secure password I'm using is admin. Select your country and hit save.

Phew! I mean congrats! You now have a working Drupal 8 site!

Storing in Git and talking Composer

You know what I love most about a new project? Creating a new git repo. Seriously, how often do you get to type git init?

git init

In PhpStorm, you can see an example.gitignore file. Refactor-Rename that to .gitignore. Open it and uncomment out the vendor line to ignore that directory:

37 lines .gitignore
... lines 1 - 9
# Ignore core and vendor when managing dependencies with Composer.
# core
/vendor/
... lines 13 - 37

The project also has composer.json and composer.lock files:

45 lines composer.json
{
"name": "drupal/drupal",
... lines 3 - 5
"require": {
"composer/installers": "^1.0.21",
... line 8
},
... lines 10 - 32
"autoload": {
"psr-4": {
"Drupal\\Core\\Composer\\": "core/lib/Drupal/Core/Composer"
}
},
... lines 38 - 43
}

Composer is PHP's package manager, and it has changed everything in our world. If you aren't familiar with it, go watch our Composer tutorial! Seriously, you can use it in Drupal 7... we do in that tutorial...

Because of the composer.json file, you should not need to commit the vendor/ directory. You should also not need to commit the core/ directory where all of Drupal lives, due to some special Composer setup in Drupal. Another developer should be able to clone the project, run composer install and both vendor/ and core/ will be downloaded for them.

When I tried to do that, I had a little trouble with the core/ directory due to an autoloading quirk. Hey, it's not released yet, so there could be a bug. It's cool.

In another screencast, I'll show you the proper way to use Composer with Drupal. But for now it's safe to not commit the vendor/ directory at least. If you run composer install, it'll populate that directory correctly.

Zip back over to the terminal and run git add . and then git status:

git add .
git status

There are a lot of files in core/, so it will be nice to not have to commit those someday. But other than these core/ files, we're not committing much. A new Drupal "project" doesn't contain many files.

Finish this by typing git commit and typing in a clever commit message for your fellow contributors to enjoy. Done!

Please, Please use a Decent Editor

I have a secret to tell you that will make your Drupal 8 experience many times better: use a decent editor, the best is PhpStorm. Atom and Sublime are also pretty good. But if you use Notepad++ or open some directory explorer to dig for files manually, there will be no rainbows, Pixy Sticks or Gumball drops in your Drupal 8 experience. Your editor must be able to auto-complete, have a directory tree and have a keyboard shortcut to open files by filename. Ok, I've warned you!

PhpStorm Symfony Plugin = Joy

If you do use PhpStorm... which would make you my best friend... it has a Symfony plugin that plays nicely with Drupal too. Score! In Preferences, under plugins, click browse repositories and search for "Symfony". You'll find this awesome Symfony plugin that has over 1.3 million downloads! If you don't have this installed yet, do it. I already have it. After installing, it'll ask you to restart PhpStorm. Once it's open again, head back to Preferences, search for Symfony, and you'll find a new Symfony plugin menu. Make sure you check the Enable Plugin for this project box. Remember to check this for each new project.

This plugin will give you some pretty sweet autocompletion that's specific to Drupal and Symfony.

Sweet! We're up and running! Let's get into the code!

Leave a comment!

  • 2020-06-30 weaverryan

    Hey MonkeyBrain!

    I'm really happy to hear you've enjoyed some other courses! Hearing that makes our job much more fun :). I'm looking forward to hearing any issues or feedback you have as you go along with this one!

    Cheers!

  • 2020-06-29 MonkeyBrain

    Thanks Ryan. Would be great to have an updated Drupal 8 course in the future, but I need to get up to speed with D8 asap, so I'll go with what is available now. I (maybe wrongly) assumed that the reason you provided the SQL dump was to include some extra custom DB tables needed for your demo, rather than just to provide the standard D8 install tables, which as you say can be provided by following the normal install process. Anyway I'll press on with the D8 course and leave comments if I find issues. I've really enjoyed working through some of the other courses on this site, this is a great learning resource. Many thanks - MB

  • 2020-06-29 weaverryan

    Hey MonkeyBrain!

    Sorry about the problem - you're 100% correct! I'm honestly not sure how that happened. Or better said, how that slipped past! I believe the problem is that the cache_container table contains binary data - so my dump of it choked with it hit that. My apologies!

    What I *should* have done is include *no* SQL dump (that's not a great way to have you install anyways) and have you go through the normal installation process on your own - basically, follow what we do in the video, instead of the README. I'm going to update that right now.

    But I'll also warn you that this tutorial is showing its age. A lot of the concepts we cover are still valid, but this uses Drupal 8.0 and you may even have trouble using it with PHP 7.4 due to some change in PHP 7.4. We're going to be putting up some additional info on each tutorial soon to help you guide this stuff. And, I hope we'll get an updated version of this tutorial soon.

    If you have any questions, please let me know! And sorry again for that bad directions in the README about the dump!

    Cheers!

  • 2020-06-26 MonkeyBrain

    Hi the supplied SQL files seem to be incomplete? I downloaded the course code this morning, and both versions of finished_database.sql seem to stop halfway through an INSERT INTO 'cache_container' statement. So they won't import correctly. (Importing using 'source' command from MySQL command-line.)

  • 2020-03-20 Diego Aguiar

    Are you using MySql or Sqlite? you need to double-check that the service is up an running, and then check that your Drupal installation is using the right connection string

  • 2020-03-19 Sasa Milivojevic

    I try without install lamp but i get same error as oliver

  • 2020-03-18 Diego Aguiar

    Hey Sasa Milivojevic

    In that case you may want to get a LAMP installation (Linux, Apache, MySql and PHP) but as Ryan said, you don't really need Apache nor MySql

    Cheers!

  • 2020-03-17 Sasa Milivojevic

    What about Ubuntu?

  • 2016-03-14 weaverryan

    Hi Oliver!

    It doesn't - it comes with *just* PHP. But, if you installed something like MAMP - which includes PHP, MySQL and Apache - you would/could still just run this command to use the php built-in web server instead of Apache. But in that case, MySQL would be running, and you could communicate with it.

    Or you can use Sqlite - it's one of the options during install (and then use the built-in PHP web server).

    Cheers!

  • 2016-03-14 Oliver Williams

    Does the php built in server come with a mysql database?
    On the Set up database page I get the message :
    "Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2002] No such file or directory."

  • 2016-01-19 weaverryan

    Glad you get it rocking! Thanks for sharing this :)

  • 2016-01-18 ddanielyan

    Thanks a lot for for the link. Using the drupal-compser template definitely creates a cleaner installation.
    I ended up with the following items in my .gitignore file:

    # Ignore core and vendor when managing dependencies with Composer.
    /vendor/
    web/core

    # Ignore configuration files that may contain sensitive information.
    web/sites/*/settings*.php
    web/sites/*/services*.yml

    # Ignore paths that contain user-generated content.
    web/sites/*/files
    web/sites/*/private

    This is still not perfect (why do i need to add all the /web/ files like index.php etc.) but definitely beats adding core to your own repository.

  • 2016-01-04 weaverryan

    Hey there!

    Hmm, I don't recall exactly, but I was using https://github.com/drupal-c..., which certainly seems active. Are you using that? The Drupal Console can also be used to start a new project - but I haven't tried it yet to see if it does it via a Composer install. Have you tried that for a new install?

    Cheers!

  • 2016-01-02 ddanielyan

    at 4:35 you mention, you had issues with not committing the core directory. I ran into the same issue with 8.0 (final). Have you ever been able to solve this issue? What I do not understand that in composer.json core is clearly marked as "replace" but composer still does not install it :-(

  • 2015-12-08 weaverryan

    Hi Vladimir!

    Sorry for my late reply! On my machine, git uses vim for the commit messages. This might be different on your machine: nano is another common editor for git to use (the editor that git uses is configurable).

    For vim, I pressed esc+:+w+q+enter

    Esc exits editing mode, colon enters a command mode, then wq tells vim to "write and quit".

    For nano, you would type, and then hit ctrl+o then ctrl+x iirc.

    I hope that helps!

  • 2015-12-01 weaverryan

    Good catch - but we'll probably leave that one :). Call it an Easter Egg ;)

  • 2015-11-29 Pietrino Atzeni

    I know, easier said than done, but listing the "Editor Must", the graphics shows "1. autocomplete", "2. show a directory tree", and "2. keyboard shortcuts"... too many 2...