enadabuzaid's avatar

Forge CLI Authenticates Successfully, But “Your API Token is Invalid” on Any Command

Hi all,

I’m having an issue with the Forge CLI. When I run forge login --api-token=XXXX, I see:

==> Authenticated Successfully As [[email protected]]

But when I try any command, like:

forge server:current

I get this error:

Your API Token is invalid.
  • I’ve generated a fresh API token from my Forge dashboard and used it for login.

  • I’ve tried logging out (forge logout) and logging in again.

  • The same happens if I use forge servers:list or any other command.

  • My token has all the default permissions and is active on my Forge profile.

  • I also see a lot of PHP deprecation warnings (using PHP 8.2), but I don’t think they are related.

Has anyone seen this? Any ideas why the CLI authenticates successfully but fails on actual commands?

Thanks in advance!

0 likes
8 replies
LaryAI's avatar
Level 58

This is a common issue with the Forge CLI, especially when running under PHP 8.2+ or when the CLI is installed via a package manager like Herd or Homebrew. Here are some steps and checks to resolve the problem:


1. Check PHP Version Compatibility

The Forge CLI phar is not always compatible with the latest PHP versions. The deprecation warnings suggest you're running PHP 8.2, which may cause issues. Try running the CLI with PHP 8.1 or 8.0:

php8.1 /path/to/forge server:current

Or, if you have multiple PHP versions installed, use php -v to check and switch to an earlier version.


2. Remove and Reinstall Forge CLI

If you installed Forge CLI via Herd or Homebrew, there might be a mismatch. Try removing and reinstalling the CLI using the official method:

# Remove the current forge binary
rm /usr/local/bin/forge # or wherever it's installed

# Download the latest phar directly
curl -s https://forge.laravel.com/cli/installer | php

# Move it to a directory in your PATH
mv forge /usr/local/bin/forge
chmod +x /usr/local/bin/forge

3. Clear Old Configurations

Sometimes, old or corrupted config files cause issues. Remove the Forge CLI config directory:

rm -rf ~/.forge

Then, log in again:

forge login --api-token=YOUR_TOKEN

4. Double-Check the API Token

  • Make sure you copy the token exactly as shown in Forge.
  • Ensure the token is active and has not been revoked.
  • Try generating a new token and using it.

5. Check for Multiple PHP Installations

If you have multiple PHP installations, the CLI might be using a different PHP version than you expect. Run:

which php
php -v

And ensure it's the version you intend.


6. Suppress Deprecation Warnings (Optional)

While not the root cause, you can suppress deprecation warnings to see if the CLI works:

php -d error_reporting=E_ALL^E_DEPRECATED forge server:current

Summary Checklist

  • Use PHP 8.1 or lower for the Forge CLI.
  • Download the latest Forge CLI phar from the official source.
  • Remove ~/.forge and re-login.
  • Double-check your API token.
  • Ensure no conflicting PHP installations.

If the problem persists after all these steps, it may be a bug with the CLI and PHP 8.2 compatibility. In that case, use PHP 8.1 for the CLI, and consider opening an issue on the Forge CLI GitHub repository with your details.

Let me know if you need more help!

enadabuzaid's avatar

Note: I have been using Forge CLI for 2 years without any issues. This problem only started happening today. I didn’t change anything in my setup, so I’m not sure what caused it.

Snapey's avatar

Did you ask forge, or check for any ongoing issues?

enadabuzaid's avatar
enadabuzaid
OP
Best Answer
Level 31

I solved it by checking the Herd Configuration with Froge because that was the issue that had happened.

Please or to participate in this conversation.