安装PHP5 (FastCgi模式)

1 安装语句

apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

2打开/etc/php5/cgi/php.ini 配置文件,在最后一行添加cgi.fix_pathinfo = 1

vi /etc/php5/cgi/php.ini

 [...]

cgi.fix_pathinfo = 1

3 Ubuntu没有独立的FastCGI安装包,所以用lighttpd里面的spawn-fcgi,运行下面命令:

apt-get install lighttpd

安装完成时会出现lighttpd无法启动的错误,因为nginx占用了80端口。运行update-rc.d -f lighttpd remove使lighttpd开机不启动。

我们安装lighttpd只需要其中的/usr/bin/spawn-fcgi,来运行FastCGI进程。运行

spawn-fcgi --help

查看它的命令帮助。

以用户www-data在本机localhost9000端口下运行一个PHP FastCGI进程,输入以下命令

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

加入开机运行,以免每次开机运行此命令。

vi /etc/rc.local

在最后一行加入下面语句(在exit前面)。

[...]

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

[...]

4 查看fastcgi运行情况

netstat -naop |grep ":9000"

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      13168/php5-cgi   off (0.00/0/0)

5 修改Nginx的配置文件,以支持Fastcgi

Nginx采用Nginx LB以及反向代理服务器,后端接多个Nginx WEB服务器,数据库服务器单独使用。本文档中NginxLB以及反向代理服务器使用IP(VIP:192.168.9.123 IP:192.168.9.124) ,后端使用了一台WEB服务器(IP:192.168.9.126) ,

 注:红色部分是使用Nginxproxy以及LB的配置,源数据和Proxy在同一台机器下使用红色部分,源数据(只使用NginxWEB功能)只使用非红色部分即可。

user  www-data;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

 

#pid        logs/nginx.pid;

events {

    use epoll;

    worker_connections  51200;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

 

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

 

    #access_log  logs/access.log  main;

 

    sendfile        on;

    tcp_nopush     on;

 

    #keepalive_timeout  0;

    keepalive_timeout  120;

    fastcgi_connect_timeout 300;

    fastcgi_send_timeout 300;

    fastcgi_read_timeout 300;

    fastcgi_buffer_size 64k;

    fastcgi_buffers 4 64k;

    fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

 

    client_header_buffer_size 256K;

    open_file_cache max=60000  inactive=20s;

    open_file_cache_valid 32s;

    open_file_cache_min_uses 1;

    #size limits

         client_max_body_size             50m;

         client_body_buffer_size        256k;

         client_header_timeout     3m;

         client_body_timeout 3m;

         send_timeout             3m;

  

    # upstream

        upstream 192.168.9.123 {

                 server 192.168.9.124:80 weight=2 ;

                 server 192.168.9.126:80 weight=5 ;

            }

    #gzip  on;

    server {

        listen       192.168.9.123:80;

        server_name  192.168.9.123;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   /var/www/owa;

            index   index.php  index.html index.htm;

        }

 

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        # 这样配置只对此根目录下的PHP文件起到反向代理作用。

        location ~ \.php$ {

           

             proxy_redirect off ;

             proxy_set_header Host $host;

             proxy_set_header X-Real-IP $remote_addr;

             proxy_set_header REMOTE-HOST $remote_addr;

             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

             client_max_body_size 50m;

             client_body_buffer_size 256k;

             proxy_connect_timeout 30;

             proxy_send_timeout 30;

             proxy_read_timeout 60;

             proxy_buffer_size 256k;

             proxy_buffers 4 256k;

             proxy_busy_buffers_size 256k;

             proxy_temp_file_write_size 256k;

             proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;

             proxy_max_temp_file_size 128m;

             proxy_pass   http://192.168.9.123;

        }

    

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php$ {

            root           /var/www/owa;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /var/www/owa$fastcgi_script_name;

            include        fastcgi_params;

        }

 

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen       443;

    #    server_name  localhost;

    #    ssl                  on;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers   on;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

#}

 server {

        listen     192.168.9.124:80; #在源数据(NginxWeb功能中,只保留端口就可以)

        server_name  192.168.9.124;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   /var/www/owa;

            index   index.php  index.html index.htm;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        

        #}

 

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php$ {

            root           /var/www/owa;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /var/www/owa$fastcgi_script_name;

            include        fastcgi_params;

        }

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

 

 

    # HTTPS server

    #

    #server {

    #    listen       443;

    #    server_name  localhost;

    #    ssl                  on;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers   on;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

}

注:测试LB功能,分别在Nginx代理服务器和NginxWEB服务器的/var/www/owa目录下建立test.php文件,内容:

<html>

 <head>

  <title>PHP </title>

 </head>

 <body>

 <?php echo '<p>Hello World 124</p>'; ?>

 </body>

</html>

以及

<html>

 <head>

  <title>PHP </title>

 </head>

 <body>

 <?php echo '<p>Hello World 126</p>'; ?>

 </body>

</html>

然后在浏览器端访问http://192.168.9.123 F5刷新,可以看到负载均衡PHP的效果。

PS:

Nginx代理服务器与Nginx WEB服务器在一台机器上,一个网卡上配置双IP的例子:

Ubuntu下单网卡多IP地址的配置

[1]删除用户默认配置文件

由于在默认清空下,配置文件是系统自动生成的用户设备配置文件保存在

/etc/udev/rule.d/下面

#cp /etc/udev/rule.d /etc/udev/rule.d.bak.0 -R

# rm /etc/udev/rule.d/*

[2]修改网卡配置文件,添加多IP配置

#vim /etc/network/interfaces

为如下内容

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

address 192.168.9.123

netmask 255.255.255.0

gateway 192.168.9.1

auto eth0:0

iface eth0:0 inet static

address 192.168.9.124

netmask 255.255.255.0

gateway 192.168.9.1

[3]让配置生效

#/etc/init.d/networking restart

 

6 在默认目录/var/www/建立PHP文件info.php

vi /var/www/info.php

<?php

phpinfo();

?>

查看Server API 会看到PHP通过FastCGI运行,支持MySQL

四、部署OpenWebAnalytics

1 下载地址

http://downloads.openwebanalytics.com/owa/owa_1_5_0rc3.tar

2 安装要求

  技术要求

Server Operating System

 

OWA should run fine under both UNIX and most Windows operating systems. However, more extensive testing has been done on UNIX operating systems.

PHP

 

OWA requires PHP 5.2.x or later.

Required php.ini Directives

Certain PHP configuration settings create problems for OWA installations. The following is a list of INI settings that should be avoided:

safe mode directive must be set to "off'.

Required PHP Extensions

The PCNTL extension is required only if you plan to utilize OWA's background processing daemon (optional). Since PCNTL comes with the PHP distribution you just have to compile your PHP with the --enable-pcntl directive. See http://www.php.net/manual/en/pcntl.installation.php for more info on how to install the PCNTL extension.

Database

 

OWA requires MySQL 4.1 or later.

At this time, OWA requires that MySQL's "strict mode" be disabled.

Web Browsers

 

OWA supports all major versions of most web browsers including Opera, Safari, Firefox, Chrome and Internet Explorer. Certain OWA visualizations require Firefox 3.5 or later.

WordPress

 

OWA's WordPress plugin requires WordPress version 2.8 or later.

MediaWiki

 

OWA's MediaWiki plugin requires MediaWiki v1.15.x or later.

权限要求

Base Directory (/path/to/owa)

The files and directories within OWA's base directory (/path/to/owa) requires read, write and execute permissions for your user account.

On a Unix server the most likely permission mode is 0750. However, depending on your web server/php setup a more permissive mode of 0755 may required.

If your web server or cgi process runs under a different user account, then read, write, and execute permissions are also required for the group that the web server user account belongs to. Group Write privileges for the base directory can be revoked once installation is complete or even before installation if you are willing to create your owa-config.php file manually. However, write privileges must remain in effect for OWA's data directory (see below).

Data Directory (path/to/owa/owa-data)

 

The files and directories within OWA's data directory (/path/to/owa/owa-data) requires read and write permissions for whatever user account your web server or cgi process is running under.

NOTE: If your web server or cgi process is not running as your user account then you will need to assign and grant write permissions to a group that includes the user account that the web server/cgi runs under.

Configuration File (owa-config.php)

 

OWA's configuration file owa-config.php must be readable by the user account that your webserver/cgi runs under.

NOTE: if you are running OWA under on a server shared by other users you should change the permissions of your owa-config.php file to mode 0750 (or even 0700) so that it is not readable by other users.

Command Line Interface (cli.php)

 

OWA's command line interface script cli.php should be readable and executable only by your user account. Change the permission mode of this file to 0700 to prevent unauthorized access to the CLI in shared server environments.

3 安装步骤

解压缩文件

 tar –xf owa_1_5_0rc3.tar

属主、权限赋予

Chmod –R 755 owa

Chown –R www-data:www-data owa

Chmod 755 owa/owa-config-dist.php

Chmod –R 755 conf includes modules owa-data plugins

修改相应配置文件

Mv owa/owa-config-dist.php owa/owa-config.php

Vi  owa-config.php 配置相关数据库信息,

define('OWA_PUBLIC_URL', 'http://192.168.9.123/');# 这行要填写Nginx代理服务器的IP信息,其他WEB服务器都填这个,以起到负载均衡的作用。

进行安装

访问  http://192.168.9.123/install.php  进行安装