From the course: Accelerating Laravel API Development with AI: From Specification to Testing
Preparing for production - Laravel Tutorial
From the course: Accelerating Laravel API Development with AI: From Specification to Testing
Preparing for production
- [Instructor] When you've completed building your app you need to release to production. There are a few things to configure. I'm going to start in the env file. It's likely you or Copilot will have modified some values in this during the initial build. Note that the env file should not be committed to the repo. Anywhere you run this code you'll need to create a new env file. The first value you'll want to config in your production is app env. Send it to production on production. Here mine is local. Also commonly used are staging and development for lower environments and testing. You'll need to generate the app key using php artisan key generate. As you can see it updates the value in my env file when I run that. When you change that value, encrypted cookies and sessions will become invalid, locking out users. A note of warning, if you are storing encrypted values in the data base and you would know if you are, those values will no longer be dencryptable. The final value is the APP_ DEBUG Boolean, set it to false so you don't display stack traces to users. APP_URL is also a good value to set. There are four commands that you will also want to run on production. If you do run these, you'll need to run them after every release. The first is php artisan config cache. This combines all config files which in turn speeds up the bootstrapping process for Laravel. The next is php artisan route cache. Similar to the config cache this combines all route files into one. In this project I'm using both API and WebRoutes. In larger projects, you may find you're using dozens of route files to make it easier to find things. In both cases, if you don't rerun them unreleased, you may not see the changes you expect. The first of the last two commands is php artisan view cache. If you're building a rest API with no front end, then php artisan view cache doesn't offer much. In this project I have some documentation in Blade files so there's a small improvement there. Finally, php artisan event cache, if you're using events. I haven't touched on them in this course, but you may find events to be helpful for more complex model relationships. With those commands and env values in mind, you're ready to set up your Laravel app in production.