Adding Deployment Hooks0:35
and then we get rid of the old ones. Alright, so we can actually customize any of these steps before or after we can do anything we want, any script on any server. So perhaps we want to run php artisan optimize after we install our composer dependencies. Alright, so let me take a look at that. I can manage this step of the deployment, and you can see I can add a hook before or after this action. In this case, we want to add an Optimize step after we install our composer dependencies, so let's select that option. Alright, and we'll name this step Optimize, and we want to run this as the forge user,
Creating Optimize Hook1:04
so let's select that option. Alright, and we'll name this step Optimize, and we want to run this as the forge user, and then within this script text box, we can actually do something special. We can say I want to change into this release placeholder, and that will be replaced with the most current release directory when this script is run. Of course, you have no idea to know the timestamp of the release beforehand, so this lets you get into the current release folder in sort of a really easy, intuitive way. Alright, and then we want to run php artisan optimize, and we'll add the --force flag right there. And here we can select which servers we want to run this on, because if you have multiple servers, you might not want to run a hook on every server.
Deploying to Test Hook2:08
I'm going to manually click Deploy here, and we can see a new deploy coming out here, and if we look at this overview, now you can see that there's a new step, Optimize, which shows the results of our hook operation. So once it installs the Composer dependencies, it should run our php artisan optimize command. Alright, and that's done, and now it's optimizing, and then we should be able to get the output of our custom hook, just like we would any other step in the deployment. And this is going to build a compiled file that's going to increase the performance of our application. And if we take a look, we can see that it did indeed generate an optimized class loader and compiled our common classes.
Adding Route Cache Hook2:43
And if we take a look, we can see that it did indeed generate an optimized class loader and compiled our common classes. Alright, so let's add another hook. Maybe in addition to compiling this file, we want to cache our routes. So let's go back to the deployment hook screen. We can manage this and then add an additional hook, compile routes. We also want to run this as forge, change into the release directory, and then run the php artisan route:cache command.
Reordering Hooks and Deploying3:10
change into the release directory, and then run the route:cache command. Alright, and let's save that hook, and then when you're on this screen, you can actually drag to order these hooks in any order you want, and it will automatically save. There's no save button to click, so you can just drag them and organize them how you want, and then you're done. We're going to put our route:compile after our optimize, and let's go back to our project and deploy. Alright, and we can see this fresh deployment coming out,
