apache alias vs symbolic link - apache

When working with apache on a unix system,
If your file system has icons in /home/me/web/icons
and you want the browser be able to display them when calling the url http://www.me.com/icons/myicon.jpg
for example,
then you have at least 2 solutions :
alias ( Alias /icons/ /home/web/icons/ )
symbolic links ( ln -s /home/web/icons /home/me/web/www/icons )
It seems to me that using apache aliases is the best choice since we know exactly that aliases
would normally be in the /etc/apache2 directory ( so that is just one place to look at in case the application
grows ), but I would be pleased to know about what solution you use and why ?

Using an Alias in your Apache httpd has several advantages over using a symbolic link:
Symbolic links require an additional disk access to resolve the symbolic link.
Alias works on all platforms supported by Apache httpd. Symbolic links are not supported by all platforms and filesystems.
Your Apache httpd configuration will work the exactly same way on a new system without the need to create symbolic links in your file system.

With shared hosting you are not authorized to alter the Apache config, so a symlink is an alternative.

Using an alias in the config file effectively documents your configuration. Using a link might well work but would not be an approach i would take.
On a productions machine I would use neither. Giving access to a user's directory would not be ideal from a security perspective. From the point of version control the icon directory should be filled like any other resource be it html or other form the QA'd release.
J

Related

Trac on shared server

I'm facing an odd problem with Trac's authentication. I have it installed in other servers and never had problem to install it, but now I'm trying to install it on a shared linux server where:
don't have access to httpd.conf;
only available scripts are php and python (wsgi);
no dev tools at all (so no chance to use gcc to compile something);
.htaccess is okay.
Well, trac is installed and working in anonymous mode and I can not find a way to make it private. It looks like it only relies on Apache basic authentication but I can not do this without httpd.conf access.
On my other instalations I use <Location> inside httpd.conf, but I can't use this tag inside .htaccess. I know that I can simply put <Location>'s content inside a .htaccess file and put this file in any www subdirectory to protect it. But since this is a wsgi script in another directory outside www I have no place to put that .htaccess.
I'm looking for a way to solve this by:
still using apache auth with any other .htaccess configuration that I've missed;
any other way Trac could be used in privative besides relying on apache;
any other issue/project tracking similar to trac is an option too.
I'm using AccountManagerPlugin on a shared Linux server machine of mine without issues.

SVN+Apache: Where to store repositories

I have been keeping all my Subversion repositories on my local computer for a while, but now I decided to move them to my web hosting server. It's an apache server and the hosting company has set up svn. My question is, where should I store my svn repositories. I originally stored them in the public_html/ directory, but (I'm certainly no security expert) I think only publicly available web content should be stored there. On the other hand, if I try storing the repositories in ~/var/svn/ then my subversion client (Eclipse) says "no element found". How do other people store their repositories with regards to Apache? Thank you.
You can select any physical location for your repositories collection, because logical path is defined inside Apache (Location container + SVNPath|SVNParentPath) later. You have only
select big partition (repository may require a lot of space)
don't forget chown|chmod repo dirs, in order to give Apache process the ability to handle files of repository
/var (/var/repos/) is good candidate for repo-root
Typically, you would store data in an appropriate subdirectory of /var (not ~/var), that is if you have access to it. E.g. /var/svn
We haven't adopted SVN for our web source yet, but have been using CVS. Our solution was to simply prevent Apache from serving the CVS store using IndexIgnore
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
You may be able to do something similar, using something based upon .svn.
It will be difficult if you are using a shared web hosting, because you need to have an access to root, to create svn-group and creating the structure of the repository. You also need to install some module on Apache like dav_svn. You will need to create a VirtualHost (sites-available) in order to serve your repos over a specific DNS.
There is a lot of tutorial on the inter-webs -> http://www.debuntu.org/how-to-subversion-svn-with-apache2-and-dav/ (for ubuntu)
Me, I rent a Virtual Private Server to host my SVN.

How do I set up virtual host directories for sub-subdomains same as subdomains?

I currently use mod_vhost_alias with a wildcard ServerAlias to catch all subdomains for the domain I use to hold development versions of websites.
This works great, but I reach an issue when I need to test websites that have 'm.' subdomain flexibility for mobile versions. In a live environment, this subdomain would still use the same directory as the normal domain, but I am unable to achieve this in development.
Example:
website.devdomain.com goes to /var/www/website.devdomain.com, and m.website.devdomain.com goes to /var/www/m.website.devdomain.com, but preferably this should go to /var/www/website.devdomain.com
Is there a way to make sub-subdomains go to their parent's directory? The current VirtualDocumentRoot snippet I use is VirtualDocumentRoot /var/www/%0/
I can create custom document roots on a per-site basis to achieve this, but if there is an automated way with VirtualDocumentRoot it would be much more practical.
I used to have the same problem, and found a simple solution: Symbolic Links!
If you're using a Linux system, you can create a symbolic link from your mobile document root to your main document root, like so:
ln -s /var/www/example.com /var/www/m.example.com
If you're on Windows, the solution is a little trickier, since Windows doesn't have an easy symlink command.
mklink /D C:\var\www\m.example.com c:\var\www\example.com
Note that the Windows version parameters are backwards from the Linux ones; Go figure.

Is there a way to check if a directory exists in Apache configuration files?

Is there a way to include configuration settings in Apache based on if a directory exists? Basically I have a portable hard drive that I transport between work and home that has some stuff I'm developing on it. I only want the Apache config to load a particular virtual host if the folder exists.
Since Apache 2.4.34 you can now use <IfFile>...</IfFile> which will check to see if a file exists. There's more details on the <IfFile> page.
No, there seems to be no direct way to do this.
The only thing that might be a solution is the IfDefine directive. You can define defines using the -d parameter to when the server is started.
The parameter-name argument is a define as given on the httpd command line via -Dparameter-, at the time the server was started.
You might be able to check for the existence of a directory in a batch or bash file, and set the -d parameter accordingly.
Whether that is an option, will depend on how your server is started from the portable hard drive.
I've come up with a solution that seems to work for Linux and OS X, and it hinges on "mountpoints". It might be possible to emulate it within Windows, as well, but you would probably have to get creative with FUSE and/or Cygwin.
If you create an empty folder in your home directory, such as "/Users/username/ExtraVhosts", you can add an apache directive to "Include /Users/username/ExtraVhosts/*".
Then, when you insert your thumb drive, you can mount somewhere and then use mountpoint "binding" to cross-link the ExtraVhosts folder to a folder on the mobile device.
An OS X example:
I have a thumb drive called 'Cherrybomb'
When I insert it, it always gets mounted to /Volumes/Cherrybomb
I can then use bindfs (sudo port install bindfs) to mount a subfolder of it, like so:
sudo bindfs /Volumes/Cherrybomb/Projects/vhosts /Users/username/ExtraVhosts
Then I can restart apache to read in the updated configuration:
sudo /opt/local/apache2/bin/apachectl restart
At that point, it's just a matter of adding entries in /etc/hosts for server aliases to get picked up.
The linux equivalent would be using the "--bind" parameter of the mount command.
One caveat: This makes it difficult to quickly unmount the USB drive, since it is always marked as "in use" by apache. Here's a removal procedure:
Close all open files and terminal sessions that are using the drive (the present-working-directory in terminal can cause unmount issues)
Stop apache: sudo /opt/local/apache2/bin/apachectl stop
umount /Users/username/ExtraVhosts
Then you can either unmount it graphically or manually (umount /Volumes/Cherrybomb).
If your work and home machines mount the drive to different locations, you could have multiple vhosts folders - home_vhost, work_vhost, etc - and use that in the binding step.
I hope this helps someone out :)
If you point apache to the mountpoint only there shouldn't be an issue. Just don't point Directory directives to directories within the drive.
eg, if you mount /dev/somedisk /mnt/somevhost, the
/mnt/somevhost directory will be there whether or not you have the drive mounted and apache will start. Apache doesn't care if the directory is empty so a <Directory "/mnt/somevhost"/> won't cause server to not start if the drive isn't mounted.
Work with UNIX not against it :-p This solution should be sufficient for development.

Using Alias in Apache ONLY if local directory not present?

We're running a reseller web host, and aliasing a particular directory for ALL the sites within. This is all happening through WHM/Cpanel, which could possibly complicate my question.
We want all hosts to run their "/concrete" directory through a shared location on the server. This is working fine by adding "Alias /concrete/ "/usr/local/share/concrete5/concrete-latest/concrete/" to the apache include editor in WHM.
However, if a local concrete/ directory exists within the particular webroot of the virtual host, we'd rather use that than "/concrete" globally. It would also be nice if we could make this alias change in the context of the virtual host, within WHM (and I haven't found a great way to modify virtual host sections in WHM without hacking a file that I don't believe we're supposed to hack.)
Thoughts?
A primitive, although probably quite effective solution might be to forget about the Alias directive and to simply rely on a symlink. A little shell script that creates those symlinks for you will simply fail if there is already something present that is called 'concrete'.