Not signed in (Sign In)
    • CommentAuthorzenobox
    • CommentTimeJun 24th 2008
     permalink
    Hi all,
    Does anyone help me about installation of php5 under nginx ? And configuration, of course.
    I don't found any specific discussion on this argument.

    Thank you
    Bye
    • CommentAuthoralphagears
    • CommentTimeJun 24th 2008
     permalink
    Yeah. I've got that set up. Sorry, this is a very long post.

    I'm using a init script to start php5-fastcgi...

    /etc/init.d/php-fastcgi
    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides: php-fastcgi
    # Required-Start: $all
    # Required-Stop: $all
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start and stop php-cgi in external FASTCGI mode
    # Description: Start and stop php-cgi in external FASTCGI mode
    ### END INIT INFO

    # Author: Kurt Zankl <[EMAIL PROTECTED]>

    # Do NOT "set -e"

    PATH=/sbin:/usr/sbin:/bin:/usr/bin
    DESC="php-cgi in external FASTCGI mode"
    NAME=php-fastcgi
    DAEMON=/usr/bin/php-cgi
    PIDFILE=/var/run/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME
    PHP_CONFIG_FILE=/etc/php5/cgi/php.ini

    # Exit if the package is not installed
    [ -x "$DAEMON" ] || exit 0

    # Read configuration variable file if it is present
    [ -r /etc/default/$NAME ] && . /etc/default/$NAME

    # Load the VERBOSE setting and other rcS variables
    . /lib/init/vars.sh

    # Define LSB log_* functions.
    # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
    . /lib/lsb/init-functions

    # If the daemon is not enabled, give the user a warning and then exit,
    # unless we are stopping the daemon
    if [ "$START" != "yes" -a "$1" != "stop" ]; then
    log_warning_msg "To enable $NAME, edit /etc/default/$NAME and set START=yes"
    exit 0
    fi

    # Process configuration
    export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
    DAEMON_ARGS="-q -b $FCGI_HOST:$FCGI_PORT -c $PHP_CONFIG_FILE"

    do_start()
    {
    # Return
    # 0 if daemon has been started
    # 1 if daemon was already running
    # 2 if daemon could not be started
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
    || return 1
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
    --background --make-pidfile --chuid $EXEC_AS_USER --startas $DAEMON -- \
    $DAEMON_ARGS \
    || return 2
    }

    do_stop()
    {
    # Return
    # 0 if daemon has been stopped
    # 1 if daemon was already stopped
    # 2 if daemon could not be stopped
    # other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE > /dev/null # --name $DAEMON
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently. A last resort is to
    # sleep for some time.
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    [ "$?" = 2 ] && return 2
    # Many daemons donâ^À^Ùt delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL"
    }
    case "$1" in
    start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
    stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
    restart|force-reload)
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
    0|1)
    do_start
    case "$?" in
    0) log_end_msg 0 ;;
    1) log_end_msg 1 ;; # Old process is still running
    *) log_end_msg 1 ;; # Failed to start
    esac
    ;;
    *)
    # Failed to stop
    log_end_msg 1
    ;;
    esac
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
    exit 3
    ;;
    esac


    Here is the /etc/default/php-fastcgi

    START=yes

    # Which user runs PHP? (default: www-data)

    EXEC_AS_USER=www-data

    # Host and TCP port for FASTCGI-Listener (default: localhost:9000)

    FCGI_HOST=localhost
    FCGI_PORT=10005

    # Environment variables, which are processed by PHP

    PHP_FCGI_CHILDREN=4
    PHP_FCGI_MAX_REQUESTS=1000


    /etc/nginx/fcgi.conf


    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;

    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT $document_root;
    fastcgi_param SERVER_PROTOCOL $server_protocol;

    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;

    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param REDIRECT_STATUS 200;


    One of my vhosts that uses php5...

    server {
    listen 80;
    server_name site.com;
    rewrite ^/(.*) http://www.site.com/$1 permanent;
    }

    server {
    listen 80;
    server_name www.site.com;
    client_max_body_size 2m;

    access_log /var/log/nginx/access.log;

    location / {
    root /path/to/site.com/default;
    index index.php;
    }

    # .php and .php5 sent to php5
    location ~ .*\.php[345]?$ {
    include /etc/nginx/fcgi.conf;
    fastcgi_pass 127.0.0.1:10005;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /path/to/site.com/default$fastcgi_script_name;
    }
    }
    Thankful People: scott9s, roshambo
    • CommentAuthorzenobox
    • CommentTimeJun 24th 2008
     permalink
    Thanks for your answer, but I wanted to ask: To set up and launch this script, before I must have installed something, some mod (ie php-fastcgi). Or do not have to install nothing compared to the basic configuration of nginx?
    Last info ... I installed source version of nginx ...

    Thanks
    • CommentAuthoralphagears
    • CommentTimeJun 24th 2008
     permalink
    The only PHP package you need to install is php5-cgi. That comes with fastcgi built in.

    I'm using the ubuntu nginx package. I'm pretty sure the only difference might be a few paths (/usr/bin/nginx vs. /usr/local/bin/nginx), but I don't think the above config would change.
    • CommentAuthorzenobox
    • CommentTimeJun 24th 2008
     permalink
    last thing ... to use php5 with mysql only have to install mysql, or I have to configure php in a particular way?
    Thank you and excuse my insistence
    • CommentAuthorrob
    • CommentTimeJun 24th 2008
     permalink
    Posted By: zenoboxlast thing ... to use php5 with mysql only have to install mysql, or I have to configure php in a particular way?
    Thank you and excuse my insistence

    You'll need the "php5-mysql" package.
    • CommentAuthorohkus
    • CommentTimeJun 24th 2008
     permalink
    I got slow speeds when using rsync.net so I'd look into:

    http://www.bqbackup.com or http://www.fxhbackup.com/
    • CommentAuthorifthengoto
    • CommentTimeDec 27th 2008
     permalink

    OK so I am just trying to move over from shared hosting and am out of my depth...

    I am trying set up Nginx to run wordpress and some other sites. (I was able to do it with a LAMP but that seemed to heavy for my small slice)

    I have used all the tutorials here and have installed Nginx via aptitude on Hardy and have used all the alphagears scripts on this page (thanks). The only one I did not use exactly was my Vhost file which looks like this:

    server {

            listen   80;
            server_name  site.com;
            rewrite ^/(.*) http://www.site.com/$1 permanent;
    
           }
    

    server {

            listen   80;
            server_name www.site.com;
    
            access_log /home/geek/public_html/site.com/log/access.log;
            error_log /home/geek/public_html/site.com/log/error.log;
    
            location / {
    
                        root   /home/geek/public_html/site.com/public/;
                        index  index.php index.html;
    
                        # Basic version of Wordpress parameters, supporting nice permalinks.
                        # include /usr/local/nginx/conf/wordpress_params.regular;
                        # Advanced version of Wordpress parameters supporting nice permalinks and WP Super Cache plugin
                        # include /usr/local/nginx/conf/wordpress_params.super_cache;
                        }
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include /etc/nginx/fcgi.conf;
            fastcgi_param SCRIPT_FILENAME /home/geek/public_html/site.com/public/$fastcgi_script_name;
            }
      }
    

    I am getting a 502 Bad Gateway nginx/0.5.33 and have searched around and have been unable to resolve.

    I read somewhere about ps ax | grep php and this is the answer I get. 4002 pts/0 R+ 0:00 grep php

    Does this mean that the php is not spawning correctly or is it something else?

    • CommentAuthoralphagears
    • CommentTimeDec 27th 2008
     permalink
    Hey ifthengoto,

    Yeah if nothing else comes up when you do a ps ax |grep php, then the php fast-cgi is not running. Did you start the daemon (/etc/init.d/php-fastcgi start)?
    • CommentAuthorifthengoto
    • CommentTimeDec 27th 2008
     permalink
    Hi alphagears,

    Thanks. It would not run because of permissions. I did chmod +x now it works and here is the result (I have no idea what it means)

    ps ax | grep php
    4088 ? Ss 0:00 /usr/bin/php-cgi -q -b localhost:10005 -c /etc/php5/cgi/php.ini
    4089 ? S 0:00 /usr/bin/php-cgi -q -b localhost:10005 -c /etc/php5/cgi/php.ini
    4090 ? S 0:00 /usr/bin/php-cgi -q -b localhost:10005 -c /etc/php5/cgi/php.ini
    4091 ? S 0:00 /usr/bin/php-cgi -q -b localhost:10005 -c /etc/php5/cgi/php.ini
    4092 ? S 0:00 /usr/bin/php-cgi -q -b localhost:10005 -c /etc/php5/cgi/php.ini
    4105 pts/2 R+ 0:00 grep php

    The bad news is that I still get the 502 Gateway error...
    • CommentAuthorSchultz
    • CommentTimeDec 27th 2008
     permalink
    you are running your php pool on port 10005 and in the nginx config you have it on port 9000. Change the nginx config to port 10005 and it should work.
    • CommentAuthorifthengoto
    • CommentTimeDec 27th 2008
     permalink
    Schultz - I changed the above vhost file to 10005 but unfortunately I get the same gateway 502 error...
    • CommentAuthorifthengoto
    • CommentTimeDec 27th 2008
     permalink
    Thank alpha and shultz,

    Got it working.

    First the init script was not starting automatically because I have not chmod +x it. Then I had to add it to the runlevels.

    Then I changed the /etc/default/php-fastcgi to run on 9000 which is the same as what was in my vhost file.

    Took me two days to get this far.
    • CommentAuthoralphagears
    • CommentTimeDec 28th 2008
     permalink
    Hey ifthengoto,

    Sorry I couldn't respond sooner. We traveled home today. Glad you got it working. Keep asking questions, that's the way I learned.
    • CommentAuthorjmstacey
    • CommentTimeDec 29th 2008
     permalink
    If you're using the php-fastcgi startup script on a debian based system, don't forget to add it with the update-rc.d command to make it start on a system reboot. I just learned that lesson the hard way.