tags:

views:

321

answers:

3

I have 2 root directories for a site, httpdocs and httpsdocs. I am sure its obvious what the 2 are for. But I want to keep things consistent through-out the site like global navigation. Right now I have two separate files for this (one in each side) and I would like to only have one. This is hard to maintain because each time I change one I have to change the other (if I remember to), it breaks the DRY rule. But if I try to include a file from one side to the other using a relative path it tells me the file path is not allowed because it goes outside the document root. If I try to include it with an absolute URL I get another error saying file access is disabled in the server configuration. (I am on a hosting account so the most I can change as far as server config is limited to .htaccess). So can anyone think of a work-around for this?

+1  A: 

Do you have the ability to create symbolic links between the two directories?

ceejayoz
I am not sure, my hosting is LAMP, how would I go about creating one? Thanks.
John Isaacks
I don't think I can, I looked it up and I guess I need terminal access to the server but I do not, I can ask my service provider to set it up, is it possible to make a symbolic link to a directory then any file I want to share put in that directory? Thanks
John Isaacks
I also tried to create one using PHP's symlink() and I get an error saying: "Permission denied". Very frustrating.
John Isaacks
+1  A: 

Why not put your global include file in yet another directory (lets call it library) and then have each http root have an include file that includes ../library/lib.php, then sets specific paramaters. This gives you the added benifit of your library php files not being in the document root path as well.

And actually. Updating because I just read the entry about "relative path" issues.

Could you set the "include path" php value to include that directory?

Something like this:

ini_set('include_path', realpath(dirname(__FILE__)."/../library").":".ini_get('include_path'));
require_once('lib.php');

Did a little more research - seems that changing open_basedir is not possible unless you are able to edit the httpd.conf or php.ini values. PHP Manual: open_basedir

gnarf
If they are not in the document root I cannot access them, I get an error telling me the path is not allowed every time I try. Is there a way to ALLOW this using .htaccess or something?
John Isaacks
I get this error when I try what you said: Warning: main(): open_basedir restriction in effect. File(/var/www/vhosts/mydomain.com/library/lib.php) is not within the allowed path(s): (/var/www/vhosts/mydomain.com/httpsdocs:/tmp):(
John Isaacks
Sounds to me like you need to complain to your hosting provider that /var/www/vhosts/mydomain.com should be your "allowed path" not just httpsdocs or httpdocs. You may be able to override it with php_value open_basedir "/var/www/vhosts/mydomain.com:/tmp" in your .htaccess - if that doesn't fix your problem - complain to your host
gnarf
@gnarf, thanks what exactly should I put in my .htaccess file? this line exactly: [php_value open_basedir "/var/www/vhosts/mydomain.com:/tmp"]? Thanks a lot for your help!
John Isaacks
I would hope that would work (updated the answer to include that option as well) - but if not - its just bad configuration of the hosting provider. Its foolish to put "library" files in your document root anyway.
gnarf
Thanks, I added that to my .htaccess on both sides and didn't see a change. I sent my hosting provider an email, hopefully they'll fix it. Thanks for all your help!
John Isaacks
I'm going to guess you're using Plesk - you should put the openbasedir directive in your vhost.conf, in the conf folder above httpdocs.<Directory /var/www/vhosts/mydomain.com/httpdocs> php_admin_value open_basedir "/var/www/vhosts/dir/you/need/access/too:/var/www/vhosts/mydomain.com/httpdocs:/tmp"</Directory>
Darren Newton
@Hieronymus, YES I am using Plesk, when I FTP into the server I can see the conf directory but I don't have permission to open it. My hosting provider said all they can do is point both http and https to the httpdocs directory, which would take a lot of work on my end to make sure it went smoothly because it is a very large site with many files on the httpsdocs side.
John Isaacks
Either your hosting company or the administrator of this server need to give you permissions to modify vhost.conf. I'm the admin on my server, so I just ssh in and do what I need to. Alternatively you could ask them to place the correct directive in vhost.conf for you.
Darren Newton
A: 

Are you using sub domain within your directory, i also had something same then i recreated the sub domain and it solved....

kamkaar