在AWS EC2上更改Apache文档根目录不起作用


Changing Apache document root on AWS EC2 does not work

我在这个目录中有一个PHP文件:/home/ec2-user/folder/file.php,我设置LAMP服务器。

我尝试过的:

A。更改/etc/httpd/conf/httpd.conf 内的文档根目录

我更改了DocumentRoot和Directory,并将Override更改为All。以下是我所做的更改:

#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。

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

内容为:

 $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文件永远不会被调用。

有什么解决方案吗?

您需要将DocumentRoot更改为/home/bitnami/文件夹—您的文件在此文件夹中,并且您正在将文档根设置为不同用户的目录,因此您无法访问这些文件。