You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PHP7.1的Laravel项目出现Nginx 'No input file specified.'错误求助

Troubleshooting "No input file specified" in Laravel + Nginx + PHP 7.1

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:

    sestatus
    

    If 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 0
    

    If 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-data
    
  • Ensure 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 storage and bootstrap/cache directories 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 -t
    
  • Restart 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 23:27:43