在AWS EC2上更改Apache文档根目录无效 [英] Changing Apache document root on AWS EC2 does not work

查看:106
本文介绍了在AWS EC2上更改Apache文档根目录无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个目录中有一个PHP文件:/home/ec2-user/folder/file.php,然后我安装了LAMP服务器.

I have a PHP file in this directory : /home/ec2-user/folder/file.php and I setup the LAMP server.

我尝试过的事情:

A.更改/etc/httpd/conf/httpd.conf

我更改了DocumentRoot和目录,并将覆盖"更改为全部".这是我所做的更改:

I changed the DocumentRoot and the Directory and I change the Override to All. Here is the changes I made:

#DocumentRoot "/var/www/html"
DocumentRoot "/home/ec2-user/folder"

#<Directory "/var/www/html">
<Directory "/home/ec2-user/folder">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride All

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>

但是,如果我致电<publicDNS>/file.php,则会在服务器上找不到所请求的URL.

But If I call <publicDNS>/file.php I get the requested URL was not found on the server.

B.在/var/www/html文件夹中创建一个serveExternal.php文件.

B. Create a serveExternal.php file inside the /var/www/html folder.

内容是:

 $fileName = $_GET['filename'];
 echo $fileName;   // shown correctly
 $cwd = getcwd(); // get the current working directory
 echo $cwd ; // prints the /var/www/html
 chdir ("/home/ec2-user/folder/"); // Change directory to /home/bitnami/folder/
 require_once($fileName); // include the required file
 chdir ($cwd); // Change the directory to its original location

但是我的PHP文件从未被调用过.

But then my PHP file is never called.

有解决方案吗?

推荐答案

您需要将DocumentRoot更改为/home/bitnami/folder,您的文件位于此文件夹中,并且将文档根目录设置为其他用户的目录,因此您无法访问这些文件.

You will need to change the DocumentRoot to /home/bitnami/folder your files are in this folder and you are setting document root to different user's directory, so you are not able to access those files.

这篇关于在AWS EC2上更改Apache文档根目录无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆