Results 1 to 4 of 4

Thread: php.ini per dir with php running as cgi

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    1

    Default php.ini per dir with php running as cgi

    Hello,

    Because of security concerns I'm running php as CGI+suexec instead as a module. How in this configuration I can have a php.ini per dir (or at least php.ini per virtual host)? I tried to replace the /usr/local/scripts/cgi-bin/php5 with a wrapper (intending to use the PHPRC variable) but immediately run into suexec security restrictions. Before continuing the struggle with the wrapper & suexec I decided to ask here:
    Is there a way using WHM to set this, or any other "canonical" way to do it?
    Any hints are welcome.
    Last edited by vesko; 12-13-2007 at 07:47 AM.

  2. #2
    Member
    Join Date
    Jun 2007
    Posts
    37

    Red face Try this...

    1. Moving php5 binary:

    mv /usr/local/cpanel/cgi-sys/php5 /usr/local/cpanel/cgi-sys/php5.bin

    2. Then creating wrapper file in the /usr/local/cpanel/cgi-sys/php5 with the following content:

    #!/bin/bash

    # This will fake the name & path and hide the /usr/local/cpanel/cgi-sys/php5 path!
    export SCRIPT_NAME=$REQUEST_URI
    export SCRIPT_FILENAME=$PATH_TRANSLATED
    export PWD=$DOCUMENT_ROOT

    if [ -f "$DOCUMENT_ROOT/php.ini" ]; then
    exec /usr/local/cpanel/cgi-sys/php5.bin -c $DOCUMENT_ROOT
    else
    exec /usr/local/cpanel/cgi-sys/php5.bin
    fi

    3. Save the file and change the permissons:

    chown root:wheel /usr/local/cpanel/cgi-sys/php5*;
    chmod 755 /usr/local/cpanel/cgi-sys/php5*;

  3. #3
    Member
    Join Date
    Nov 2006
    Location
    Sofia, Bulgaria
    Posts
    32
    cPanel/WHM Access Level

    Root Administrator

    Default

    Hi,
    I managet to get it working per virtual host with this wrapper (I also came up to the idea that it has to be chowned to root/wheel ):
    Code:
    #!/bin/sh
    user=`whoami`
    export PHPRC=/home/$user/public_html
    exec /usr/local/cpanel/cgi-sys/php5bin
    I reworked your wrapper to look like this:
    Code:
    #!/bin/bash
    
    # This will fake the name & path and hide the /usr/local/cpanel/cgi-sys/php5 path!
    export PWD=$DOCUMENT_ROOT
    
    export PHPRC=`dirname $PATH_TRANSLATED`/php.ini
    
    exec /usr/local/cpanel/cgi-sys/php5bin
    The PWD has to be exported to hide the path.
    I prefer to use the PHPRC, because it will just look in the specified directory for php.ini, because with the '-c' you have to first check does the files exists (as you do in your example).

  4. #4
    cPanel Development cPanelKenneth's Avatar
    Join Date
    Apr 2006
    Posts
    4,133
    cPanel/WHM Access Level

    Root Administrator

    Default

    Use mod_suphp. It will give you what you want, without having to jump through hoops with fragile wrappers.

Similar Threads

  1. Individual php.ini files for PHP FCGI and PHP CGI
    By Miraenda in forum cPanel & WHM Discussions
    Replies: 10
    Last Post: 05-19-2013, 01:46 AM
  2. custom php.ini with php handler set as cgi
    By johny_gjx in forum cPanel & WHM Discussions
    Replies: 0
    Last Post: 02-16-2009, 03:54 AM
  3. Replies: 8
    Last Post: 06-18-2008, 07:45 PM
  4. PHP5 not detecting php.ini in user's home dir
    By a_raims in forum cPanel & WHM Discussions
    Replies: 8
    Last Post: 10-06-2006, 02:14 AM
  5. php5(cgi) ignoring php.ini files in user dirs
    By panayot in forum cPanel & WHM Discussions
    Replies: 1
    Last Post: 06-09-2006, 02:21 PM