Loading Laravel into plain PHP Script without using Artisan command


Laravel is a web application framework which made the web application development quite easier and enjoyable. It incorporates certain flexible features in your application. On March 2015, Laravel is witnessed as one of the most popular PHP frameworks, along with CodeIgniter, symphony, and other frameworks. There is no doubt it is going to improve lot more in the future and make the development much easier.

As everyone knows, Artisan is the command-line interface included with Laravel. It provides a number of helpful commands that can assist you while you build your application. This helps us lot to create custom PHP command and run in the command line or scheduler like cron job. Artisan makes it easy to work with all the Laravel components and services from within a PHP script outside the HTTP routing.

I recently ended up looking for a way to hook into the Laravel framework, the same way as what Artisan is doing but without a registered command. That was because of a requirement I had where I wanted to put a dynamically generated command which will give certain output fetched from Laravel application. This was done by an external script knowing the path where Laravel application is installed. Thanks to the flexibility of the Laravel framework. I am sharing the work I have done so that it helps others.


Go into your Laravel installation directory. Create a file called in any name what you like to name your command. Get the following code.


This script was tested in Laravel 5.2. Please comment if anyone tested in any other versions and working. Or else notify me in the comment if it needs any modification.


If you find it helpful, please share with others.

Leave a Reply

Your email address will not be published. Required fields are marked *


Please wrap all source codes with [code][/code] tags.

This site uses Akismet to reduce spam. Learn how your comment data is processed.