 So we've got a couple more minutes, but Patrick just had the brilliant idea to ease my nerves and that is to tell jokes So for the next two minutes, I'm gonna tell a couple jokes Raise your hand if you've heard this. What do you call a cow with two legs? Or you can just call it out if you know the answer No lean meat These are all my cow jokes so forgive me, but what do you call a cow with no legs? Ground beef, there you go. What do you call a cow just after she's given birth? Decaffeinated Well, we still have a couple minutes, but I'm gonna go ahead and get started the doors are closed My name is Brian Lewis. I'm from Wichita, Kansas. Hence the cow jokes. That's what I'm famous for I Am a front-end developer front of engineers the official title at four kitchens been there for about a month and a half Before that I was doing modules unraveled So if you've listened to the modules unraveled podcast you might recognize my voice if not no worries This session originally the first time I gave this took about three hours Because somebody kept asking questions and it's totally cool But you know three hours doesn't fit in a session here the second time I gave it ended up being two hours so let's get a little closer and so for this I've cut out like all of the General site building stuff because I talked about a lot of advanced site building things And today it's it's pretty much solely going to focus on configuration management and composer Composer is actually going to go first but Everything is pre-recorded because using composer on any even the best Wi-Fi is slow and on conference Wi-Fi Doesn't exist So if you want to follow along well, you're not gonna be able to because everything's video and edited and you're Not going to but later if you want to do this You're gonna need composer get drush and I use Drupal console for some things as well The two big ones are composer and get those are actually required to do anything Drush and console are installed as a part of this process But it's a good idea to have them both installed globally on your system so that you can use them without having to like Use like vendor slash bin slash drush or whatever just type drush Cool, so let's just get started It is officially 215 installing Drupal with composer. There is a come. There's a composer template on GitHub it's a github.com slash Drupal dash composer slash Drupal dash project. That's what I'm basing this entire series on and so On that site if you scroll down a little bit, there's a usage section where it says composer create project That's what I'm gonna use Just to start this whole thing off Also, this session is not going to teach you the ins and outs of composer or configuration management It's basically a giant demo. Here's how I built a site from scratch beginning to end with composer and configuration management pushing things from local to live Yeah, so if you wanted to learn the ins and outs, you're gonna have to do that later This is gonna show you the awesome power of both of them and then you can explore later So here's I've got a terminal open. I'm just gonna hit play. It's using that composer create project command That you saw a second ago And I'm pretty sure I hit play Let's try again. That didn't do anything. Was it playing over there? Oh, sorry. It doesn't play on my computer So this is really inconvenient because I can't see what it's doing But it's it's running everything and composer will never ever run this fast on your machine ever ever I'm pretty sure that was like What No, unfortunately, I can't I wish I could Yeah, so after you run that command You basically have a composer or you have a Drupal eight site installed and here's the directory structure So we've got I told it to install into a DC and a comm directory and if you look in there There's actually a web directory underneath that. That's where Drupal itself is installed So that's where your the core is your modules your themes the sites directory all that's in there one level below the actual project root and we'll talk more about Why that is in a minute? I'm gonna blow through some of this because this is gonna take too long but I've added the site to the host file and created the virtual host directory create the database And now I'm going to use Drupal console to actually install the site I'm being pretty verbose with my install script And you can this I'll be recorded so you can see this later I'm gonna try and blow it through it though because I got a lot to show you So with that whoa got really flounder without running You can see I had to fill out a couple more questions, but then after mere seconds in video edited time We have Drupal installed and we can actually log into it using Drush Uli with the Uri in there and when you do that it takes you straight to the site where you can log in and change your password or You know, whatever you want to do. So like literally those two commands installed Drupal Installed the project and then an install Drupal and log me in so That's pretty awesome, right? Composer sweet So at this point if you're gonna follow along you definitely want to export your database now For configuration management purposes later I'm gonna show you what happens if you don't import a database But if you do then you can just start exporting and importing config between Sites right away. So it's always a good idea to go ahead and export that database now I should have hit play a minute ago, but it's just doing it pretty easy peasy stuff and Now we're gonna prepare the settings at php and settings dot local dot php files I'm gonna skip over probably a lot of this, but If you don't already clean up your settings dot php file I highly recommend it because this I think it's originally like 730 lines when I'm done deleting all the comments and Unused stuff it comes out to 40 lines. That's actually being used So that makes it way easier to read and actually 10 of those lines are gonna go to another file in a minute anyway definitely helpful something I always do and to Raise your hand if you've used a settings dot local dot php file like with Drupal 7 Awesome. I'm gonna skip a lot of this then. I won't always any time In the settings dot php file if you haven't used it before there's a little snippet there that says If a settings dot local dot php file exists use it and The only thing you really need to know is make sure that is a very last thing in the file Because if you have database credentials for example in that settings dot local dot php file and then other ones further down in this file They'll be overwritten with this one in your local settings won't do anything. So make sure it's lasting Yeah, that's Let's try it. Is that any better? It shouldn't be playing yet Is it better though? Okay, cool. Hopefully that'll work It will all be recorded and I'll be releasing all this stuff later too. So you can watch it Let's see So this is Uncommenting the if settings dot local dot php file exists. Okay, we did that If you have any other questions throughout this session, feel free to raise your hand. I'll answer them But I'll also try and give you some time at the end to do the same thing. I wish I could see the screen So I had to change the permissions on the default directory So that I could actually create the settings dot local dot php file because they were set to 555 Change it back to seven or change it to 777 Create the settings up HP file and then change the default directory back to 555 and and then you're good So let's go ahead and move on Next we're gonna initialize a git repo Add the settings dot local dot php to a git ignore file If you don't use a global git ignore file you should look into that But for the purposes of this I'm just gonna add it to the projects dot git ignore file And it's just gonna make sure that the settings of local dot php file is never committed in this project Raise your hand if you use global git ignore files Cool, you guys are awesome You're doing this, right? Really wish I could see the screen I don't know when it's done. All right, so we've added all those files and we're committing them All right, and then I'm going to go ahead and push it up to a remote repo So that we can pull it to our live one. Have you guys raise your hand if you've used configuration management so far in your blade Handful cool, and raise your hand if you've used composer Why are you guys here? I mean you already know everything You're just here to see me mess up on stage. I understand All right So let's let's go on to using come composer to manage dependencies We are going to use it to Install packages from packages dot Drupal dash composer org. You probably can't read that either I can't see even know if you can This is where you want to go to look for packages. Basically. This is a clone of packages that Mirrors Drupal dot org so anything that's on triple dot org any modules themes in like that You can install using composer by thanks to this packages site So all you do is search for what you want in this case. I'm going to search for path auto God really wish I could see that and then you'll select it and right there You'll see the composer require command that you need to install it You'll also need to do a specify a version because down the right hand corner You can see like there's triple seven versions triple eight versions dev versions all kinds of stuff But we'll talk about that in just a second I'm going to skip these manual installation ones you can add these Things straight to the composer.json file, but since you guys are already using composer and configuration configuration management I'm going to assume that you know how to use the command line So let's Well, there is you should know that you shouldn't do this basically When you add it directly to the composer.json file if you run like composer update to install it It's also going to update all of the other packages in that list So you might be trying to just install path auto, but you might inadvertently update five other modules that you didn't mean to and so That's not a great idea So I'm gonna skip a couple of these so we can get ahead to the Command line stuff, which is the right way to do it All right the other command line And it's even it's easier to use right composer require quote vendor slash package colon version and quote enter and You've got it And it takes care of adding it to the composer.json file and everything for you So yeah, I mean that's how you install a module Pretty awesome, and you might also notice that I used The dev version when I in the command, but it installed version alpha 3 That might confuse some people at first and that has to do with the prefer stable option Which I'll explain in just a minute Now uninstalling via the command line is just as simple. You just do composer remove vendor slash package no quotes No version number no nothing you just type it in it'll remove it. We'll take it out of the composer.json file You're all set super simple And you'll also notice that every time I do this it's installing dependencies So like I installed path auto it also installed C tools and token and then when I removed it Also remove those two because they weren't being used by anything else in that in that package file Composer is awesome So if you want to upgrade and downgrade projects It's pretty easy. Okay, so here's here's when I mentioned that I Specified the at dev version, but it installed alpha 3 instead if you really really want the dev version You just install it like as if it were a Like a git project Yes That is a great question It didn't used to but I believe it does now Greg, do you know the answer to that? If you when you compose or install a module does it run like the install hooks and everything Okay, it only pulls down the code files. So you'll need to install it yourself as well Is that the same thing for removing if you remove it? Perfect. Thank you for the clarification. So when you remove one makes you disable it or uninstall it in this case Before you composer remove. Otherwise, you're gonna be leaving stuff in the database and that's not good Great question. Thank you Do where's my mouse there it is This is awful. I can't see the screen. Okay, so we're still enforcing the division. So I mentioned that you would Install it as if it were a git branch So you can use like dev dash 8 dot x dash 1 dot x and that'll give you the actual dev version Regardless of whether you have Required it. What was it now? I'm losing my Prefer stable. Thank you for first able set to true So I'll actually get it for you Cool. So now you can see that we have version 8 dot x dash 1 dot x c 4 9 5 2 e 1 installed So it's an actual like hash commit of that module And now when we run Composer Update in the future, it'll always be the dev version and not a stable release So if you want to downgrade a module, this is kind of the only reason I ever specify a specific version And that's like if there was a breaking change Then I'll want to revert back Otherwise they use the like the star at dev because it'll always do the latest release But if it's a breaking change all you do is add The or specify the version you could do it through the composer.json file like this is doing or you can Do it through the command line by just saying Composer require and specify a version so now you can see that it installed version 1 or 8 113 and Updating is the same same thing if you have a specific version installed You can use the command line or the composer.json file and just specify the version you want Any questions so far about composer or anything that I've done really wrong that you guys who really know composer know Okay, I guess I'm doing well so far Cool, so I mentioned that I only specify versions when I am Need to downgrade Usually I follow this technique of automatically keeping everything Update with the latest stable. I set my prefer stable to true and in that instance star at dev for the version Will install the dev version until there's an official release and then stick to official releases from that point forward If you set prefer stable to false, then it's just going to use the dev version no matter what for better or worse It'll also affect all of your packages and projects cool So for that I would I'm gonna go ahead install the admin toolbar module here using the star at dev You can see that happen And you'll actually notice when I do that it says there's nothing to install and that's because we've already installed 14 Which is the latest release But it did update the composer.json file there with the new version pattern so that in the future it will update It won't be stuck to that version and if you want to only install stable releases ignoring that initial dev you can just do like 8.1.star but It does the same thing if it's a stable release using that dev will let you have that initial dev release as well So if you already know there's at least one stable release either way it doesn't matter You can use that dev or not. It really won't make a difference As long as you have prefer stable set to true clarify that So this is I Can't tell what it's doing So it's really unfortunate. I Think it's just showing what I what I just explained using the the star without the dev Yeah cool So the really fun stuff is that you can install packages from a git repository This you may or may not have done before raise your hand if you've ever used a composer to install a git package Far fewer awesome now. I feel like I can I can show you guys something I'm gonna take a look at the redirect module. This is at github.com slash md-system slash redirect when I Wrote this session. There was no redirect for eight on triple org So you had to get it from git now there is one and so you don't have to do this, but if you want to for example If you have a set of modules or a theme that you use within your company on multiple sites But you know, you don't necessarily want to release them to triple org This is a good way that you can use composer to require that module or theme in a bunch of sites But you know just use it internally so In the composer.json file here, I'll open that up real quick and you can see that there's some metadata telling you about like the title and the description But there's also The type value and the type is set to Drupal dash module in the composer project That we used in the very first step to install Drupalm if you look in there There's a setting at the bottom that says Anything that is of type Drupal dash module put in the module slash country of directory anything that's of type Drupal dash theme put it in the theme slash country of directory So you can actually create your own types and then install them into specific places into your folder structure However, you want this one is using triple Drupal dash module So it's going to go in with the other contrib modules even though it's coming from from github instead of from triple org So you can use that And there's also that require section down at the bottom That's super handy in case your module needs like a library like the full calendar module needs a full kind of library It could require that library here so that when you require the module in your project It will also get the library and put it where you've told it to you automatically without having to download each separately So let's go ahead and install it First thing you have to do is add the git repository to your repositories section in your composer.json file and The repository is going to be the github URL basically So you can see after the packages Entry at a comma and at a new one There we go Again, I wish I could see it But the type is git and then the URL is their github URL and this just tells composer look in a git repository And here's the URL of that repository that you should look in for these packages So now we can just require the module using the git branch as the version So in the command line to be like composer require Drupal dash redirect colon dev dash a dot x dash one dot x and When it's done, you'll see the hash of the specific version of it was That was installed and all of these are also being written to your lock file composer.lock file raise your hand if you don't know What a composer.lock file is Okay, just a few I'll go ahead and explain it the composer.lock file is created every time you run like composer update Or install things like this and that lock file meet Contains the specific Versions of the modules that you're installing that means that when you push this to another Instance of your site and run composer install It'll read it from the lock file and get that version not an update a potentially updated version of that of that module Hope that's clear So if you're wondering how to decide which version pattern you should use when you're requiring packages I created this little table. Those first two are the ones that I use most often either The dev until stable or always dev Every once in a while. I'll use the exact version if I need to downgrade but Those are some of the it's just a little table I put together See somebody taking a picture of it cool Again, these will all be in the slides Okay, so actually I'm gonna skip the overriding settings and code with settings dot PHP because We're not gonna have time for it So we'll go on to installing the site on a production server with composer So you're gonna clone the repo Run the install with no dev And then copy the database credentials and install a site So I'll just hit play I've done this on like a one-click install type site So I'll have to do a couple things but basically I'm an SSH into it Go into the public HTML directory and move the existing site to a backup directory so I can get to the database credentials later and This particular host expects the Drupal root to be in the public HTML slash DC and APR What's going on? Oh, I'm already cloning it. Oh, well, so I'll clone it here and then Because it's because I don't have full control over this server I'm just gonna create a symbolic link basically from source web to the directory of things. It's gonna be on and that'll let me work From this packages file All right, so then we just run composer Install no dev raise your hand if you don't know what no dev does Okay, no dev is going to ignore everything in the require dash dev section of your composer.json file so you can put things like Develop in there so that that's never installed on your production server you can put What's the stage file proxy or reroute email all of those things that you don't want on your production server and like be hat or PHP unit things that you use locally, but don't need to be on the server put those in the Require dash dev section and then when you're when you run composer install Dash dash no dash dev that'll ignore that and just include the stuff from the require section So that's installed Got it. I'll go ahead and copy the database credentials from my original site to the one we just created I'm hoping some of this is useful to everybody. I Really love your feedback on this after the the sessions that I know if something needs to change drastically So I'm just creating the settings.local file with the database credentials cool, so then Let's see. I'm gonna skip this part. I basically just drop the database and create a new one and I have to watch it because they also install the site and this is again is all because I use the one-click install so once it's all set up you can go to your site and It's running on the production server now. I'm gonna install Drupal. Raise your hand if you've ever installed Drupal this fast I think I fast forwarded that a thousand times literally Cool, so we've got a site installed on production using the one that we pushed from local any claps. No, okay, cool However, if you are familiar with configuration management, you probably are thinking yourself He just messed up because he had stalled it and didn't import the database. That's true But I'm gonna show you how to fix that if you ever make that mistake as well Okay, let's go talk about configuration management. Gosh, I'm running out of time So whoops, I just get something Okay, so Drupal stores configuration files in the directory that you specified in your settings dot PHP by default Drupal will create a science default files config underscore some random hash slash sync directory and I'm gonna move that up one directory so that it's outside of my web root So that's into the just the project route that way it's still within version control, but not web accessible plus for security and with the Composer project that we used to create the site. That's super easy So I'll just change that real quick from whatever that random one was to dot dot slash config slash sync and Now I'm ready to move ahead. You definitely want to delete the old config directory that was installed With by Drupal because you can have some issues if you've got two different config directories that it thinks it should be looking in So that's that and at this point we have a fresh installation on production and partially build site locally you can do configuration either through the UI or the Terminal raise your hand if you want to see it through the UI Awesome, I like you guys. Oh, some people said well, I'm sorry if you want to see it through the UI you'll have to come later because it's There were only like two or three of you I'm gonna skip through these slides for the running on time It's interesting stuff, but it's way better through to the command line So the entire Did I just skip something? Yeah, okay, so here's with Drush sue super super fast. You basically just type Drush config dash export and it's done and I'm pulling up the site. You can see the config directory was created all the configuration files are in there There's even a .htaccess file automatically created that tightens up security a little little better cool, so now we need to go ahead and Push that with git so we're going to Commit that I think I first Commit the settings .php file because I was never done and then I'm adding the config Directory really wish I could see that screen Can somebody tell me what it's doing? Oh, right. I'm removing the the the site on the Is this the live site now? It's the development Yeah, the old config files remove those okay, so now we should be left with just the Just the config so we're going to add that and commit it locally and Push it up and then we'll be ready to pull it into production Okay I'm going to skip the UI because we're not going to show that right now Think of this is still UI So I did run into an issue because I tried to pull the config and I didn't notice that hadn't unlinked the Settings .php file when I tried to pull the new one in if you come across that just change the default Folders permissions to something like 777 pull it in and then change them back to 555 I've only had that issue with the settings .php file not the like config Directors or anything so okay This is on the live site if I do a good status. You'll see that it did pull the config directory except If I try and do get pulled it'll say is a oh here we go. This is this is changing the permissions right? Yes, good Like I said, you won't need to do this for the to sync config. It's just in the default directory so it should be done and Now that we have pulled in changes I like to run composer install no dev Just because it's a good practice to have the latest modules at all times, but I don't think it actually does anything here And I change into the Directory and try to import but it says your UID is different and we expected that because I didn't import the database so if you come across this then you'll need to set the variable Drush 7 had V V get and V set your blade has a drush 8 has see get and see set for Setting configuration and because we're not using variables. So if we switch to the web directory we can run drush See get is it going? There we go Drush see get system dot site you you ID it'll print it out there for you and Then you can just basically copy that and go over to the other side or the production site it doesn't matter which one you use and run drush See set system site you ID quote Paste it in and quote and then you're ready to start syncing configuration. So if you forget that error that says The UIDs are different Just grab it from one and paste it in the other In the last note, I don't know if anybody knows why this happens. Please come up and tell me but I've had an issue when I try to import it says that the The shortcuts have an issue and so I basically have to come in here and delete the default shortcuts and then it works Has anybody had that issue? Yes Like I did a Google search for it and there were like two mentions of it But it's happened to me every time since so I don't know what the deal is But they delete them then you're good. So okay back in the terminal. We're just gonna run drush config import why? and boom import successfully So now we can go to the home page on production and you'll see that the site name has changed From my awesome site to Drupal con New Orleans site building and that's that's it. Did Does anybody have any questions? I was gonna run through a whole like Two minute like change things here and then push them up. But if you've got questions, I'd love to answer those first Leaving the config file and then adding config sync Moving out of the site's default files directory. Okay. Yeah, so when it's in the files directory, it's Technically web accessible although they've got that random hash in there So it's very difficult and I just like to put them up into the project route Outside of my web route just for a little more security and easier for me to get to if I need to to check something Does that make sense? Cool any other questions? About either one composer or config management Yeah Yeah, that's that whole section that I skipped in the middle about having a local settings file. You can set module Settings basically in that file that will never be pushed or affect other instances of the site And we can talk more Yep. Yep. I put them in there and they're never saved the configuration or anything. Yeah There was another question I thought No, oh Yeah, I don't Possibly I possibly should the question was do I have any issues of security since I'm installing things from packages instead of straight from dribble.org I Don't actually know if there should be cause for alarm, but I think it's it's pretty well used and maintained and I Haven't heard anybody talk about it. So Yes Okay, so the question I think that is a great philosophical question that I have no answer to The question in case anybody is curious someone to talk about it was What are my thoughts on? Relying on a third party like composer to install things where if somebody changes the package on packages or whatever and All of a sudden it doesn't work if I'm relying on them to get that then I can't get it because it doesn't work There's actually a buff that's going to be happening after this all about composer I would say go to that buff and ask there because they'll probably be able to answer better than I can Turn that on. Yeah, I keep talking So you essentially have two different Rebos one is like the rendered side and we built it to a whole the the art So it kind of gives you the best You can Go to the four kitchens booth and check out aquifer you can tell you all about it All right, so we're about out of time, but I'm gonna run through like a typical workflow We've spent all this time getting things set up now. Let's change some things locally commit it using configuration management to get push it up and import it and Have an exact copy. This is all the stuff. We're gonna do you can read that if you'd like, but basically we're install modules install themes Set a default theme enable modules change a temp path create a view move some blocks around Save a Google analytics configuration, but then override it with a local file And then we're gonna do the actual exporting and pushing everything up. So here we go install the module We're going to first change into the project route and then Do a composer install path auto? Now we're gonna install the Zimpen ease theme for Drupal 8 which is the only Drupal 8 theme that I found that looked halfway decent on Drupal over right now And then we're going to go back to the web directory and enable the all all the modules So admin toolbar admin toolbar extra tools path auto and redirect And that's done. So now we're going to go ahead and In the user interface set the Zimpen ease theme as the default theme and change the temp path from The funky MAMP one to just slash TMP And I did create a couple of articles before I did this so when we create a view it's actually going to show something So we're going to structure your views Just add a simple view that lists articles This is the good stuff guys Real simple to save that and then we're going to go to the Google analytics Settings. Oh, no, I'm gonna add these blocks first And that articles block that is created to the left sidebar and then just for fun at the who's new block because who doesn't like to know Who's new on a site and then we're going to go Save a Google analytics account in the configuration so that it is actually saved to Configuration and will be pushed to live when we do it and you can see some things already taking place I hope that's not your Google analytics account 9999999-99 Cool, and then this is the settings up local file that I skipped because we didn't have time But basically I'm just setting that to an empty string so that locally nothing ever Reports and then we're exporting the local configuration Super easy and then we're gonna commit it to get and and push it up to the repo. I'm just showing that the composer.json and lock files are updated because we've installed the additional modules. Cool, it's all added. Push it up and then you switch over to our production site, get pull run composer install no dev to get the new modules and their dependencies if there are any. And then we're gonna import the configuration and rebuild the cache. Can you imagine trying to do this live? So with that imported and rebuilt, we can view the site. So everything theoretically should look exactly like it does on local as it does on the production, minus the things that are overridden. Just look on the modules page, you can see when I go to it, there we go. The admin toolbar and all of those fun things are enabled as well as redirect, path auto. And then, yeah, so that's all checked. You can see that the temp directory is no longer trying to go to a MAMP directory, it's going to just slash temp. And then back on the homepage, you can see that the blocks are there on the left, the view is created, got a nice drop down menu, things to admin toolbar. And everything is exactly like it was on local as it is on production. And that just took two minutes if you can edit your life like I edited the videos. Oh, and now I'm showing that the Google Analytics account is showing up there on live, but on the development site, there's no Google Analytics because I overwrote it, but we didn't talk about that. So, cool. Any other questions about anything? Yes, sir? I have not, I've not even heard of them. The dot, dot dev or dot MV? It's dot EMV. Dot EMV? I haven't heard of it. Gotcha. No, I haven't heard of it or reused it. I'll just check it out. I don't know, possibly. I'm not actually running that buff so you can run in and say, is this good? And they'll tell you. Cool. Awesome. Any other questions before we go? Run into a case, run into what? Oh, patch. Yes, that's all taken care of. If you look at the composer project on GitHub, there's a section there that says how to patch them. You basically just link to the patch and it takes care of installing that patch during the build. Yep, that's great. Yes, I'm pretty sure it will. I hope not. Okay, any other questions? Oh, was it? It's too bad.