写这个是因为博主在部署新网站的时候遇到的坑爹的问题

  服务器已经有了环境:LNMP,也有网站在跑,这个是php5.5

  坑爹的是,有个新网站要部署,按照惯例,nginx.conf中添加server,重启nginx却发现新网站跑不起来

  查看error_log报的是[error] 18850#0: *2956 directory index of "/data/web/***/upload/" is forbidden

  于是博主就各种搜,各种试,结果都不行,博主当时就想,也太坑爹了吧,于是跟客户商量着“要不咱重做系统?重新部署环境?”,客户讲“我服务器上有***、***、***,你都得给我重装上”。得,这你大爷的我咋知道你跑的什么玩意(博主算是技术小白)。

  于是本地搭了个环境,把客户的老网站部署到本地测试,结果,呵呵,没跑起来,于是博主又是一通嗖嗖嗖,调试了一通,没有搞出个所以然。博主就对客户说了,咱学艺不精,您还是另请高明吧!!!谁承想,这货通过手段找到了领导,领导讲“***,这个客户由**1、**2,协助处理下”,这不坑爹吗,那俩哥们都是不动手的主,活又打到我手里了,这时小领导问“客户什么环境”,我“LNMP”,“PHP什么版本”,“PHP5.5”,“我司网站php5.5运行不了,给他部署多版本php共存吧”,我“。。。”,真是如梦初醒,醍醐灌顶。宝宝心里苦,宝宝不会。然鹅,博主想了下,成。

  吐槽结束 

  正文开始。。。

  新网站所需为php5.2或5.3

  php5.5和mysql都是编译安装的,路径都在/usr/local目录下,如果采用yum安装的话是安装到/etc目录的,所以方案是可行的

  yum install php-fpm,版本是5.3的,成了,不过如果php-fpm默认端口是9000,已经有一个php-fpm在运行了,如果还要运行另外一个,那么新安装的php-fpm就需要给他修改下端口

  vim /etc/php-fpm.d/***.conf

  listen = 127.0.0.1:9000    修改为

  listen = 127.0.0.1:9001

  :wq

  service php-fpm restart    重启新安装的php-fpm(原先的php-fpm没有此命令,所以不担心会冲突)

  做个探针检查下环境

  在新网站目录里

  vim test.php

  <?php

    phpinfo();

  ?>

  :wq

  浏览器里面打开这个文件,显示如下:

  LNMP环境多版本php共存_环境

  说明php安装正确

  但是网站依然无法打开,/etc/php.ini中short_open_tag = 0 重启php-fpm依然打不开

  netstat -ntpl查看php-fpm运行正常

 LNMP环境多版本php共存_LNMP_02

  检查探针中,发现没有mysql,说明新安装的php-fpm没有跟mysql通信

  检查下有什么没有安装的包吗?

  只安装了一个php-fpm肯定是不行的,要再安装一些相关包

  yum install php-mysql php-mbstring php-mcrypt php-pdo

  安装完成重启php-fpm

  网站依然打不开,探针里面一言没有mysql,宝宝心里好捉急

  新安装的php-fpm还是不能跟mysql通信

  vim /etc/php.ini

  ...

  [MySQL]

  ...

  mysql.default_socket =    修改为

  mysql.default_socket = /tmp/mysql.sock    

  :wq

  重启php-fpm

  网站可以正常打开了!!!

  总结,该问题困扰了几天,终于搞好了!1、方法总比困难多;2、你身边需要有个一语惊醒梦中人的人;3、工作干不好会被扣工资的

   以上忽略了mysql的相关内容,数据库的配置,数据库导入等,

   

  另附nginx.conf的内容

   注:第一个server中的fastcgi_pass和第二个、第三个的端口不同,第一个是php-fpm5.5,第二、三个是php-fpm5.3的

    环境没做特殊变更,客户的东西能少动就少动


#user   www;  ## Default: nobody

worker_processes  1;  ## Default: 1


error_log  logs/error.log;

error_log  logs/error.log  notice;

error_log  logs/error.log  info;


pid        logs/nginx.pid;

worker_rlimit_nofile 8192;


events {

  worker_connections  4096;  ## Default: 1024

}


http {

   include       mime.types;

    default_type  application/octet-stream;

    access_log   off;

    sendfile        on;

    keepalive_timeout  65;

    server_tokens off;

    fastcgi_intercept_errors on;

    client_header_timeout 10;

    client_body_timeout 10;

    reset_timedout_connection on;

    send_timeout 10;

    client_header_buffer_size 32k;

    large_client_header_buffers 1 128k;

    client_max_body_size 8m;

    gzip on;

    gzip_buffers 32 4k;

    gzip_comp_level 9;

    gzip_http_version 1.1;

    gzip_min_length 1k;

    gzip_proxied expired no-cache no-store private auth;

    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php p_w_picpath/jpeg p_w_picpath/gif p_w_picpath/png p_w_picpath/jpg;

    gzip_vary on;

    gzip_disable "MSIE [1-6]\.";

    log_format wwwlogs '$remote_addr $upstream_addr - - $time_iso8601 "$request_method $scheme://$host$request_uri $server_protocol" $request_time $upstream_response_time $status $upstream_status $bytes_sent $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_cache_status:TCP';


#################################################################################


index index.html index.php default.php index.htm;

server {

  listen 80;

    root /data/***/***1;

    error_page 404 /404.html;

    server_name  ***1.com;

    location / {

        allow all;

        try_files $uri $uri/ /index.php/$request_uri;

    }

    location ~ (index)?\.php($|/) {

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        fastcgi_param PATH_INFO $fastcgi_path_info;

        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

    }

}

#################################################################################


index index.html index.php default.php index.htm;

server {

    listen 80;

    root /data/***/***2;

    error_page 404 /404.html;

    server_name  ***2.com ;

#    location / {

#        allow all;

#        try_files $uri $uri/ /index.php/$request_uri;

#    }  

#    location ~ (index)?\.php($|/) { 


    location = /favicon.ico {

        log_not_found off;

        access_log off;

    }


    location ~ \.php$ {

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass 127.0.0.1:9001;

        fastcgi_index index.php;

        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

#        fastcgi_param PATH_INFO $fastcgi_path_info;

#        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 

    }

}

#################################################################################

index index.html index.php default.php index.htm;

server {

    listen 80;

    root /data/***/***3;

    error_page 404 /404.html;

    server_name   ***3.com;

#    location / {

#        allow all;

#        try_files $uri $uri/ /index.php/$request_uri;

#        try_files $uri /index.php;

#    }  

    location = /favicon.ico {

        log_not_found off;

        access_log off;

    }


    location ~ \.php$ {

#    location ~ (index)?\.php($|/) { 

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass 127.0.0.1:9001;

        fastcgi_index index.php;

        include fastcgi_params;

#        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

#        fastcgi_param PATH_INFO $fastcgi_path_info; 

#        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 

    }

}

#################################################################################


}