View Poll Results: Did this help you install PHP as CGI on Dreamhost?

Voters
0. You may not vote on this poll
  • Yes

    0 0%
  • No

    0 0%
+ Reply to Thread
Results 1 to 1 of 1

Thread: Install PHP as CGI on DH

  1. #1
    Administrator Administrator's Avatar
    Join Date
    Feb 2006
    Location
    Superb Development
    Posts
    362

    Install PHP as CGI on DH

    Install PHP as cgi tutorial for DH

    Create a cgi-bin folder in your web directory
    /yourwebsite.com/cgi-bin

    Put these two files php-copy.sh and php-update.sh in your main website directory.
    /yourwebsite.com

    Create php as CGI
    php-copy.sh
    Code:
    #!/bin/sh
    CGIFILE="$HOME/testsite.superbdevelopment.net/cgi-bin/php.cgi"
    INIFILE="$HOME/testsite.superbdevelopment.net/cgi-bin/php.ini"
    rsync -a /dh/cgi-system/php5.cgi "$CGIFILE"
    # REMOVE THE FOLLOWING LINE TO CREATE THE UPDATE-ONLY SCRIPT:
    cp /etc/php5/cgi/php.ini "$INIFILE"
    
    perl -p -i -e '
    s/.*post_max_size.*/post_max_size = 100M/;
    s/.*upload_max_filesize.*/upload_max_filesize = 100M/;
    ' "$INIFILE"
    To keep php up to date
    Code:
    #!/bin/sh
     
     test $# = 0 && exit 1
     while test "$1";do
       case $1 in
         -php5) PHP=php5 ;; 
         -sm) shift; SM=$1 ;;
         -rg) shift; RG=$1 ;;
         -pms) shift; PMS=$1 ;;
         -umfs) shift; UMFS=$1 ;;
         -mqg) shift; MQG=$1 ;;
         -met) shift; MET=$1 ;;
         -mit) shift; MIT=$1 ;;
         -ml) shift; ML=$1 ;;
         *) D=$1 ;;
       esac
       shift
     done
     test "$D" || exit 1
     test -d "$HOME/$D" || exit 1
     CGI="$HOME/$D/cgi-bin"
     mkdir -m0755 -p $CGI || exit 2
     
     PHP=${PHP:-php}
     SM=${SM:-On}
     RG=${RG:-Off}
     PMS=${PMS:-8M}
     UMFS=${UMFS:-7M}
     MQG=${MQG:-Off}
     MET=${MET:-30}
     MIT=${MET:-60}
     ML=${ML:-8M}
     
     CGIFILE="$CGI/$PHP.cgi"
     INIFILE="$CGI/php.ini"
     
     echo "CGI=$CGI MQG=${MQG} UMFS=${UMFS} PMS=${PMS} RG=${RG} SM=${SM} MET=${MET} MIT=${MIT} ML=${ML}" >&2
     
     rsync -au /dh/cgi-system/$PHP.cgi "$CGIFILE"
     [ -s /etc/$PHP/cgi/php.ini ] && \
       sed -e "s/^safe_mode[ ]*=.*/safe_mode = $SM/" \
       -e "s/register_globals[ ]*=.*/register_globals = $RG/" \
       -e "s/magic_quotes_gpc[ ]*=.*/magic_quotes_gpc = $MQG/" \
       -e "s/.*post_max_size.*/post_max_size = $PMS/" \
       -e "s/.*upload_max_filesize.*/upload_max_filesize = $UMFS/" \
       -e "s/.*max_execution_time.*/max_execution_time = $MET/" \
       -e "s/.*max_input_time.*/max_input_time = $MIT/" \
       -e "s/.*memory_limit.*/memory_limit= $ML/" \
    
     
     chmod 0755 "$CGIFILE"
     chmod 0644 "$INIFILE"
     [ -s $CGI/.htaccess ] || echo "Options -Indexes" > $CGI/.htaccess
     touch $HOME/$D/.htaccess
     if grep -q '^Options' $HOME/$D/.htaccess; then
       grep -q '+ExecCGI' $HOME/$D/.htaccess || \
         sed -i 's/^Options\(.*\)/Options\1 +ExecCGI/' $HOME/$D/.htaccess
     else
       echo "Options +ExecCGI" >> $HOME/$D/.htaccess
     fi
     grep -q '^AddHandler[ ]\+php-cgi[ ]\+.php' $HOME/$D/.htaccess ||
       echo "AddHandler php-cgi .php" >> $HOME/$D/.htaccess
     if grep -q '^Action[ ]\+php-cgi' $HOME/$D/.htaccess; then
       sed -i "s@^Action[ ]\+php-cgi.*@Action php-cgi /cgi-bin/$PHP.cgi@" \
         $HOME/$D/.htaccess
     else
       echo "Action php-cgi /cgi-bin/$PHP.cgi"  >> $HOME/$D/.htaccess
     fi
    Check your cgi-bin directory to make sure you have the following in your .htaccess file.
    If it is not then do the following
    /yourwebsite.com/cgi-bin/
    Inside the cgi-bin directory create a .htaccess file with this code inside it:
    Code:
    redirect 301 php.cgi http://yourwebsite.com
    redirect 301 php.ini http://yourwebsite.com
    Run the two .sh scripts in your SSH console make sure you leave them at the defaults then you can go edit your php.ini file to your custom settings.

    Once your complete add this to the .htaccess file for your website content
    /yourwebsite.com
    Code:
    Options +ExecCGI 
    Options -Indexes
    AddHandler php-cgi .php
    Action php-cgi /cgi-bin/php.cgi
    Last edited by Administrator; 02-16-2007 at 07:18 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts