Enabling virutal directory support for php

Hlo,

Ive been working on getting my server template set up the past week, and finally got it the way I wanted it. Now I’m just wondering if it is possible for each new master virutal server to have its own php.ini? I saw a few posts where people said there should be one setup by default in /home/*/etc/ but there was nothing to that effect there. I used the php configuration module and tried adding other global php.ini files, and that also did not work. Is there a way to at least allow each virtual server to use its own php.ini, I wouldn’t mind creating them manually, as long as it can be done.

Thanks,

Mark Armstrong

Joe,

Thanks for the reply here. I just want to make sure im doing this right before I mess up my pretty template :slight_smile:

For the lines you are having me add, I went to the apache website section in my template settings, and the first large box that is enabled after you choose: "apache directives below…" is where I added them.

Next,
When you refer to the virtual hosts section, are you referring to the virtual host declarations for each domain in httpd.conf? Would I add:
RemoveHandler .php

RemoveHandler .php4

to the ends each virtual host declaration in httpd.conf?

Lastly,

#!/bin/sh

PHPRC=$PWD/…/etc/php4

PHP_FCGI_CHILDREN=4

export PHP_FCGI_CHILDREN PHPRC

exec /usr/bin/php

Am I just making someting like wrappers.sh with this code and placing it in the /etc/skel directory? Do scripts in that directory get run automagically? :slight_smile:

Thanks again for the help. Now, you mentioned this was all scripted in the pro install scripts, so im guessing this features comes by default in the pro version? Thanks for not just saying "buy the pro version" :slight_smile:

mark

I got around to testing this again, and any php pages in public_html that I ran gave a forbidden error. I made a folder in /home/mydomain/ called fcgid and made a script alias for it. That didn’t work. I removed it, and then tried to run regular php files from public_html and that is when I got the forbidden errors. I removed all the fcgid info from the httpd.conf, and the php pages run fine. Any idea on what I may be missing here?

Here is the module section from phpinfo

apache2handler
Apache Version Apache/2.0.53 (RHEL)
Apache API Version 20020903
Server Administrator root@localhost
Hostname:Port mywebhostguys.com:0
User/Group apache(48)/48
Max Requests Per Child: 4000 - Keep Alive: off - Max Per Connection: 100
Timeouts Connection: 120 - Keep-Alive: 15
Virtual Server Yes
Server Root /etc/httpd
Loaded Modules core prefork http_core mod_so mod_access mod_auth mod_auth_anon mod_auth_dbm mod_auth_digest util_ldap mod_auth_ldap mod_include mod_log_config mod_env mod_mime_magic mod_cern_meta mod_expires mod_deflate mod_headers mod_usertrack mod_setenvif mod_mime mod_dav mod_status mod_autoindex mod_asis mod_info mod_dav_fs mod_vhost_alias mod_negotiation mod_dir mod_imap mod_actions mod_speling mod_userdir mod_alias mod_rewrite mod_proxy proxy_ftp proxy_http proxy_connect mod_cache mod_suexec mod_disk_cache mod_file_cache mod_mem_cache mod_cgi mod_fcgid mod_perl sapi_apache2 mod_python mod_ssl mod_dav_svn mod_authz_svn

got it. This looks good.

Server API CGI/FastCGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /home/mywebhostguys.com/etc/php.ini

Thanks for all the help Joe.

Hey Mark,

All of the multi-version PHP stuff (including php.ini per-virtual server) is currently tied to the Install Scripts feature of Virtualmin Professional…so it’s not in GPL. This will probably be refactored into generic code eventually. But, for now, you’ll need to make those decisions up front in your Server Templates—in the Apache website section where you can set directives, you’d add something like this to the public_html Directory section:

AddHandler fcgid-script .php
AddHandler fcgid-script .php4
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php4

And at the end of the VirtualHost section:

RemoveHandler .php
RemoveHandler .php4

(This allows it to be setup on a per-domain basis–you could change defaults versions and such. Obviously, this example doesn’t include php5, but adding other versions should be obvious.)

Then, of course, you’d need the wrappers in your skel directory. Those just look like this:

#!/bin/sh
PHPRC=$PWD/…/etc/php4
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN PHPRC
exec /usr/bin/php

This, of course, assumes you have mod_fcgid installed.

So, yeah, you can definitely do it…it’s even automatic, once you have the Server Templates setup right. Switching via the UI isn’t possible in GPL, though.

Hey Mark,

All of the multi-version PHP stuff (including php.ini per-virtual server) is currently tied to the Install Scripts feature of Virtualmin Professional…so it’s not in GPL. This will probably be refactored into generic code eventually. But, for now, you’ll need to make those decisions up front in your Server Templates—in the Apache website section where you can set directives, you’d add something like this to the public_html Directory section:

AddHandler fcgid-script .php
AddHandler fcgid-script .php4
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php4

And at the end of the VirtualHost section:

RemoveHandler .php
RemoveHandler .php4

(This allows it to be setup on a per-domain basis–you could change defaults versions and such. Obviously, this example doesn’t include php5, but adding other versions should be obvious.)

Then, of course, you’d need the wrappers in your skel directory. Those just look like this:

#!/bin/sh
PHPRC=$PWD/…/etc/php4
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN PHPRC
exec /usr/bin/php

This, of course, assumes you have mod_fcgid installed.

So, yeah, you can definitely do it…it’s even automatic, once you have the Server Templates setup right. Switching via the UI isn’t possible in GPL, though.

For the lines you are having me add, I went to the apache website section in my template settings, and the first large box that is enabled after you choose: "apache directives below..." is where I added them.

Yes, but explicitly they ought to be in the public_html Directory section within that. e.g. something like this:

<Directory ${HOME}/public_html>
Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/doxfer/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/doxfer/fcgi-bin/php5.fcgi .php5
</Directory>

Next, When you refer to the virtual hosts section, are you referring to the virtual host declarations for each domain in httpd.conf? Would I add: RemoveHandler .php

RemoveHandler .php4

to the ends each virtual host declaration in httpd.conf?

Well, yes, but I’m talking about Server Templates, so you only need to add it once (except for existing virtual servers. In the Server Templates case, put it at the end of the text in the same field as the Directory stuff I just mentioned.

Am I just making someting like wrappers.sh with this code and placing it in the /etc/skel directory? Do scripts in that directory get run automagically? :)

No, there’s no magic here. They need to be named what you called them in the FCGIWrapper directives. In my examples php5.fcgi or php4.fcgi in the fcgi-bin directory.

Now, you mentioned this was all scripted in the pro install scripts, so im guessing this features comes by default in the pro version?

Yes, it’s part of the Install Scripts feature (which needed this capability in order to install all of the 80 or so scripts that Virtualmin Professional can automatically install, since some require PHP4 and some require PHP5).

Thanks for not just saying "buy the pro version" :)

If we didn’t want people using the GPL version, we wouldn’t offer it. Remember, we’ve been Open Source developers far longer than we’ve built commercial products (and longer than most people have known what FOSS is). It’s not something we do for the PR value.

We also enjoy making a living, of course. But you’ll buy it when you want what Professional offers. In the meantime, we’ll just get you hooked on all the great stuff Virtualmin can do (GPL is already more powerful than any of our competitors…Professional is playing a whole new game). And, of course, next time you sign up for hosting, you’ll ask your hosting provider for Virtualmin Professional pre-installed because you’re used to it, and know how to do lots of cool stuff with it. And then we’ll all be very happy. :wink:

Hey Mark,

All of the multi-version PHP stuff (including php.ini per-virtual server) is currently tied to the Install Scripts feature of Virtualmin Professional…so it’s not in GPL. This will probably be refactored into generic code eventually. But, for now, you’ll need to make those decisions up front in your Server Templates—in the Apache website section where you can set directives, you’d add something like this to the public_html Directory section:

AddHandler fcgid-script .php
AddHandler fcgid-script .php4
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php4

And at the end of the VirtualHost section:

RemoveHandler .php
RemoveHandler .php4

(This allows it to be setup on a per-domain basis–you could change defaults versions and such. Obviously, this example doesn’t include php5, but adding other versions should be obvious.)

Then, of course, you’d need the wrappers in your skel directory. Those just look like this:

#!/bin/sh
PHPRC=$PWD/…/etc/php4
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN PHPRC
exec /usr/bin/php

This, of course, assumes you have mod_fcgid installed.

So, yeah, you can definitely do it…it’s even automatic, once you have the Server Templates setup right. Switching via the UI isn’t possible in GPL, though.

Hi Joe,

I worked on this this weekend a bit. Here is what I ended up with for my template:

ServerName ${DOM}
ServerAlias www.${DOM}
DocumentRoot ${HOME}/public_html
ErrorLog ${HOME}/logs/error_log
CustomLog ${HOME}/logs/access_log combined
ScriptAlias /cgi-bin/ ${HOME}/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory ${HOME}/public_html>
Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php4
</Directory>
<Directory ${HOME}/cgi-bin>
allow from all
</Directory>
RemoveHandler .php
RemoveHandler .php4

Here is what this turned into in httpd.conf:

<VirtualHost *:80>
SuexecUserGroup "#511" "#512"
ServerName anothertest.com
ServerAlias www.anothertest.com
ServerAlias lists.anothertest.com
DocumentRoot /home/anothertest/public_html
ErrorLog /home/anothertest/logs/error_log
CustomLog /home/anothertest/logs/access_log combined
ScriptAlias /cgi-bin/ /home/anothertest/cgi-bin/
ScriptAlias /awstats /home/anothertest/cgi-bin
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/anothertest/public_html>
Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/anothertest/fcgi-bin/php4.fcgi .php
FCGIWrapper /home/anothertest/fcgi-bin/php4.fcgi .php4
</Directory>
<Directory /home/anothertest/cgi-bin>
allow from all
</Directory>

RemoveHandler .php

RemoveHandler .php4
Alias /dav /home/anothertest/public_html
Alias /pipermail /var/lib/mailman/archives/public
<Location /dav>
DAV On
AuthType Basic
AuthName anothertest.com
AuthUserFile /home/anothertest/etc/dav.digest.passwd
Require valid-user
ForceType text/plain
</Location>
RedirectMatch /cgi-bin/mailman/([^/])(.) https://anothertest.com:10000/virtualmin-mailman/unauthenticated/$1.cgi$2
RedirectMatch /mailman/([^/])(.) https://anothertest.com:10000/virtualmin-mailman/unauthenticated/$1.cgi$2
</VirtualHost>

Does this look correct for the most part? From here am I just to copy the php.ini in home/somedomain/etc?

Also, for adding the wrappers in /etc/skel what I did was make php4.fcgi and pasted the code you provided. Im wondering If that is even the right place to put it? I think im close on this. Any more help is appreciated Joe.

Thanks,

Mark Armstrong

Hey Mark,

All of the multi-version PHP stuff (including php.ini per-virtual server) is currently tied to the Install Scripts feature of Virtualmin Professional…so it’s not in GPL. This will probably be refactored into generic code eventually. But, for now, you’ll need to make those decisions up front in your Server Templates—in the Apache website section where you can set directives, you’d add something like this to the public_html Directory section:

AddHandler fcgid-script .php
AddHandler fcgid-script .php4
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php
FCGIWrapper ${HOME}/fcgi-bin/php4.fcgi .php4

And at the end of the VirtualHost section:

RemoveHandler .php
RemoveHandler .php4

(This allows it to be setup on a per-domain basis–you could change defaults versions and such. Obviously, this example doesn’t include php5, but adding other versions should be obvious.)

Then, of course, you’d need the wrappers in your skel directory. Those just look like this:

#!/bin/sh
PHPRC=$PWD/…/etc/php4
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN PHPRC
exec /usr/bin/php

This, of course, assumes you have mod_fcgid installed.

So, yeah, you can definitely do it…it’s even automatic, once you have the Server Templates setup right. Switching via the UI isn’t possible in GPL, though.