PHP Artisan is the command line interface included with Laravel. It is a script called artisan in the root folder of every Laravel project, and developers run it in a terminal as php artisan followed by a command, for example php artisan migrate to update the database structure. Artisan handles the routine jobs of building and running a Laravel application, so they are done the same way every time.
The name explains the syntax: php is the program that runs the script, and artisan is the script itself.
What developers use Artisan for
The Artisan documentation shows how to list every available command with php artisan list, and how to see what any one of them does with php artisan help followed by its name. A few that appear on almost every project:
php artisan make:model Booking --migration
php artisan migrate
php artisan migrate:rollback
php artisan down
php artisan up
In order, these:
- create a new Eloquent model and a matching migration file for its table;
- apply any database changes that have not been run yet;
- undo the last batch of database changes;
- put the site into maintenance mode during an update;
- bring it back online.
There are also commands for clearing caches, creating controllers and email classes, running automated tests and processing queued jobs in the background. Laravel’s interactive console, Tinker, is opened with php artisan tinker and lets a developer work with the application’s data directly, which is useful for checking a problem on a copy of the site.
Database changes that can be repeated and reversed
Laravel’s migrations are described in its documentation as version control for your database. Each change to the structure, such as a new table for loyalty points or a new column for a delivery note, is written as a file and applied with php artisan migrate.
For a business, this means the change made on the developer’s laptop is applied in exactly the same way on the test copy and then on the live site. Nobody adds a column by hand on the production database and forgets to do it elsewhere. If a release goes wrong, migrate:rollback reverses the last batch.
Some commands deserve care. migrate:fresh drops every table and rebuilds the database from scratch, which is useful on a developer’s machine and destructive on a live site. Laravel asks for confirmation before running destructive migration commands in production, and a sensible routine adds a fresh backup before any migration on the live database.
Scheduled tasks with one server setting
Many business systems need jobs to run on their own: reminders the day before an appointment, a nightly stock import, a weekly report to the manager. Laravel’s task scheduler lets developers define all of them inside the application, and the server needs only one cron entry that runs php artisan schedule:run every minute.
Schedule::command('reminders:send')->dailyAt('18:00');
The schedule is part of the code, so it is versioned, reviewed and moved with the application. When the site moves to new hosting, that single cron entry is the only scheduling setting to recreate.
Custom commands for your own processes
Developers can add their own Artisan commands with php artisan make:command. A new command class is created in the app/Console/Commands folder, and it can do any job the business needs: import prices from a supplier’s file, send a batch of reminders, or tidy up abandoned baskets. Once written, the same command can be run by hand, by the scheduler or by a deployment script.
Where Artisan fits with Laravel and Composer
Composer installs Laravel and its packages, and Artisan runs tasks inside the installed application. Most deployment routines for a Laravel site use both: Composer installs the exact package versions, and Artisan applies migrations, clears and rebuilds caches and restarts queue workers.
On our Laravel development projects, you own the code, content and accounts, and we provide documentation.
FAQ
Do I need to use Artisan as a site owner?
No. Artisan is a developer’s tool, run on the server or a development machine. Site owners work in the admin area. It helps to know it exists, because many maintenance jobs on a Laravel site are Artisan commands, and a developer quoting for maintenance should be able to explain which ones run and when.
Is Artisan the same as Laravel?
No. Artisan is one part of Laravel, its command line interface. Laravel also includes the Blade templating engine, the Eloquent ORM, routing, queues and much more. Artisan is the tool developers use to create and manage those parts from the terminal.
What is php artisan serve?
It starts a simple web server on the developer’s computer, so the site can be opened in a browser at a local address while it is being built. It is meant for development only. Live sites run on a proper web server.
Can Artisan commands run in the background?
Yes. Commands can be queued so that a queue worker processes them in the background, and the scheduler can run them at set times. This is how long jobs, such as importing a large product file, are kept away from the pages visitors use.