Error: Closure::{closure}(): Argument #2 ($handler) must be of type callable, Psr\Http\Server\RequestHandlerInterface@anonymous given
Root Cause: The rate limiting middleware was using an unnecessary anonymous class wrapper that was causing type conflicts.
Fix Applied: Simplified the middleware call in api/index.php line 72 to directly pass the handler instead of wrapping it.
Before:
return $limitMw->process($request, new class($handler) implements \Psr\Http\Server\RequestHandlerInterface {
public function __construct(private $handler) {}
public function handle(\Psr\Http\Message\ServerRequestInterface $request): \Psr\Http\Message\ResponseInterface {
return ($this->handler)($request);
}
});After:
return $limitMw->process($request, $handler);Error: Failed opening required '/home/appfast-new/htdocs/new.appfast.net/api/../vendor/autoload.php'
Root Cause: Composer dependencies were not installed in the production environment.
Solution: Run the deployment script to install dependencies.
# Navigate to your project directory
cd /path/to/your/project
# Run the deployment script
chmod +x scripts/deploy.sh
./scripts/deploy.shREM Navigate to your project directory
cd C:\path\to\your\project
REM Run the deployment script
scripts\deploy.bat-
Install Composer Dependencies:
composer install --no-dev --optimize-autoloader
-
Create Required Directories:
mkdir -p storage cache uploads storage/ratelimit chmod 755 storage cache uploads storage/ratelimit
-
Set Up Environment:
- Copy
.env.exampleto.env(if available) - Configure database connection
- Set JWT secrets
- Configure CORS settings
- Copy
-
Run Installation (if not done):
- Visit
/install/in your browser - Follow the installation wizard
- Delete
/install/directory after completion
- Visit
-
Verify Installation:
- Check that
install.lockfile exists - Test the
/healthzendpoint - Verify database connection
- Check that
Ensure these PHP extensions are installed:
mysqliorpdo_mysqlpdoopensslmbstringjsoncurl
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ api/index.php [QSA,L]location / {
try_files $uri $uri/ /api/index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}- Clear any PHP opcache:
php -r "opcache_reset();" - Restart your web server
- Check that the updated
api/index.phpfile is deployed
- Verify
vendor/autoload.phpexists - Check file permissions on the vendor directory
- Re-run
composer install --no-dev --optimize-autoloader
- Check database credentials in
.env - Verify database server is running
- Ensure database user has CREATE privileges
- Check PHP error logs for specific errors
After deployment:
- Delete
/install/directory - Verify
install.lockexists - Check file permissions (755 for directories, 644 for files)
- Configure proper CORS origins
- Set up SSL/TLS certificates
- Configure firewall rules
- Set up regular backups
Monitor these endpoints for health:
GET /healthz- Application health checkGET /csrf/token- CSRF token generation (should return 200)
If you continue to experience issues:
- Check PHP error logs
- Verify all required PHP extensions are installed
- Test database connectivity
- Review web server configuration
- Run the test suite:
php vendor/bin/pest --testsuite=unit