Attempting to use symbolic link for var/www/html

前端 未结 1 367
栀梦
栀梦 2021-01-05 03:30

this is what I\'m trying to accomplish: creating symbolic link from var/www/html to a directory in the home (~) folder. the directory I\'m trying t

相关标签:
1条回答
  • 2021-01-05 03:54

    This is because apache runs as apache user and the /var/www/html is owned by root in Amazon Linux AMI. You can change ownership/permissions as suggested by Frank, or use userdirs.

    It seems to me that you want the webserver's folder to be conveniently accessible from your home directory (~). I wanted something like this on my EC2 and decided to use Per-user web directories (mod_userdir).

    This feature of lets you keep parts of the HTTP server's space in a directory owned by a user. Each user gets his own directory, located by default in /home/username/public_html. The pages, scripts and other files in that directory are accessible to the internet by appending /~username to your domain. Additionally, you can change the name of that folder in httpd.conf from public_html to something else, like gitRepo. In that case, if you have an index.html file in /home/ec2-user/gitRepo/index.html, it will be accessible to the public via http://ec2-hostname.aws.amazon.com/~ec2-user/index.html and be owned by ec2-user, which is convenient for editing files from user level.

    To set this up on EC2 (assuming "gitRepo" for the folder name you want to use), use nano /etc/httpd/conf/httpd.conf to open Apache config file and scroll down until you see <IfModule mod_userdir.c>. Then change this section to look like the following:

    <IfModule mod_userdir.c>
        #
        # UserDir is disabled by default since it can confirm the presence
        # of a username on the system (depending on home directory
        # permissions).
        #
        UserDir enabled all
    
        #
        # To enable requests to /~user/ to serve the user's public_html
        # directory, remove the "UserDir disabled" line above, and uncomment
        # the following line instead:
        #
        UserDir gitRepo
    
    </IfModule>
    

    Afterwards you should be good to go but ensure the permissions are set up correctly:

    chmod 711 /home/ec2-user
    chmod 755 /home/ec2-user/gitRepo
    chown -R ec2-user /home/ec2-user/gitRepo
    

    And finally reload the web server like this:

    sudo service httpd reload
    
    0 讨论(0)
提交回复
热议问题