Overview
Forge provides a command-line tool that you may use to manage your Forge servers, sites, and resources from the command-line.Installation
Requires PHP 8.0+You may install the Forge CLI as a global Composer dependency:
Get Started
To view a list of all available Forge CLI commands and view the current version of your installation, you may run theforge
command from the command-line:
Authenticating
You will need to generate an API token to interact with the Forge CLI. Tokens are used to authenticate your account without providing personal details. API tokens can be created from Forge’s API dashboard. After you have generated an API token, you should authenticate with your Forge account using the login command:FORGE_API_TOKEN
environment variable in your CI build environment.
Current Server & Switching Servers
When managing Forge servers, sites, and resources via the CLI, you will need to be aware of your currently active server. You may view your current server using theserver:current
command. Typically, most of the commands you execute using the Forge CLI will be executed against the active server.
server:switch
command:
server:list
command:
SSH Key Authentication
Before performing any tasks using the Forge CLI, you should ensure that you have added an SSH key for theforge
user to your servers so that you can securely connect to them. You may have already done this via the Forge UI. You may test that SSH is configured correctly by running the ssh:test
command:
ssh:configure
command. The ssh:configure
command accepts a --key
option which instructs the CLI which public key to add to the server. In addition, you may provide a --name
option to specify the name that should be assigned to the key:
ssh
command to create a secure connection to your server:
Sites
To view the list of all available sites, you may use thesite:list
command:
Initiating Deployments
One of the primary features of Laravel Forge is deployments. Deployments may be initiated via the Forge CLI using thedeploy
command:
Updating Environment Variables
You may update a site’s environment variables using theenv:pull
and env:push
commands. The env:pull
command may be used to pull down an environment file for a given site:
env:push
command to push the variables back to your site:
Viewing Application Logs
You may also view a site’s logs directly from the command-line. To do so, use thesite:logs
command:
Reviewing Deployment Output / Logs
When a deployment fails, you may review the output / logs via the Forge UI’s deployment history screen. You may also review the output at any time on the command-line using thedeploy:logs
command. If the deploy:logs
command is called with no additional arguments, the logs for the latest deployment will be displayed. Or, you may pass the deployment ID to the deploy:logs
command to display the logs for a particular deployment:
Running Commands
Sometimes you may wish to run an arbitrary shell command against a site. Thecommand
command will prompt you for the command you would like to run. The command will be run relative to the site’s root directory.
Tinker
As you may know, all Laravel applications include “Tinker” by default. To enter a Tinker environment on a remote server using the Forge CLI, run thetinker
command:
Resources
Forge provisions servers with a variety of resources and additional software, such as Nginx, MySQL, etc. You may use the Forge CLI to perform common actions on those resources.Checking Resource Status
To check the current status of a resource, you may use the{resource}:status
command:
Viewing Resources Logs
You may also view logs directly from the command-line. To do so, use the{resource}:logs
command:
Restarting Resources
Resources may be restarted using the{resource}:restart
command:
Connecting To Resources Locally
You may use the{resource}:shell
command to quickly access a command line shell that lets you interact with a given resource: