没有不值得去解决的问题,也没有不值得去学习的技术!

API Returns 500 After Deploying on LNMP 2.1 Due to Incorrect open_basedir in .user.ini

Check the Nginx error log. Error: PHP message: PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s)

1. The API responds with a 500 error. See Figure 1.

API responds with 500
Figure 1

2. Check the Nginx error log. Error: PHP message: PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s): See Figure 2.

Check the Nginx error log. Error: PHP message: PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s)
Figure 2
Plaintext

2025/03/11 10:46:31 [error] 323148#0: *3 FastCGI sent in stderr: "PHP message: PHP Warning:  require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/object/src/api/web/:/tmp/:/proc/) in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Warning:  require(/home/wwwroot/object/src/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Fatal error:  require(): Failed opening required '/home/wwwroot/object/src/api/web/../../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/object/src/api/web/index.php on line 6" while reading response header from upstream, client: 101.204.100.38, server: objectapi.ikhw.cn, request: "POST /unregistered-user/get-id HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "objectapi.ikhw.cn"



3. Reference: LNMP Add, Delete Virtual Host and Pseudo-Static Usage Tutorial Anti-Cross-Directory Settings  Check the contents of .user.ini

Plaintext

[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# cat .user.ini
open_basedir=/home/wwwroot/object:/tmp/:/proc/


4. Edit .user.ini. The .user.ini file cannot be modified directly; to modify or delete it, you must first run: chattr -i /home/wwwroot/object/.user.ini

Plaintext

[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# cat .user.ini
open_basedir=/home/wwwroot/object/src:/tmp/:/proc/


5. The error persists. I finally decided to delete .user.ini. Reference: LNMP Anti-Cross-Site and Cross-Directory Security Settings, Only Supports PHP 5.3.3 and Above Edit directly in php.ini

Plaintext

2025/03/11 10:53:59 [error] 323149#0: *5 FastCGI sent in stderr: "PHP message: PHP Warning:  require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/object/src/api/web/:/tmp/:/proc/) in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Warning:  require(/home/wwwroot/object/src/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Fatal error:  require(): Failed opening required '/home/wwwroot/object/src/api/web/../../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/object/src/api/web/index.php on line 6" while reading response header from upstream, client: 101.204.100.38, server: objectapi.ikhw.cn, request: "POST /unregistered-user/get-id HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "objectapi.ikhw.cn"

Plaintext

2025/03/11 10:53:59 [error] 323149#0: *5 FastCGI sent in stderr: "PHP message: PHP Warning:  require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/object/src/api/web/:/tmp/:/proc/) in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Warning:  require(/home/wwwroot/object/src/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Fatal error:  require(): Failed opening required '/home/wwwroot/object/src/api/web/../../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/object/src/api/web/index.php on line 6" while reading response header from upstream, client: 101.204.100.38, server: objectapi.ikhw.cn, request: "POST /unregistered-user/get-id HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "objectapi.ikhw.cn"

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系