Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1663855
  • 博文数量: 631
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3920
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-06 21:58
个人简介

博客是我工作的好帮手,遇到困难就来博客找资料

文章分类

全部博文(631)

文章存档

2022年(2)

2021年(4)

2020年(40)

2019年(4)

2018年(78)

2017年(213)

2016年(41)

2015年(183)

2014年(66)

我的朋友

分类: 系统运维

2018-04-11 21:25:42


(1)配置环境
yum  -y install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurldevel curl curl-devel 


yum -y  install  gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel libpng-devel libjpeg-devel freetype freetype-devel pcre-devel libevent* libxml2*  


yum -y install  php-mcrypt  libmcrypt  libmcrypt-devel


(2)安装nginx
wget  


tar zxvf nginx-1.10.2.tar.gz


./configure --prefix=/usr/local/nginx --pid-path=/usr/local/nginx/nginx.pid --error-log-path=/usr/local/nginx/error.log --http-log-path=/usr/local/nginx/access.log --with-http_ssl_module --with-mail --with-mail_ssl_module --with-stream --with-threads --with-http_stub_status_module --with-http_ssl_module  


make & make install  


(3)安装php


wget  

tar -jxf mirror  


./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts   


make & make install 


# cp php.ini-development (或是 php.ini-production 用于服务器的,安全性较高) /usr/local/php/etc/php.ini

在执行文件时  加上 --with-config-file-path=/usr/local/php/etc 可以指定php.ini的位置 


# cd /usr/local/php/etc/  进入这个目录

# cp php-fpm.conf.default php-fpm.conf  添加php-fpm.conf 配置文件

# cd php-fpm.d  在进入这个目录


# cp   添加,这个文件是phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx的配置,ps:php5.X版本是直接在php-fpm.conf这个文件配置,没有这个文件的


进入php-fpm.conf 这个文件把 ;pid = run/php-fpm.pid 前面的;去掉,我编译php5版本是,发现启动php没有php-fpm.pid这个文件,导致不能重启,后面发现把这个打开,启动就能生成php-fpm.pid这个文件了


启动php


#/usr/local/php/sbin/php-fpm


配置nginx


进入nginx.conf ,在 /usr/local/nginx/conf/nginx.conf中


location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}


把这行注释去掉 fastcgi_param SCRIPT_FILENAME \script$fastcgi_script_name;改成fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


重启nginx :/usr/local/nginx/sbin/nginx -s reload


安装完成


php-fpm信号控制启动重启等状态


SIGINT, SIGTERM 立刻终止
SIGQUIT 平滑终止
SIGUSR1 重新打开日志文件
SIGUSR2 平滑重载所有worker进程并重新载入配置和二进制模块


php重启:kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`


停止 : kill -SIGINT php-fpm.pid



复制php-fpm文件到php安装目录


# cp -R ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf

拷贝php.ini文件 
安装目录有2个文件:php.ini-development和php.ini-production 
注意php.ini-production拥有较高的安全性设定,则适合上线当产品使用


# cp php.ini-development /usr/local/php/lib/php.ini

或者


# cp php.ini-production /usr/local/php/lib/php.ini

如果操作了这一步以后使用phpinfo()就会看到Loaded Configuration File: 



php-fpm启动 
拷贝启用文件

#  cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm

启动

#  /etc/init.d/php-fpm


php安装成功 
重启


# killall php-fpm
#  /etc/init.d/php-fpm




配置nginx支持PHP 

nginx的配置文件nginx.conf在

# cd /usr/local/nginx/conf

nginx默认web文件夹在 
/usr/local/nginx/html 
如果需要nginx支持PHP需要修改nginx.conf

每次修改完Nginx,都需要重启服务。

# /usr/local/nginx/sbin/nginx -s reload

打开本地显示此页面,则配置成功。 



 1、编辑php.ini
               vim /usr/local/php/php.ini
              定位到 cgi.fix_pathinfo= 并将其修改为: cgi.fix_pathinfo=0


          2、编辑php-fpm.conf,确保 php-fpm 模块使用www用户和 www组的身份运行。 
              vim /usr/local/php/etc/php-fpm.conf
               找到以下内容并修改: 


 找到以下内容:
                      ;pid = run/php-fpm.pid
               将前面的“;”去掉





 3、配置 Nginx 使其支持 PHP 应用: 


               vim /usr/local/nginx/conf/nginx.conf


               (1) 修改默认的 location 块,使其支持 .php 文件: 


location / {  
root /home/www;  
index index.php index.html index.htm;  
}  
              (2) 下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:




location ~* \.(php|php5)?$ {  
root /home/www;  
fastcgi_index index.php;  
fastcgi_pass 127.0.0.1:9000;  
include fcgi.conf;  
}  





错误1:


安装包:php-5.6.20.tar.bz2


编译成功完成,结果在make的时候报错


libtool: link: `ext/opcache/ZendAccelerator.lo' is not a valid libtool object


解决办法:


# make distclean


重新编译,make,通过


错误2:


启动php-fpm时报错:


Starting php-fpm [22-May-2017 11:18:29] ERROR: [pool www] cannot get uid for user 'nginx'


意思是没有nginx用户,添加就好了

# useradd nginx





错误3:


配置好php和nginx之后,访问index.php时一片空白






解决办法:


        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;                                          
        }


阅读(826) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~