Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 4 of 4
  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 08: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
    18

    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
    3,768
    cPanel/Enkompass 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 & Tags
Similar threads

  1. Individual php.ini files for PHP FCGI and PHP CGI
    By Miraenda in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 08-22-2011, 09:55 AM
  2. custom php.ini with php handler set as cgi
    By johny_gjx in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 02-16-2009, 04:54 AM
  3. Replies: 8
    Last Post: 06-18-2008, 08:45 PM
  4. PHP5 not detecting php.ini in user's home dir
    By a_raims in forum cPanel and WHM Discussions
    Replies: 8
    Last Post: 10-06-2006, 03:14 AM
  5. php5(cgi) ignoring php.ini files in user dirs
    By panayot in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 06-09-2006, 03:21 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube