I have a question about how PHP and PHP Classes are handled by Virtualmin.
I have a specific PHP Class (http://sourceforge.net/projects/phpwhois/) I want to make available to all my Virtual Servers.
The install instructions, for this class are pretty vague, but easy enough to follow...
Basically, untar the distribution somewhere outside your server's document root and make sure the directory is listed in 'include_path' in your php.ini file, server configuration or in an .htaccess file. If you want to test it using a web browser just copy example.php , example.html and whois.icon.png anywhere on your server's document root and try it.
phpWhois is not a PHP aplication is a class that can be used in applications. There is no need to make the installation folder accesible to anyone but PHP, nevertheless you can install it inside your server's document root if you like, it will work without problems or security risks.
So... here are my questions.
Howdy,
One way to do that would be to place the files in a publicly accessible area on your server, where all domains could see and access them.
For example, you could put it in "/usr/local/lib/phpwhois/".
Then, for any domain that needs to access it -- you could add that path to the "include_path" line in $HOME/etc/php.ini.
-Eric
@andreychek - Thanks!
I was just curious if there was an area which PHP, on Virtualmin, already "included" for this type of thing (classes), so that I didn't have to add the path, to the "include_path" line, for every virtual server instance.
I know Smarty suggests installing to:
/usr/local/lib/php/Smarty/
...which is very close to what you suggested.
However, the <a href="http://www.php.net/manual/en/ini.core.php#ini.sect.path-directory'>PHP Manual suggested:
/path/to/php/pear
The php.ini file, found at:
/etc/php5/apache2/php.ini
...says basically the same thing:
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
;include_path = ".:/usr/share/php"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"
;
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
So, what I'm a little confused by is:
include_path = ".:usr/share/php/phpwhois"
include_path = ".:usr/share/php/pear"
/etc/php5/apache2/php.ini
will that include the classes for all of the Virtualmin, virtual web-server instances?Howdy,
Virtualmin isn't doing anything unusual with PHP... it simply ensures that the PHP provided by your distribution is installed.
If you're looking for best practices, you might want to review how your particular distribution recommends setting up things.
Is /usr/share/php a better option than /usr/local/lib?
I suspect it all comes down to personal preference :-)
Will PHP recognize all directories found in /usr/share/php from a single "include_path" or do I have to have a separate "include_path" for each class directory
PHP syntax isn't my area of expertise, but it looks like you can add all the paths on one line as shown here:
http://www.php.net/manual/en/ini.core.php#ini.include-path
If I make this change via Webmin, to the php.ini file, found at: /etc/php5/apache2/php.ini will that include the classes for all of the Virtualmin, virtual web-server instances?
When using the default FCGID mode (or even with CGI), the file "/etc/php5/apache2/php.ini " isn't read. The php.ini file is pulled from $HOME/etc/php.ini.
However, you could always create a .ini file in /etc/php5/conf.d containing parameters you want run, that would be read for all PHP apps running on your system.
-Eric
@andreychek
I use Debian for my servers and PEAR is located at:
/usr/share/php
So, I guess that is the best place to park other classes, too, huh?
I find three or four php.ini files on my system, recognized by Virtualmin/Webmin...
Which one do I use, to "include_path" for all virtual web-servers?
The only existing php.ini file that will be read is the one in $HOME/etc/php.ini.
Your other alternative would be to create a new .ini file in /etc/php5/conf.d, and add an include_path line in there.
-Eric
@andreychek
I understand that the $HOME/etc/php.ini is the only php.ini file that is read, which I assume is actually:
/home/WEBSITE-NAME/etc/php5/php.ini
...and is edited in Virtualmin by going to Services > PHP 5 Configuration > Edit Configuration Manually
So, when I go to Webmin > Others > PHP Configuration there are three php.ini files there:
/etc/php5/apache2/php.ini
/etc/php5/cgi/php.ini
/etc/php5/cli/php.ini
...are these files not used or un-needed? Do these files have an affect on PHP for the entire Virtualmin server? If I included the "include_path" statement in one of these files, would that take care of the issue for the whole Virtualmin server or would I still have to add that same "include_path" in the Services > PHP 5 Configuration > Edit Configuration Manually area, for each web-server instance?
If I included the "include_path" statement in one of these files, would that take care of the issue for the whole Virtualmin server or would I still have to add that same "include_path" in the Services > PHP 5 Configuration > Edit Configuration Manually area, for each web-server instance?
Well, as I mentioned above, if you want to add configuration to all domains on your server, you would need to do that by creating a new .ini file in /etc/php5/conf.d/, and putting the include_path in there.
That is the only way to have PHP configuration included in all domains on your server :-)
-Eric
@andreychek
I will have to give that a shot. I've been trying several things on my test server and can't seem to get things to work.
I used SSH to remote into my server and executed the command:
which pear
...and:
pear config-show
Using these commands, I'm able to see that PEAR is installed and running.
I created a PHP file with the following code:
<?php
require_once 'System.php';
var_dump(class_exists('System', false));
?>
...and when I load that PHP file in a web browser I get:
bool(true)
...which is what I'm supposed to get if PEAR is working correctly.
So, I can verify that PEAR is working correctly, across all Virtualmin virtual web servers. The problem is, I can't seem to verify if the specific PEAR installed classes, I want to use, are working, to verify if I can use PEAR for all virtual web servers or if I will have to do it another way, like the new .ini file in /etc/php5/conf.d/, like you recommended above.
I've been trying all day, to get the Net_GeoIP to work, and I'm not getting anything, but a black, white page.
...and of course, their support isn't nearly as good as yours ;-)
I've been trying all day, to get the Net_GeoIP to work, and I'm not getting anything, but a black, white page.
You may want to take a peek in your error logs, $HOME/logs/error_log.
If the site is throwing an error of any kind, it should be showing up in there.
-Eric