大网数据广告活动
服务器运维问答

PHP require not traversing up directory on AWS EC2 Instance

· 52CE 我爱测

This was working without issue but after running a system update on EC2, I noticed I was getting the following error and no matter what I do I can not resolve this. It just doesn't seem to move up a directory and tries to access …

问题原文

原帖链接 · curv · CC BY-SA 3.0

This was working without issue but after running a system update on EC2, I noticed I was getting the following error and no matter what I do I can not resolve this. It just doesn't seem to move up a directory and tries to access '../../' as part of the file path rather than traversing up two directories.

The file I am trying to require lives here

/var/www/html/site/app/data/myFile.php

My index file lives here: /var/www/html/site/public/rest/index.php

require __DIR__ . '/../../app/data/myFile.php';

The error

Fatal error: require(): Failed opening required '/var/www/html/site/public/rest/../../app/data/myFile.php' (include_path='.:/usr/share/pear:/usr/share/php')

已采纳解答

原帖链接 · pietrop · CC BY-SA 3.0

I can't write a comment due to my reputation (1 pt) but probably the reasons are two:

  1. Check if require "/var/www/html/site/app/data/myFile.php"; works. If not, check if the owner of /var/www/html/site/app/data (and all of its content) is the user running the server web (run top and see the username corresponding to apache2, apachectl or httpd).
  2. Try to execute print __DIR__; in order to check if it is correct and eventually follow this question posted on Stackoverlfow: https://stackoverflow.com/questions/31654069/wrong-dir-magic-constant-value. It's ununaswered but has some interesting tips.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。