Back to Blog
Lesson 52 of the Laravel Fundamentals: From Zero to Your First App course
LaravelJune 26, 20263 min read

Task Manager: Deployment Preparation

Learn how to perform a final production audit for your Task Manager. We cover clearing secrets, verifying dependencies, and running final tests before launch.

LaravelDeploymentSecurityTestingTask Managerphpbackend

Previously in this course, we explored managing assets in production using Vite. Now, it's time to perform a final, comprehensive audit of your Task Manager before you push your code to a live server.

Deployment is more than just uploading files; it's about ensuring your environment is hardened, your dependencies are clean, and your application logic is bulletproof.

The Pre-Deployment Audit

Before you ship, you need to verify three critical pillars: security (no secrets in code), integrity (clean dependencies), and functionality (passing tests).

1. Eliminating Hardcoded Secrets

As we discussed in our environment security best practices, sensitive data belongs in the .env file, never in your source code.

Search your entire project for strings that look like API keys, database passwords, or "secret" tokens. A common mistake is hardcoding a Stripe key or a mail provider password directly into a config/ file or a controller.

The Audit Step: Run this command in your terminal to search for potential leaks:

Bash
grep -rn "API_KEY" .

If you find anything, move that value to your .env file immediately and reference it in your code using env('YOUR_KEY') or, preferably, via a config file using config('services.key').

2. Verifying Dependencies

Your composer.lock file ensures that the exact versions of packages used in development are used in production. However, over time, you might have installed packages you no longer use.

Run composer install --no-dev --optimize-autoloader locally to simulate the production environment.

  • --no-dev: Excludes packages like fakerphp/faker or barryvdh/laravel-debugbar which are not needed for your production Task Manager.
  • --optimize-autoloader: Converts your PSR-0/4 autoloading into a class map, which significantly boosts performance.

3. Running Final Tests

Never deploy without a clean test suite. We’ve been building testing habits throughout this course—now is the time to execute them all at once.

Bash
php artisan test

If any test fails, do not proceed. Deployment should only happen when your suite is green. This confirms that your core features—like creating, updating, and deleting tasks—are still working as intended after your recent refactors.

Hands-on Exercise: The Final Checklist

Perform these actions on your project right now:

  1. Clean up: Delete any dd() or dump() calls you might have left in your controllers.
  2. Audit: Open your config/ directory. Ensure no values are hardcoded as strings like 'password' => 'secret123'.
  3. Verify: Run php artisan config:cache and php artisan route:cache. If these commands fail, it usually means you are using env() calls directly in your route or controller files instead of within config/ files.
  4. Test: Run php artisan test one last time.

Common Pitfalls

  • Caching in Development: Do not run php artisan config:cache in your local development environment unless you are actively testing production-like settings. It will prevent changes to your .env file from taking effect.
  • Missing Extensions: Ensure your production server has the same PHP extensions your local machine has (e.g., bcmath, ctype, fileinfo, json, mbstring, openssl, pdo, tokenizer, xml).
  • Ignoring the .env file: Never commit your .env file to version control. Ensure it is listed in your .gitignore file.

Recap

You've built your Task Manager from a simple route to a functional CRUD application. By auditing your secrets, optimizing your dependencies with composer, and ensuring a passing test suite, you’ve moved from "it works on my machine" to "it's ready for the world."

Production deployment is the final milestone in this journey. With these checks complete, you can be confident that your application is secure and performant.

Up next: We will walk through the actual steps of pushing your code to a production server and setting up your environment for the first time.

Similar Posts