Deploying Laravel/Lumen Projects

This is very short blog on what should be the steps when deploying any laravel/lumen project on your server.

Its very easy to get started with laravel/lumen as we have very strong commans avaialble to use i.e artisan which also helps us to start a loal web server for testing, but things become very complicated when you are tryng to deploy application on server for the very first time.

So in this blog I will list down the steps that I follow as well as try to exlpain my reasons behind it.

  1. Check you PHP version(In case of multiple PHP version installed, check which one is configured for your application in NGINX/Apache). This is very important steps and it should be within the range that your laravel version supports it.
  2. Copy you application source code inside the websites root directory. for eg, in Apache its generally /var/www/your-website-name.
  3. Rename .env-sample to .env and updates it’s configuration accordingly
  4. Install Composer if its not installed already
  5. Run composer install to resolved any dependencies.
  6. Run your migration command to created your database schema and seed any values if needed.
  7. Run chown command to updated owner of all files within you application(eg. for apache its www-data)
  8. Run chgrp command to update the group(eg. for apache its www-data)
  9. Create a link for storage folder in your application’s public folder
ln -s /path/to/laravel/storage/app/public /path/to/public/storage

Note: Make sure to delete any logs file that you have in storage folder, otherwise it will create some issues in productions when you are woprking on windows system and deploying application on linux based OS( eg. CentOS, Debian etc)

  1. After that open you web server configuration file and point you web server to your applications public directory. Make sure to restart your web server after making any changes to it for it to take effect.
  2. Add cron job if available any to cron tab
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Thanks for reading…

Leave a Reply