I have a Virtual Private server with Dreamhost. I’m trying to create a shared folder that all of my domains can access. In the folder I’d like to put PHP classes, and even static files like javascripts.
I’ve created a directory on the same level as my domain folders. I’d like to call a file via something like this… /home/username/shared/file.php. This isn’t working however, and I’m hoping some magic (like .htaccess maybe) will make this work.
EDIT: Oops, OK, I am able to include PHP files using the method above. How can I include static files like Javascript, CSS, images, etc from the same directory?
This works:
<?php include('/home/username/shared/file.php'); ?>
This doesn’t work:
<link rel="stylesheet" type="text/css" href="/home/username/shared/reset.css" media="screen" />
Alternatively, I realize that I could just place my static files inside of a domain, and simply point to them, but I’d like to know how to make this other configuration work.
You should be happy that
<link rel="stylesheet" type="text/css" href="/home/username/shared/reset.css" media="screen" />did not work. If it would, you would have a great security hole.The correct way is to make a symlibk to that shared directory in your document root, or using Aliases.
The Symlink Method
Run the following in a shell:
It’ll create a symlink named
/home/target/shared, pointing to/home/username/shared. You might need add aOptions +FollowSymLinksdirective to your server config (or a.htaccessfile)The Alias Method
This method requires a change in your server configuration (e.g. httpd.conf). Add an
Aliasdirective to it:Note: this will only be used for requests through your server (e.g.
http://example/shared/reset.css), and not for PHP files. Within PHP files, you have to use the full path (/home/username/shared/file.php)Which method you choose is up to you. The latter is easier to configure as you do not have to worry about permissions / ownership. The former could be used if you really need to use
/home/target/shared/file.php.