-
-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
This comprehensive guide helps you resolve common issues when using Laravel Safeguard. Issues are organized by category with step-by-step solutions.
Problem: composer require
fails with "Package not found"
Symptoms:
Could not find package grazulex/laravel-safeguard
Solutions:
- Update Composer:
composer self-update
- Clear Composer cache:
composer clear-cache
- Check package name:
# Correct package name
composer require --dev grazulex/laravel-safeguard
# NOT grazulex/safeguard or laravel-safeguard
- Check Composer configuration:
composer config --list
Problem: Composer reports dependency conflicts
Symptoms:
Your requirements could not be resolved to an installable set of packages.
Solutions:
- Check conflicts:
composer why-not grazulex/laravel-safeguard
- Update dependencies:
composer update --with-dependencies
-
Check requirements:
- PHP: 8.3 or higher
- Laravel: 12.19 or higher
-
Force resolution (last resort):
composer require --dev grazulex/laravel-safeguard --ignore-platform-reqs
Problem: Commands not available after installation
Symptoms:
php artisan safeguard:check
# Command "safeguard:check" is not defined.
Solutions:
- Clear Laravel caches:
php artisan cache:clear
php artisan config:clear
php artisan route:clear
- Re-discover packages:
php artisan package:discover --ansi
- Check if commands are available:
php artisan list | grep safeguard
- Manual registration (if auto-discovery fails):
// config/app.php
'providers' => [
// ...
Grazulex\\LaravelSafeguard\\LaravelSafeguardServiceProvider::class,
],
Problem: "Configuration file not found" error
Symptoms:
Configuration file config/safeguard.php not found
Solutions:
- Publish configuration:
php artisan vendor:publish --tag=safeguard-config
- Check if file exists:
ls -la config/safeguard.php
- Force republish if needed:
php artisan vendor:publish --tag=safeguard-config --force
- Check file permissions:
chmod 644 config/safeguard.php
Problem: Custom rules not being detected
Symptoms:
php artisan safeguard:list
# Custom rules don't appear in the list
Solutions:
- Check file location:
ls -la app/SafeguardRules/
- Verify namespace:
// In your custom rule file
namespace App\\SafeguardRules;
use Grazulex\\LaravelSafeguard\\Contracts\\SafeguardRule;
- Check configuration:
// config/safeguard.php
'custom_rules_path' => app_path('SafeguardRules'),
'custom_rules_namespace' => 'App\\\\SafeguardRules',
- Verify rule implementation:
class MyCustomRule implements SafeguardRule
{
// Must implement all required methods
public function id(): string { }
public function check(): SafeguardResult { }
public function appliesToEnvironment(string $env): bool { }
public function severity(): string { }
}
- Clear caches:
php artisan config:clear
php artisan cache:clear
Problem: Configuration file has syntax errors
Symptoms:
PHP Parse error: syntax error, unexpected '}' in config/safeguard.php
Solutions:
- Check PHP syntax:
php -l config/safeguard.php
- Validate configuration:
php artisan safeguard:config validate
- Common syntax issues:
// β Missing comma
'rules' => [
'rule1' => true
'rule2' => true, // Missing comma after true
],
// β
Correct syntax
'rules' => [
'rule1' => true,
'rule2' => true,
],
- Republish if corrupted:
php artisan vendor:publish --tag=safeguard-config --force
Problem: Commands work sometimes but not others
Symptoms:
php artisan safeguard:check
# Sometimes works, sometimes doesn't
Solutions:
- Check Laravel environment:
php artisan --version
php artisan env
- Verify package is still installed:
composer show grazulex/laravel-safeguard
- Check for conflicting packages:
composer show | grep safeguard
- Reinstall package:
composer remove --dev grazulex/laravel-safeguard
composer require --dev grazulex/laravel-safeguard
Problem: Command runs but no rules are checked
Symptoms:
php artisan safeguard:check
# π― 0 checks run
Solutions:
- Check enabled rules:
php artisan safeguard:list --enabled
- Verify configuration:
// config/safeguard.php
'rules' => [
'app-key-is-set' => true, // Make sure some rules are enabled
'csrf-enabled' => true,
],
- Check environment-specific rules:
# Try different environment
php artisan safeguard:check --env=production
# Or use all rules instead of environment-specific
php artisan safeguard:check --env=production # Uses all enabled rules
- Debug rule loading:
php artisan safeguard:check --verbose
Problem: Commands fail with memory or timeout errors
Symptoms:
Fatal error: Allowed memory size of X bytes exhausted
Maximum execution time exceeded
Solutions:
- Increase memory limit:
php -d memory_limit=512M artisan safeguard:check
- Configure in safeguard.php:
'performance' => [
'memory_limit' => '1G',
'timeout_seconds' => 600,
'max_scan_files' => 5000,
],
- Reduce scan scope:
'scan_paths' => [
'app/',
'config/',
// Remove large directories like 'vendor/', 'node_modules/'
],
- Enable parallel processing:
'performance' => [
'parallel_processing' => true,
],
- Use caching:
php artisan safeguard:cache rebuild
Problem: Command runs but produces no output
Symptoms:
php artisan safeguard:check
# (no output)
Solutions:
- Check output buffering:
php artisan safeguard:check --verbose
- Try different format:
php artisan safeguard:check --format=json
- Check log files:
tail -f storage/logs/laravel.log
- Test with specific rule:
php artisan safeguard:test-rule app-key-is-set
Problem: Invalid JSON output
Symptoms:
{
\"status\": \"failed\",
// Trailing comma or syntax error
}
Solutions:
- Validate JSON output:
php artisan safeguard:check --format=json | jq .
- Check for encoding issues:
php artisan safeguard:check --format=json | iconv -f utf-8 -t utf-8//IGNORE
- Use alternative format:
php artisan safeguard:check --format=cli
Problem: Output has wrong colors or formatting
Solutions:
- Disable colors for CI:
php artisan safeguard:check --ci
- Force colors:
php artisan safeguard:check --ansi
- Check terminal support:
echo $TERM
# Should support colors
Problem: Custom rule exists but doesn't run
Solutions:
- Check rule is enabled:
// config/safeguard.php
'rules' => [
'my-custom-rule' => true, // Must be enabled
],
- Verify rule ID matches:
// In your custom rule
public function id(): string
{
return 'my-custom-rule'; // Must match config key
}
- Check namespace and autoloading:
composer dump-autoload
- Test rule individually:
php artisan safeguard:test-rule my-custom-rule
Problem: Custom rule throws exceptions
Solutions:
- Check error handling:
public function check(): SafeguardResult
{
try {
// Your logic here
return SafeguardResult::pass('Check passed');
} catch (Exception $e) {
return SafeguardResult::fail('Check failed: ' . $e->getMessage());
}
}
- Validate dependencies:
public function check(): SafeguardResult
{
if (!function_exists('some_required_function')) {
return SafeguardResult::fail('Required function not available');
}
// Continue with check
}
- Debug with verbose output:
php artisan safeguard:test-rule my-custom-rule --verbose
Problem: Security checks fail in GitHub Actions but work locally
Solutions:
- Check PHP version consistency:
# .github/workflows/security.yml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3' # Match your local version
- Ensure .env file exists:
- name: Create .env file
run: |
cp .env.example .env
php artisan key:generate
- Check dependencies:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- Debug with verbose output:
- name: Run security checks
run: php artisan safeguard:check --verbose --fail-on-error
Problem: Security checks fail in GitLab CI
Solutions:
- Check Docker image:
security_check:
image: php:8.3-cli
before_script:
- apt-get update -yqq
- apt-get install -yqq git unzip
- Install Composer:
before_script:
- curl -sS https://getcomposer.org/installer | php
- mv composer.phar /usr/local/bin/composer
- Check file permissions:
script:
- chmod +x vendor/bin/*
- php artisan safeguard:check --fail-on-error
Problem: Security checks fail in Docker containers
Solutions:
- Check file permissions:
# In your Dockerfile
RUN chown -R www-data:www-data /var/www
RUN chmod -R 755 /var/www/storage
- Install required extensions:
RUN docker-php-ext-install pdo_mysql mbstring
- Set proper working directory:
WORKDIR /var/www
COPY . .
RUN composer install --no-dev
# Laravel debug mode
APP_DEBUG=true php artisan safeguard:check --verbose
# PHP error reporting
php -d display_errors=1 -d error_reporting=E_ALL artisan safeguard:check
# Laravel logs
tail -f storage/logs/laravel.log
# System logs (if applicable)
tail -f /var/log/php_errors.log
# Test individual components
php artisan safeguard:list
php artisan safeguard:config validate
php artisan safeguard:test-rule app-key-is-set
# Check Laravel installation
php artisan --version
php artisan env
# Time execution
time php artisan safeguard:check
# Memory usage
php -d memory_limit=1G artisan safeguard:check --verbose
# Profile with xdebug (if available)
php -d xdebug.profiler_enable=1 artisan safeguard:check
Common Issues:
- Missing .env file
- Incorrect file permissions
- Database connection issues
Solutions:
# Setup local environment
cp .env.example .env
php artisan key:generate
chmod 755 storage/
chmod 755 bootstrap/cache/
Common Issues:
- Strict file permissions
- Limited PHP extensions
- Memory/timeout limits
Solutions:
# Check production requirements
php --version
php -m | grep required_extension
# Optimize for production
composer install --no-dev --optimize-autoloader
php artisan config:cache
Common Issues:
- Missing dependencies
- Incorrect environment variables
- Timeout limits
Solutions:
# Use appropriate timeouts
php -d max_execution_time=300 artisan safeguard:check
# Set proper environment
export APP_ENV=testing
export APP_DEBUG=false
- β Check this troubleshooting guide
- β Read the FAQ
- β Search existing issues
- β
Try with
--verbose
flag - β Test with minimal configuration
Include this information:
# System information
php --version
composer --version
php artisan --version
# Package information
composer show grazulex/laravel-safeguard
# Laravel environment
php artisan env
# Error output with verbose flag
php artisan safeguard:check --verbose
- π Documentation: Laravel Safeguard Wiki
- π Bug Reports: GitHub Issues
- π¬ Questions: GitHub Discussions
- π§ Security Issues: Contact maintainers directly
# Create new Laravel project
composer create-project laravel/laravel test-safeguard
cd test-safeguard
# Install Laravel Safeguard
composer require --dev grazulex/laravel-safeguard
# Publish config
php artisan vendor:publish --tag=safeguard-config
# Test with minimal configuration
php artisan safeguard:check --verbose
Checklist:
- Same PHP version
- Same Laravel version
- Same package versions (
composer.lock
) - Environment variables set
- File permissions correct
- Required extensions installed
Solutions:
- Reduce
scan_paths
- Increase
timeout_seconds
- Enable
parallel_processing
- Use rule caching
- Limit
max_scan_files
Solutions:
- Customize
secret_patterns
- Exclude test directories
- Use environment-specific rules
- Create custom rules for specific needs
Still having issues? Check the β FAQ or create an issue on GitHub.
Laravel Safeguard - Configurable Security Checks for Laravel Applications
π Home | π¦ Installation | β‘ Quick Start | π‘ Examples | π Full Docs
Made with β€οΈ for the Laravel community
Β© 2025 - Laravel Safeguard by Grazulex