centos安装nginx和php7

php7发布了很久时间了,最近有空下载下来看看

nginx安装:nginx安装首先依赖几个库。分别为pcre,zlib,openssl分别下载这几个库,

有些库编译需要gcc,先安装gcc,yum install -y gcc gcc-c++

以zlib为例子 我下载是zlib-1.2.8.tar.gz,解压

#tar -zxvf zlib-1.2.8.tar.gz

#cd tar -zxvf zlib-1.2.8

# ./configure --prefix=/usr/local/zlib make make install 

#make && make install

其它两个一样./configure --prefix=/usr/local/zlib make make install    ./configure --prefix=/usr/local/openssl make make install

现在编译nginx,

# tar -zxvf nginx-1.11.3.tar.gz

#cd nginx-1.11.3

#./configure --prefix=/usr/local/nginx
--with-pcre=../pcre-8.37
--with-zlib=../zlib-1.2.8
--with-openssl=../openssl-fips-1.0.2d

后面带的库路径是表示这样库源码的路径,我下载的库都是放在同一个目录下,所以是同级关系

#make && make install

nginx安装就完成了,启动 /usr/local/nginx/sbin/nginx,浏览器点击127.0.0.1查看安装成功

php7安装:

下载php-7.0.10.tar.gz,

# tar -zxvf php-7.0.10.tar.gz  //解压

#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc  --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip

如果出现缺少什么库时,直接yum 安装如

yum -y install libxml2 libxml2-devel libxslt-devel ...

 

有时候出现错误

Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 153 M RSS (266 MB VSZ)
Started: Thu Jul 12 00:03:05 2012 - 06:17 ago
State : Sleeping, pid: 4018

直接rm -rf /var/run/yum.pid 强行解除锁定,yum就能用了

执行成功后编译

#make && make install

成功后需要复制配置文件php.ini 和php-fpm.conf www.conf

从源码包复制php.ini

# 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 www.conf.default www.conf   添加www.conf,这个文件是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

 



 

posted @ 2016-08-22 22:05  wil燦  阅读(8070)  评论(3编辑  收藏  举报