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
~/.forgeand 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!