Using EBS for the www/http directory - apache

I have a simple web server set up on an ec2 instance.
I want to use a separate EBS disk to store the websites it hosts.
I have created and mounted a disk at /data and can access it via SSH and ftp.
But when i try to serve websites from it by specifying a folder there in vhosts, I get the standard apache page.
I think it might be something to do with permissions / ownership of the directory but I can't seem to figure it out.
Any advice?

Simple solution: you need to add the folder you want to serve from (in my case /data) in /etc/httpd/conf/httpd.conf
<Directory "/data">
AllowOverride None
# Allow open access:
Require all granted
</Directory>

Related

access same directory from multiple domains

Hi I have several domains that would like to access the same image repository. Is there an easy way of doing this? I am running plesk on linux.
I have found this page https://httpd.apache.org/docs/2.4/mod/core.html#directory. with this syntax to be put in the additional directives for http and https sections in the server settings.
will this
<Directory "/usr/local/httpd/htdocs">
Options Indexes FollowSymLinks
</Directory>
allow me to read and write to those directories?
FollowSymLinks option will allow exactly it - Apache will be able to process data which is not physically located inside domain directory, but is referred to by a symlink located inside domain directory.
There are two major points that you should be aware of:
1. You should have sufficient permission for system users of the domain which will be accessing shared files on the directory which contain these files. Basically, chmod 666 will do the job, but it is up to you how exactly set up rights to maintain desirable security level.
2. If websites are using PHP code, you should ensure that shared directory is included in open_basedir value.
This link can be useful - How to change open_basedir parameter for all domains?

Setting sabre/dav to have root directory outside of apache web root

I am trying to set up a WebDav server using sabre/dav. I got it set up and running and as long as I serve up files form with in the web server root (like /var/www/mydocs) I can access them in read-write mode. However, when I move sabre’s root directory to be like /mnt/mydocs I can only access them in read only mode. I do not think it is file permissions because I set them up the same both places and gave apache full access to both. I think it might be apache directory access directives but I have not found any combination that works. The last thing I tried in the apache config file was something like this.
<Directory “/mnt/mydocs”>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
Any ideas? Thanks for your help.

Is there any reason that the apache webroot /var/www/html is set as root-owned?

I just launched a LAMP dropplet from Digital Ocean and am starting coding. When trying to create a new directory inside the web root it says
mkdir: cannot create directory ‘blog’: Permission denied
I can fix this by running chown -R user /var/www/html but I'm wondering if this will break things or if there's a better way of doing this. Thanks!
You have a variety of options on permissions, but essentially www-data needs read (and probably execute) permission.
I like to redefine the DocumentRoot in my VirtualHost definitions to use something other than /var/www/html, anyway.
For example, you could use /srv/www/sitename, and then assign permissions myuser:www-data to it.
There are also numerous threads on the DigitalOcean forums (and around the internet) about permissions schemes for web files. (e.g. Proper Permissions for Web Server Directory.)

Load images outside apache directory

Well, I have a website in apache directory: /var/www/html. Previously I had all my web images in /var/www/html/media, so I used to put /media/imgX.jpgfor loading them. but now I need to put them in /mnt/imgs.
For some reason, using this path does not work the same way as before.
I think it has something to do with permissions using files from outside apache directory but I am not sure about it. Any idea?
The easiest way to add directories to Apache httpd is to use the "alias" module:
Alias /images "/mnt/imgs"
<Directory "/mnt/imgs>
Options Indexes
AllowOverride All
Require all granted
</Directory>
Once you have set up this, test it with: "yourdomain.com/images".
Of course:
The directory "/mnt/imgs" need the appropriate rights, so Apache Httpd can access it. Therefore you need to find out the group it runs with.
These files will be available to the public, if you dont secure them.
Once this is functional, remove the "indexes" line from the snippet above.

Apache always get 403 permisson after changing DocumentRoot

I'm just a newbie for Apache. I just installed apache 2.2 on the FreeBSD box at my home office. The instruction on FreeBSD documentation is that I can change the DocumentRoot directive in order to use the customized directory data. Therefore, I replaced...
/usr/local/www/apache22/data
with
/usr/home/some_user/public_html
but something is not right. There's index.html file inside the directory, but it seems that apache could not read the directory/file.
Forbidden
You don't have permission to access / on this server.
The permission of
public_html
is
drwxr-xr-x
I wonder what could be wrong here. Also, in my case, I am not going to host more than one website for this FreeBSD box, so I didn't look at using VirtualHost at all. Is this a good practice just to change the DirectoryRoot directive?
Somewhere in the apache config is a line like:
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/usr/local/www/apache22/data">
You must change this path too, to make it work. This directive contains for example:
Order allow,deny
Allow from all
Which give initial user access to the directory.
one possibility that comes to mind is SELinux blocking web process from accessing that folder. If this is the case, you would see it in selinux log. You would have to check the context for your original web root with:
ls -Zl
and then apply it to your new web folder:
chcon whatevercontextyousaw public_html
Or, instead, if its not a production server that requires security (like a development machine behind a firewall), you might want to just turn selinux off.
Just one idea. Could be a number of other things.