Trying to define custom php.ini for nobody under suPHP

santrix

Well-Known Member
Nov 30, 2008
225
2
68
We have tied down php.ini via a .conf file in

/usr/local/apache/conf/userdata/

I want to (due to a plugin for WHMCS) define a custom php.ini for the default virtual host entries in httpd.conf - specifically this section:

Code:
<VirtualHost 0.0.0.0:8888>
    ServerName server.domain.co.uk
    DocumentRoot /usr/local/apache/htdocs
    ServerAdmin [email protected]
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>
</VirtualHost>


# Default vhost for unbound IPs

<VirtualHost *>
    ServerName server.domain.co.uk
    DocumentRoot /usr/local/apache/htdocs
    ServerAdmin [email protected]
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>
</VirtualHost>
I need (I think) to add ...

Code:
Include "/usr/local/apache/conf/userdata/std/2/nobody/*.conf"
... to each of these VH entries, so I can define a different location for php.ini.

I could of course, just edit it in, but I know it will be overwritten. I'm aware of /var/cpanel/templates/main.default which contains the template for this area of httpd.conf, but again, if I edit it, it will be overwritten on the next cpanel update.

I suspect this requires me to create a .local file in the templates directory, and do something with distiller, but this is where I can't work out what to do next.... Help! :D
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
If you copy /var/cpanel/templates/apache2/main.default to /var/cpanel/templates/apache2/main.local location, then you can add an include line in the section you are indicating.

The specific section you mention would be the following:

Code:
[%- FOREACH vh IN sharedips -%]
# DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.

<VirtualHost [% vh %]>
    ServerName [% servername %]
    DocumentRoot [% serverroot %]/htdocs
    ServerAdmin [% serveradmin %]
    [%- IF supported.mod_suphp %]
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>
    [%- END %]
    [%- IF supported.mod_userdir && userdirprotect_enabled && defaultvhost.userdirprotect != '-1' %]
    UserDir disable
    [%- IF defaultvhost.userdirprotect != '' %]
    UserDir enabled [% defaultvhost.userdirprotect %]
    [%- END -%]
    [%- END %]
    Include "/usr/local/apache/conf/userdata/std/2/nobody/*.conf"
</VirtualHost>

[% END -%]

# Default vhost for unbound IPs

<VirtualHost *>
    ServerName [% servername %]
    DocumentRoot [% serverroot %]/htdocs
    ServerAdmin [% serveradmin %]
    [%- IF supported.mod_suphp %]
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>
    [%- END %]
    [%- IF supported.mod_userdir && userdirprotect_enabled && defaultvhost.userdirprotect != '-1' %]
    UserDir disable
    [%- IF defaultvhost.userdirprotect != '' %]
    UserDir enabled [% defaultvhost.userdirprotect %]
    [%- END -%]
    [%- END %]
</VirtualHost>

[%- FOREACH vhost IN vhosts -%]
In that section, you could do this:

Code:
[%- FOREACH vh IN sharedips -%]
# DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.

<VirtualHost [% vh %]>
    ServerName [% servername %]
    DocumentRoot [% serverroot %]/htdocs
    ServerAdmin [% serveradmin %]
    [%- IF supported.mod_suphp %]
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>
    [%- END %]
    [%- IF supported.mod_userdir && userdirprotect_enabled && defaultvhost.userdirprotect != '-1' %]
    UserDir disable
    [%- IF defaultvhost.userdirprotect != '' %]
    UserDir enabled [% defaultvhost.userdirprotect %]
    [%- END -%]
    [%- END %]
</VirtualHost>

[% END -%]

# Default vhost for unbound IPs

<VirtualHost *>
    ServerName [% servername %]
    DocumentRoot [% serverroot %]/htdocs
    ServerAdmin [% serveradmin %]
    [%- IF supported.mod_suphp %]
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>
    [%- END %]
    [%- IF supported.mod_userdir && userdirprotect_enabled && defaultvhost.userdirprotect != '-1' %]
    UserDir disable
    [%- IF defaultvhost.userdirprotect != '' %]
    UserDir enabled [% defaultvhost.userdirprotect %]
    [%- END -%]
    [%- END %]
    Include "/usr/local/apache/conf/userdata/std/2/nobody/*.conf"
</VirtualHost>

[%- FOREACH vhost IN vhosts -%]
After making those changes, you would not have to distill as this is the template file. You'd simply have to rebuild and restart. I suggest making a backup first of Apache configuration:

Code:
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak120203
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart