How do I set dynamic include-paths?

Alles, was den Apache betrifft, kann hier besprochen werden.

How do I set dynamic include-paths?

Postby Squall83 » 14. January 2011 06:58

Hello everyone,

I have the following problem:
Two versions of a PHP-game are on a server and they each need their own include-paths so they don't use each other's code. Since until now I didn't have more than one project on the server all the include-paths were set in the php.ini which is extremely bad as I was told now. I asked this question in the German forum already (viewtopic.php?f=4&t=43893) but the guy who answered my questions lost his patience after a while and ran away swearing at my noobness as soon as he realized that while I surely know how to program I don't know much about PHP-specifics and - probably more importantly - server configuration. 8) I came as far as

"If you want each project to have their own include paths, then give each one a config.php which contains a single command, i.e. set_include_path("path1;path2;..."), and make the server call this file each and every time someone starts a php-script. You don't need to use 'include(relative/path/to/config.php)' in each and every single script, you can automize it."

So my question is: How do I automize this?

Greetings,
Squall83
Squall83
 
Posts: 10
Joined: 09. January 2011 22:12

Re: How do I set dynamic include-paths?

Postby Sharley » 15. January 2011 01:45

Are we talking about Apache in XAMPP as PHP is compiled as a module and permits the use of .htaccess to set an include path.
(CGI compiled PHP permits a custom php.ini file in each web root folder of as many projects as needed).


If using XAMPP then it is possible to use a .htaccess file in the web root folder of each of your projects to use...
php_value include_path
...following are some links that may help with getting a handle on this .htaccess method:
http://www.webdeveloper.com/forum/showt ... p?t=149130
Read item #2 in the following link:
http://www.geeksengine.com/article/php- ... -path.html


If you are not using XAMPP then the CGI custom php.ini file include_path configuration elements and instructions are also contained in the above links - more reading here especially some of the posted comments:
http://php.net/manual/en/function.set-include-path.php


I hope this helps you move forward as the above may be a more workable alternative to the information you have already received.

Good luck and best wishes.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: How do I set dynamic include-paths?

Postby Squall83 » 17. January 2011 19:14

Thanks for the links. They helped me a lot, but it doesn't work completely yet. I created .htaccess files in the root directories (i.e. the directories defined as "DocumentRoot" in my virtual hosts) and put my include-paths in there, so it looks about like this:

php_value include_path include_path = ".;D:\Programme\xampp\php\PEAR;.................."

Now I can get to the Login-Screen (which was not possible without these files if the php.ini doesn't have the paths), but if I try to log in the game, I get the dreaded 500 Error. I read in your links and also through Google-searching that I have to go to the httpd.conf and set Allow Override, but that didn't help. I searched the whole file and found "AllowOverride" 3 times, two of which being set to None (in <Directory /> and <Directory "D:/Programme/xampp/cgi-bin"> tags), which I set to All now and one in the tag "<Directory "D:/Programme/xampp/htdocs">", which was set to All already. However I still get Error 500. I did restart Apache after changing the Allows, of course.

Maybe it helps if I say that the game runs on 2 virtual hosts (portal and game) and each of them received a .htaccess from me.
Squall83
 
Posts: 10
Joined: 09. January 2011 22:12

Re: How do I set dynamic include-paths?

Postby WilliL » 17. January 2011 20:23

google sagt dazu http://www.php-resource.de/forum/php-developer-forum/58936-frage-zu-htaccess-php_value-include_path.html

danach würde ich die htaccess ändern in:
Code: Select all
php_value include_path ".;D:\Programme\xampp\php\PEAR;.................."
Willi
WilliL
 
Posts: 660
Joined: 08. January 2010 10:54
Operating System: Win7Home Prem 64 SP1

Re: How do I set dynamic include-paths?

Postby Sharley » 18. January 2011 03:06

Squall83 wrote:php_value include_path include_path = ".;D:\Programme\xampp\php\PEAR;.................."
You have include two include_path entries when only one is required
Code: Select all
php_value include_path = ".;D:\Programme\xampp\php\PEAR;.................."


Squall83 wrote:but if I try to log in the game, I get the dreaded 500 Error.
When ever you get this server error check in the \xampp\apache\logs\error.log file, which will be quite specific as to the error 500 cause - you can drag this file into your text editor or associate the file extension .log with your text editor for double clicking to open and edit.


Squall83 wrote:I read in your links and also through Google-searching that I have to go to the httpd.conf and set Allow Override
You have been misled, you should set this directive in each individual vhost container, for example, like so
Code: Select all
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Note the syntax - no space between Allow and Override.

When the server finds an .htaccess file in the vhosts container DocumentRoot, it needs to know which directives declared in that file can override earlier configuration directives - All, None or specific directives:
http://httpd.apache.org/docs/2.2/mod/co ... owoverride
Squall83 wrote:...which I set to All now
You must not change the httpd.conf file settings from their defaults as you are going to do this on a directory by directory basis in your .htaccess files which is what you want to do, right?
You could open all sorts of security holes by not knowing the consequences of changing the default httpd.conf file settings.
So please return the httpd.conf file back to it's default settings.


Read the error.log file with regard to error 500 and we will be a position to move forward.

Best wishes. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: How do I set dynamic include-paths?

Postby Squall83 » 22. January 2011 10:17

Oops, I didn't see that typo. ^^ My error.log states that the path couldn't be found, but since I had that typo it's obvious why. Now that I removed the typo it seems to work. After all the trouble I had in the other thread I never thought that it'd be as simple as copying the include path into both .htaccess files and changing the syntax a little bit. Thank you so much! ^_^

I read that "Options" is set to All by default. Is it important to limit the options or can I leave my .htaccess files with just the include path command? I mean, I don't need any options other than that single include path command.

Also I returned the httpd.conf back. I only did it because whenever something doesn't work at all I try to remove all potential error sources and if it works afterwards then I revert the changes step by step to see where the error came from. And if it doesn't work even after opening all those security holes then at least I know that I misunderstood something basic. ^^
Squall83
 
Posts: 10
Joined: 09. January 2011 22:12

Re: How do I set dynamic include-paths?

Postby Sharley » 22. January 2011 11:34

Squall83 wrote:I read that "Options" is set to All by default. Is it important to limit the options or can I leave my .htaccess files with just the include path command? I mean, I don't need any options other than that single include path command.
These access options should be defined in each of your vhosts containers in the <Directory> directive and so there would be no need to include them in the .htaccess file of each DocumentRoot.

Actually most of what you want to do can be included in each vhost container as vhosts are quite powerful in what they can include being their own httpd configuration file which overrides the main httpd.conf file as it is read after the main one.

The vhost manual is here:
http://httpd.apache.org/docs/2.2/vhosts/

So it looks like you are now moving forward and should start to enjoy being a server administrator as you have the right approach and finding where the documentation is located is half the battle. :)

Best wishes.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3


Return to Apache

Who is online

Users browsing this forum: No registered users and 200 guests