What steps should one take to make a Laravel app ready for production mode

Bayram EKER
2 min readAug 1, 2022

--

Step 1:

Apply changes to .env file

  • APP_ENV=production
  • APP_DEBUG=false

Step 2:

Make sure that you are optimizing Composer’s class autoloader map

  • composer dump-autoload --optimize
  • or along install: composer install --optimize-autoloader --no-dev
  • or during update: composer update --optimize-autoloader

Step 3:

Optimizing

Note: You should not enable any of these optimizations in development as they all will cause various problems when adding/removing classes. The performance gains are not worth the trouble in a development setting.

  • php artisan config:cache
  • php artisan route:cache
  • php artisan view:cache
  • php artisan optimize

Step 4 :

(Optional) Compiling assets

When you run the dev or production scripts, all of your application's CSS and JavaScript assets will be compiled and placed in your application's public directory:

  • npm run prod

Step 5 :

(Optional) Generate the encryption keys Laravel Passport needs

When deploying Passport to your application’s servers for the first time, you will likely need to run the passport:keys command. This command generates the encryption keys Passport needs in order to generate access tokens. The generated keys are not typically kept in source control:

  • php artisan passport:keys

Step 6:

(Optional) Start Laravel task scheduler by adding the following Cron entry

So, when using Laravel’s scheduler, we only need to add a single cron configuration entry to our server that runs the schedule:run command every minute. If you do not know how to add cron entries to your server, consider using a service such as Laravel Forge which can manage the cron entries for you:

  • cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Step 7:

(Optional) Install, config and start the Supervisor

  • sudo apt-get install supervisor

Step 8:

(Optional) Create a symbolic link from public/storage to storage/app/public

To make these files accessible from the web, you should create a symbolic link from public/storage to storage/app/public. Utilizing this folder convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.

To create the symbolic link, you may use the storage:link Artisan command:

  • php artisan storage:link

--

--

Responses (1)