使用PHP7.1的Laravel项目出现Nginx 'No input file specified.'错误求助
Looking at your error log, the key line pointing to the root issue is:
PHP message: PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0 Unable to open primary script: /var/www/public/index.php (Operation not permitted)
Even though your index.php has wide-open 777 permissions, PHP-FPM is being blocked from accessing it. Let's work through the most common fixes step by step:
1. Check SELinux (Most Likely Hidden Culprit)
SELinux is often the silent blocker here—it enforces access controls separate from Unix file permissions.
First, check if SELinux is active in enforcing mode:
sestatusIf the output shows
Current mode: enforcing, it's restricting PHP-FPM's access to your files.To test if this is the issue, temporarily disable SELinux (don't leave this off long-term):
setenforce 0If your site loads after this, set the correct SELinux context for your web directory to fix it permanently:
# Allow web processes to read your Laravel files chcon -R -t httpd_sys_content_t /var/www/ # Allow write access to Laravel's required directories chcon -R -t httpd_sys_rw_content_t /var/www/storage /var/www/bootstrap/cache
2. Verify PHP-FPM User Permissions
PHP-FPM runs as a specific user (usually www-data, nginx, or php-fpm), and this user needs proper access to your /var/www directory.
Find your PHP-FPM user/group:
Open your PHP-FPM pool config (typically at/etc/php/7.1/fpm/pool.d/www.conf) and look for these lines:user = www-data group = www-dataEnsure this user owns your Laravel directory or has read access:
chown -R www-data:www-data /var/www chmod -R 755 /var/www(Note: The
storageandbootstrap/cachedirectories need write access, so update those if needed:chmod -R 775 /var/www/storage /var/www/bootstrap/cache)
3. Validate & Refresh Nginx/PHP-FPM Configs
Your Nginx config looks correct, but let's confirm and apply any changes:
Test the Nginx config for syntax errors:
nginx -tRestart both services to apply permission/context updates:
systemctl restart nginx systemctl restart php7.1-fpm
4. Check for Other Security Tools
If you're on a system with AppArmor or similar filesystem security tools, they might also block access. Check AppArmor's status with:
aa-status
If your PHP-FPM profile is restricting access to /var/www, you'll need to update the profile to allow it.
内容的提问来源于stack exchange,提问作者unknown

