PHP cannot use a ScriptAlias or Alias: Why? WorkAround?
Posted by: twohawks (---.lax.dsl-w.verizon.net)
Date: May 27, 2008 10:17PM

PHP cannot use a ScriptAlias or Alias: Why?

Hi Folks,
First post here. Installed Wamp a few days ago. Heard a lot of good things about it - including - the developers at fluxbb.org (formerly the punbb group) really had good things to say, which finally swayed my decision. So far I'm loving it...

Well after about a good ~18hours of research, modding, and testing I must conclude that it is simply not natively supported for php to utilize the apache alias or scriptalias. I am wondering if any of you know of a wrokaround other than what I am doing, or if I perhaps overlooked something (under the ca-gillion stones I overturned searching for an answer)? Following are details...

1) Create cgi-bin outside the document root, i.e., say your website is in www/public_html, then create www/cgi-bin
2) Set up a vhost for implied domain, and assign it to use said cgi-bin as the executable directory (it doesn't necessarily have to be the cgi-bin directory for this discussion, its simply convenient...)
3) Assume the ScriptAlias (or Alias, depending on your method for setting it up) is "/cgi-bin/"
3) Test your cgi (using the alias, of course).
4) Assuming all works correctly, you can use this directory to store sensitive data you wish to access from other scripts as well as cgi...

5a) For instance, I create a "text.ini" file containing sensitive info I wish to retrieve using a php script.
5b) I can access the data with php scripts using either of these paths:
- "home/www/cgi-bin/text.ini"
- "../cgi-bin/text.ini"
6) But there is no way in hell I have found that you can actually use the alias from php, ie...
- "/cgi-bin/text.ini" ...is a no go, no matter umteen ways I have tried to configure apache and/or vhosts.

Of course, my knowledge, and ability for creatively investigating the apache, cgi, and php manuals, is not expert (but I swear its been thorough),,.

SOOOO...
....Maayyyybee someone here has a trick, without implementing a complex cgi/php wrapper scenario or whathave-you...
(I may not have expressed that technically correctly, but you experts out there should know what I am referring to without getting into it - there's at least two methods I have read about, but htey require reconfiguring the server and php installations in a primary way - something I am uninterested in)...

..., i.e., a simple way of, say, telling apache and/or php (or whatever) to allow/instruct php to be able to actually use the alias ???

Just to be clear, checking the realpath to "../cgi-bin/text.ini" gives positive results (of course) whereas checking "/cgi-bin/" with php yields a blank result.
Of course, if I setup a cgi file in there I can it with the alias in, say for instance, an html form, etc.

What I end up having to do because of this is before uploading files to the "real-world" server, I have to change the places where I have these pathway concerns, i.e., another "different for testing locally than on my 'other' server" situation.

If nothing else, I hope that posting is useful for saving anyone else the major time you might spend hammering on this problem.

Your insights would be most welcome.
Cheers,
TwoHawks

Love is the Function, No Form is the Tool.

Options: ReplyQuote
Re: PHP cannot use a ScriptAlias or Alias: Why? WorkAround?
Posted by: toivo (203.19.130.---)
Date: May 27, 2008 11:48PM

Hi,

In the PHP applications I have seen it is common practice to store the path to the document root in a configuration file or a table and retrieve it from there when initiating the session.

On the other hand, you could use one of the magic constants like __FILE__ or __DIR__, for details see
[php.net]

Regards,

toivo
Sydney, Australia

Options: ReplyQuote
Re: PHP cannot use a ScriptAlias or Alias: Why? WorkAround?
Posted by: yfastud (Moderator)
Date: May 28, 2008 12:46AM

Quote

1) Create cgi-bin outside the document root, i.e., say your website is in www/public_html, then create www/cgi-bin
The answer is yes, you can create cgi-bin either inside or outside www folder; for example, www/friend1, www/buddy2 or d:/friend1, e:/buddy2
Quote

2) Set up a vhost for implied domain, and assign it to use said cgi-bin as the executable directory (it doesn't necessarily have to be the cgi-bin directory for this discussion, its simply convenient...)
VH for sub-domains would be
<VirtualHost *:80>
ServerName friend1.your_domain.com
DocumentRoot C:/wamp/www/friend1
ScriptAlias /cgi-bin/ "C:/wamp/www/friend1/cgi-bin/"
  <Directory "C:/wamp/www/friend1">
    Options Indexes FollowSymLinks Includes +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName buddy2.your_domain.com
DocumentRoot e:/buddy2
ScriptAlias /cgi-bin/ "e:/buddy2/cgi-bin/"
  <Directory "e:/buddy2">
    Options Indexes FollowSymLinks Includes +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
and VH for domains would be
<VirtualHost *:80>
ServerName www.friend1_domain.com
DocumentRoot C:/wamp/www/friend1
ScriptAlias /cgi-bin/ "C:/wamp/www/friend1/cgi-bin/"
  <Directory "C:/wamp/www/friend1">
    Options Indexes FollowSymLinks Includes +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName www.buddy2_domain.com
ScriptAlias /cgi-bin/ "e:/buddy2/cgi-bin/"
  <Directory "e:/buddy2">
    Options Indexes FollowSymLinks Includes +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Quote

3) Assume the ScriptAlias (or Alias, depending on your method for setting it up) is "/cgi-bin/"
Then url for sub-domains would be:
"[friend1.your_domain.com];
"[buddy2.your_domain.com];

And url for domains would be:
"[www.friend1_domain.com];
"[www.buddy2_domain.com];

Example cgi test script here (click submit to run cgi script, will be closed after an hour or two)
[test.jlbn.com]

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides



Edited 1 time(s). Last edit at 05/28/2008 06:28AM by yfastud.

Options: ReplyQuote
Re: PHP cannot use a ScriptAlias or Alias: Why? WorkAround?
Posted by: twohawks (---.lax.dsl-w.verizon.net)
Date: May 28, 2008 03:21AM

@ toivo: Thank you for your suggestion and reminding me about those magic constants.
I guess I can set a constant for /cgi-bin/ {using something like $cgi = realpath('../cgi-bin/') to do that}, but I was hoping I could simply continue to use "/cgi-bin/" anywhere for accessing it, to keep things simple and universal (across the board).

BTW, for anyone reading, __DIR__ is new in PHP 5.3.0, so be careful about relying on it in a purchased hosting situation ;^)

@ yfastud: Thank you for chiming in. I assume you realize what my question actually is, and that items 1-5 were not questions but details for understanding the involved directives for addressing the question, and that you are probably posting in order to help anyone who may come to read this thread... nice job.

Cheers,
HTH

Love is the Function, No Form is the Tool.

Options: ReplyQuote
Re: PHP cannot use a ScriptAlias or Alias: Why? WorkAround?
Posted by: yfastud (Moderator)
Date: May 28, 2008 05:15AM

I assume you've already tested my simple test scripts so I will close it now. As you have seen, my test site includes all simple test scripts for XML, XSL, Perl/CGI, SQLite, PHP, PHP+MySQL, PHP+SQL, ASP.net, ASP.net+SQL, ASP.net+MySQL, JSP... Before, I've left it open so everyone can test them out and even download those simple scripts so they can test locally, but some people really abuse my system, so no more now :-(

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: PHP cannot use a ScriptAlias or Alias: Why? WorkAround?
Posted by: twohawks (---.lax.dsl-w.verizon.net)
Date: May 28, 2008 09:26AM

Thanks yfastud.

Love is the Function, No Form is the Tool.

Options: ReplyQuote


Sorry, only registered users may post in this forum.