热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Linux系统下安装PHPcgi的的详细过程

一,什么是nginx,它有什么优点Nginx(enginex)是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Nginx是一个很牛的高性能Web和反向代理服务器,它具有有很多非常优越的特性:在高连接并发的情况下,Nginx是Apache服务器不错的替

一,什么是nginx,它有什么优点


Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。

Nginx 是一个很牛的高性能Web和反向代理服务器, 它具有有很多非常优越的特性:
在高连接并发的情况下,Nginx是Apache服务器不错的替代品: Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一. 能够支持高达 50,000 个并发连接数的响应, 感谢Nginx为我们选择了 epoll and kqueue作为开发模型.
Nginx作为负载均衡服务器: Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务, 也可以支持作为 HTTP代理服务器对外进行服务. Nginx采用C进行编写, 不论是系统资源开销还是CPU使用效率都比 Perlbal 要好很多.
作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器), Last.fm 描述了成功并且美妙的使用经验.
Nginx 是一个 安装非常的简单 , 配置文件 非常简洁(还能够支持perl语法), Bugs非常少的服务器: Nginx 启动特别容易, 并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动. 你还能够 不间断服务的情况下进行软件版本的升级.

二,安装所要软件

wget http://sysoev.ru/nginx/nginx-0.8.15.tar.gz

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz

wget http://museum.php.net/php5/php-5.2.6.tar.gz

三、安装PHP 5.2.6(FastCGI模式)

安装php的时候,需要安装支持php的一些库,不过一般情况,装好linux系统时,这些库基本上都装好,所以支持php安装的软件,就在这儿不说了。如果make && make install时提示出错时,你可以看一下缺少什么,你就装什么。

tar zxvf php-5.2.6.tar.gz
cd php-5.2.6/
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-zlib-dir --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-gd --enable-ftp --with-iconv --with-gettext --with-curl --enable-fastcgi --with-openssl

make && make install
cd /usr/local/php/lib
cp php.ini-dist php.ini

cp /usr/local/php/bin/php  /usr/bin/php-cgi

1,修改php.ini

nano php.ini  按f6然后输入extension_dir

查找/usr/local/php/etc/php.ini中的extension_dir = "./"
修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

2,启动php-cgi

/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -f /usr/bin/php-cgi

nginx配置文件中的  fastcgi_pass 127.0.0.1:9000; 就是根据上面来的

3,查看一下

[zhangy@BlackGhost www]$ ps -e|grep php-cgi
3737 ?        00:00:00 php-cgi
3738 ?        00:00:03 php-cgi
3739 ?        00:00:03 php-cgi
3740 ?        00:00:04 php-cgi
3741 ?        00:00:03 php-cgi
3742 ?        00:00:03 php-cgi

四,安装nginx

tar zxvf nginx-0.8.35.tar.gz
cd nginx-0.8.35/
./configure --user=zhangy --group=users --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre
make && make install

1,配置nginx.conf

nano /usr/local/nginx/conf/nginx.conf


user  zhangy users;

worker_processes 10;

error_log  /var/vlogs/nginx_error.log  crit;

pid        /var/vlogs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

events
{
  use epoll;
  worker_connections 65535;
}

http
{
  include       mime.types;
  default_type  application/octet-stream;

  #charset  gb2312;

  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;

  sendfile on;
  tcp_nopush     on;

  keepalive_timeout 60;

  tcp_nodelay on;

  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;

  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-Javascript text/css application/xml;
  gzip_vary on;

  #limit_zone  crawler  $binary_remote_addr  10m;

    upstream 127.0.0.1:1081  { server 127.0.0.1:1081; }
    upstream localhost:1080 { server 127.0.0.1:1080; }

  server
  {
    listen       10000;
    server_name  :10000;
    index index.html index.htm index.php;
    root  /home/zhangy/www/metbee/trunk/src/web;

    #limit_conn   crawler  20;

    location ~ .*\.(php|php5)?$
    {

         proxy_pass http://127.0.0.1:1081;
         break;

      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }

#     location /main {
#         proxy_pass http://fast_test;
#         break;
#     }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }

    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /var/log/metbee.log  access;
      }

  server
  {
    listen       80;
    server_name  :80;
    index index.html index.htm blog/index.php;
    root  /home/zhangy/www;

     location /test {

         proxy_pass http://localhost:1080;
         break;
     }

#   location ~ .*\.(php|php5|html)?$
# location ~ .*
#    {

if (!-e $request_filename){
        rewrite ^/tag/(.*) /blog/index.php?tag=$1 last;
        rewrite ^/page/(\d+)$  /blog/index.php?paged=$1 last;
        rewrite ^/(.*)/(\d+)\.html /blog/index.php?p=$2 last;
        rewrite ^/category/(.*) /blog/index.php?category_name=$1 last;
#       rewrite ^/date/([0-9]{4,4})/([0-9]{1,2})?$ /blog/index.php?year=$1&mOnthnum=$2&page=$3 last;
#       rewrite ^/date/([0-9]{4,4})/([0-9]{1,2})?$ /blog/index.php?m=$1$2 last;
    rewrite ^/newpage(\d+)$  /blog/index.php?page_id=$1 last;
    rewrite ^/feed$  /blog/index.php?feed=rss2 last;
    rewrite ^/comment/feed$  /blog/index.php?feed=comment-rss2 last;
        rewrite http://blog.51yip.com$ http://blog.51yip.com/blog/index.php redirect;
}

location ~ .*\.(php|php5)?$
   {
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }

    log_format  wwwlogs  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for';
    access_log  /var/log/wwwlogs.log  wwwlogs;
  }

  server
  {
    listen       10001;
    server_name  :10001;
    index index.html index.htm index.php;
    root  /mnt/song/fastfds2/data;

    location ~ .*\.(php|php5)?$
    {
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }

    log_format  imagelogs  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for';
    access_log  /var/log/imagelogs.log  imagelogs;
  }

  server
  {
    listen  11211;
    server_name :11211;

    location / {
    stub_status on;
    access_log   off;
    }
  }
}

2,fastcgi.conf

cd /usr/local/nginx/conf

nano /usr/local/nginx/conf/fastcgi.conf


fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

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_FILENAME    $document_root$fastcgi_script_name;
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  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;

3,优化linux内核参数

nano /etc/sysctl.conf

在末尾加上下面的东东

net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog =  32768
net.core.somaxcOnn= 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024  65535

4,启动nginx

ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx

5,查看启动

[zhangy@BlackGhost www]$ ps -e|grep nginx
4070 ?        00:00:00 nginx
4071 ?        00:00:00 nginx
4072 ?        00:00:00 nginx
4073 ?        00:00:00 nginx
4074 ?        00:00:00 nginx
4075 ?        00:00:00 nginx
4076 ?        00:00:00 nginx
4077 ?        00:00:00 nginx
4078 ?        00:00:00 nginx
4079 ?        00:00:00 nginx

五,开机启动

nano /etc/rc.local

ulimit -SHn 65535
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -f /usr/bin/php-cgi
/usr/local/nginx/sbin/nginx

nginx fastcgi

nginx fastcgi


推荐阅读
  • 构建LNMP架构平台
    LNMP架构的组成:Linux、Nginx、MySQL、PHP关于NginxNginx与apache的作用一样,都是为了搭建网站服务器,由俄罗斯人lgorsysoev开发,其特点是 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 负载均衡_Nginx反向代理动静分离负载均衡及rewrite隐藏路径详解(Nginx Apache MySQL Redis)–第二部分
    nginx反向代理、动静分离、负载均衡及rewrite隐藏路径详解 ... [详细]
  • Linux下部署Symfoy2对app/cache和app/logs目录的权限设置,symfoy2logs
    php教程|php手册xml文件php教程-php手册Linux下部署Symfoy2对appcache和applogs目录的权限设置,symfoy2logs黑色记事本源码,vsco ... [详细]
  • k8s+springboot+Eureka如何平滑上下线服务
    k8s+springboot+Eureka如何平滑上下线服务目录服务平滑上下线-k8s版本目录“上篇介绍了springboot+Euraka服务平滑上下线的方式,有部分小伙伴反馈k ... [详细]
  • Linux一键安装web环境全攻略
    摘自阿里云服务器官网,此处一键安装包下载:点此下载安装须知1、此安装包可在阿里云所有Linux系统上部署安装,此安装包包含的软件及版本为& ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • LVS实现负载均衡的原理LVS负载均衡负载均衡集群是LoadBalance集群。是一种将网络上的访问流量分布于各个节点,以降低服务器压力,更好的向客户端 ... [详细]
  • nginx+多个tomcat
    学习nginx的时候遇到的问题:nginx怎么部署两台tomcat?upstream在网上找的资源,我在nginx配置文件(nginx.conf)中添加了两个server。结果只显 ... [详细]
  • 有意向可以发简历到邮箱内推.简历直达组内Leader.能做同事的话,内推奖励全给你. ... [详细]
  • centos php部署到nginx 404_NodeJS项目部署到阿里云ECS服务器全程详解
    本文转载自:http:www.kovli.com20170919ecs-deploy作者:Kovli本文详细介绍如何部署NodeJS项目到阿里云ECS上, ... [详细]
author-avatar
逢源堂_344
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有