gstreamer0.10-ffmpeg
gstreamer0.10-plugins-good
packages.
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.
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.
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.
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!
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:
... 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:
{ | |
"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!
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!
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!
Hey Terrence,
Thanks for the tip! Though this version may differ from the one we're showing in this screencast. We do recommend our users download the course code and follow the tutorial from the start/ directory. But your way is totally valid too, just keep in mind some differences that may occur in the newer version.
Cheers!
Hi!
I know this is quite old but I still have a question.
As far as I can tell this tutorial is about creating modules and using drupal like a framework (such as symfony), but how about creating modules to use inside drupal? Will this tutorial dive into that? Or maybe you can point out some other good symfonycasts friends that will discuss that?
Hope you can help, thanks
Hi Matias C.!
Sorry for my very slow reply! Yes, this tutorial is getting pretty old - the concepts haven't changed to much, but it's showing its age a bit ;).
> but how about creating modules to use inside drupal? Will this tutorial dive into that? Or maybe you can point out some other good symfonycasts friends that will discuss that?
When it comes to the true, Drupaly stuff - like actually learning Drupal - that's not something we cover - it's not our area of expertise. I recommend, in case you haven't already, checking out https://drupalize.me/
Sorry I can't give you a SymfonyCasts recommendation - but good luck!
Cheers!
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.)
Hey Griff P.!
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!
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
Hey Griff P.!
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!
Cheers weaverryan. I am working through the course and leaving notes on the different chapters. For this chapter, I couldn't get the Drupal install working with the supplied composer.json
, I think it is just too out of date with the current packages. So I did the full Drupal install as recommended in the Drupal docs: composer -n create-project -s dev drupal/recommended-project start
. (Installing Drupal in the 'start' directory). This now installs Drupal 9, rather than Drupal 8, which meant I had to upgrade my version of MySQL (it requires 5.7 minimum). I got that working using MacPorts. Setting up the Git repo is also different from the video, as the Drupal directory layout has changed since 8.0.
Hey Griff P.!
Nice work!
> For this chapter, I couldn't get the Drupal install working with the supplied composer.json, I think it is just too out of date with the current packages
Yes, sadly, that's not too surprising :/
> Setting up the Git repo is also different from the video, as the Drupal directory layout has changed since 8.0.
This is one of the things I'm most excited to update, as this had a lot of evolution from 8.0 -> through the other 8's to 9.
Keep up the good work! You may find other differences, but I promise that the *fundamentals* that we're showing - dependency injection, services, etc - are timeless :).
Cheers!
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 :-(
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!
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.
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."
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!
Hey sasa1007
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!
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
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...
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!
// composer.json
{
"require": {
"composer/installers": "^1.0.21", // v1.0.21
"wikimedia/composer-merge-plugin": "^1.3.0" // dev-master
}
}
For anyone following this tutorial and have issues trying to install Drupal 8, I installed the latest Drupal 9 version and followed along.