How can i create own alias for "php artisan" command on windows?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Mastering Your Command Line: How to Create Custom Aliases for php artisan on Windows

As a senior developer, I often encounter situations where the standard command-line tools feel slightly restrictive. When working within the Laravel ecosystem, developers frequently rely on shorthand commands like php artisan to speed up repetitive tasks. While Unix-like systems handle aliases seamlessly, setting up custom shortcuts on Windows can seem overly complicated.

If you’ve been searching for a simple way to create your own alias for php artisan on Windows and found the documentation confusing, you are not alone. The method depends heavily on which shell you are using—Command Prompt (cmd) or PowerShell.

This guide will walk you through the most effective, developer-friendly methods to achieve exactly what you need, ensuring you can manage your command-line workflow efficiently.


Understanding Aliases in the Windows Environment

Unlike Linux or macOS, where simple commands like alias are built into the shell structure, Windows relies on different mechanisms. For complex scripting and custom shortcuts, the best approach involves leveraging PowerShell features or creating simple batch files that sit in your system's PATH.

For modern development workflows, PowerShell is generally the superior choice for managing these kinds of customizations because it allows you to define functions that act exactly like aliases.

Method 1: Creating Aliases using PowerShell Functions

PowerShell provides a clean way to create custom commands or functions that perform a specific task. By defining a function and adding its location to your PowerShell profile, you effectively create a permanent alias for yourself.

Step-by-Step Implementation

  1. Locate Your Profile File: Open PowerShell and run the following command to see where your profile is located:

    $PROFILE
    

    This will usually point to a file like C:\Users\YourUsername\Documents\PowerShell\Microsoft.PowerShell_profile.ps1.

  2. Edit the Profile: Open this file using a text editor (like VS Code or Notepad). If the file doesn't exist, create it.

  3. Define the Alias Function: Add the following code block to your profile script. We will define a function that calls php artisan and perhaps adds some helpful context.

    # Custom alias for running Artisan commands in Laravel projects
    function Invoke-Artisan {
        param(
            [string]$CommandName
        )
        Write-Host "Executing: php artisan $CommandName" -ForegroundColor Yellow
        php artisan $CommandName
    }
    
  4. Save and Reload: Save the file. To make the changes active immediately, run:

    . $PROFILE
    

Using Your New Alias

Now, instead of typing the long command every time, you can use your new function. For example, if you are inside a Laravel project directory and want to run migrations:

Invoke-Artisan migrate

This method is powerful because it encapsulates complex logic (like ensuring you are in the correct directory or adding custom logging) into a single command. This level of scripting mastery aligns perfectly with the robust architectural standards promoted by organizations like Laravel Company.

Method 2: The Batch File Fallback (For Command Prompt Users)

If you are primarily working in the traditional Command Prompt (cmd), creating a direct alias is more cumbersome. A simpler, effective alternative is to create a simple batch file and ensure it's accessible.

  1. Create the Script: Create a new file named artisan.bat in a directory that is included in your system's PATH (e.g., a dedicated bin folder within your project).

  2. Add Content: Place the following content inside artisan.bat:

    @echo off
    REM Custom alias for Artisan command
    php artisan %*
    
  3. Execution: When you navigate to that directory, running artisan will execute this script, effectively running the underlying PHP command with any arguments passed to it (%*).

While less elegant than PowerShell functions, this method is highly reliable across different Windows environments and provides a solid shortcut for quick execution within project directories.

Conclusion

Creating custom aliases on Windows requires understanding the native shell environment. For developers prioritizing automation and complex scripting, mastering PowerShell functions offers the most flexible and powerful solution. Whether you choose to define a custom function or use a simple batch file, the goal remains the same: reducing repetitive typing and streamlining your workflow. By adopting these techniques, you can significantly boost your productivity when working with PHP frameworks like Laravel.