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 to symlink to in home (~
) is a git repository, if that makes any difference. I have an index.html file in this directory.
I've created a symbolic link to var/www/html on an Amazon EC2 instance using this command: ln -s ~/dirIWant/ html
, however this is resulting in the following error when I try to access my webpage: 403 Forbidden "You don't have permission to access / on this server."
I'm using apache.
Has anybody else tried to do something similar and gotten it to work?
Currently, when I go to my website www.blah.com, it shows this 403 error. I've tried to change the permission using sudo chown -h apache:apache
but it doesn't seem to help. Do you have any other ideas?
What exactly does /var/www/html mean? This is the default path that the more popular web servers use as the default. You should use the folder path your host says to use. It's the base directory for your website.
/var/www/html is the typical/default location. You should keep in the back if your mind that it is possible to override locations with "alias" directives - although these are typically used to graft programs web interfaces into a path and have a subdirectory associated with them.
To remove a symbolic link, use either the rm or unlink command followed by the name of the symlink as an argument. When removing a symbolic link that points to a directory do not append a trailing slash to the symlink name.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With