php7 nginx 配置

nginx的编译安装

编译环境

$ yum -y install gcc gcc-c++ autoconf automake libtool make cmake
$ yum -y install zlib zlib-devel openssl openssl-devel pcre-devel

pcre: 为支持地址重写rewrite功能

创建用来运行nginx的用户及组

我们创建一个新的用户和用户组来运行nginx,这样可以把nginx和root分开,保证nginx不具备root权限。但是,我们并不希望nginx成为一个真实的可以登陆到远程进行操作的用户,所以,我们并不给它创建家目录,在useradd的时候,用-M参数:

$ groupadd nginx
$ useradd -g nginx -M nginx

但通过上面的用户创建之后,nginx用户可以通过设置一个密码登陆到服务器,这个不是我们想要的,我们禁用它的ssh登陆权限.禁止用户登陆也很方便,只需要修改配置文件中有关用户和用户组的信息即可。

$ vi /etc/passwd

找到nginx,将后面的/bin/bash改为/sbin/nologin即可。

OK,用户处理完毕。

编译安装Nginx

$ wget http://xxxxxxxxxx/nginx1.7.x.tar.gz
$ tar zxvf nginx1.7.x.tar.gz
$ cd nginx1.7.x

最终的./configure配置如下:

$ ./configure --prefix=/usr/local/nginx 
--pid-path=/usr/local/nginx/run/nginx.pid 
--with-http_ssl_module 
--user=nginx 
 --group=nginx 
--with-pcre 
--without-mail_pop3_module 
--without-mail_imap_module 
--without-mail_smtp_module

如果没报错,则执行如下编译安装:

$ make
$ make install
$ cd /usr/local/nginx
$ ls
$ sbin/nginx

nginx服务的载入

$ /usr/local/nginx/sbin/nginx -s reload
$ chmod +x /etc/init.d/nginx 
$ chkconfig --add nginx
$ chkconfig nginx on

PHP7的编译安装

依赖环境

$ yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel

编译安装php7

$ wget http://am1.php.net/get/php-7.0.0.tar.gz/from/this/mirror
$ tar zvxf php-7.0.0.tar.gz
$ cd php-7.0.0
$ ./configure --prefix=/usr/local/php7 
--with-config-file-path=/usr/local/php7/etc 
--with-config-file-scan-dir=/usr/local/php7/etc/php.d 
--with-mcrypt=/usr/include 
--enable-mysqlnd 
--with-mysqli 
--with-pdo-mysql 
--enable-fpm 
--with-fpm-user=nginx 
--with-fpm-group=nginx 
--with-gd 
--with-iconv 
--with-zlib 
--enable-xml 
--enable-shmop 
--enable-sysvsem 
--enable-inline-optimization 
--enable-mbregex 
--enable-mbstring 
--enable-ftp 
--enable-gd-native-ttf 
--with-openssl 
--enable-pcntl 
--enable-sockets 
--with-xmlrpc 
--enable-zip 
--enable-soap 
--without-pear 
--with-gettext 
--enable-session 
--with-curl 
--with-jpeg-dir 
--with-freetype-dir 
--enable-opcache
$ make
$ make install
$ cd /usr/src/php-7.0.0/
$ ls

$ cp php.ini-production /usr/local/php7/etc/php.ini
$ vi /usr/local/php7/etc/php.ini

启用php-fpm服务

搞定配置文件:

$ cd /usr/local/php7/etc
$ mv php-fpm.conf.default php-fpm.conf
$ mv php-fpm.d/www.conf.default php-fpm.d/www.conf

搞定php-fpm的服务载入:

$ cd /usr/src/php-7.0.0/sapi/fpm
$ ls
$ cp init.d.php-fpm /etc/init.d/php-fpm
$ chmod +x /etc/init.d/php-fpm
$ chkconfig --add php-fpm
$ chkconfig php-fpm on

nginx代理php实现访问

$ vi /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;
}
$ service nginx reload

在根目录下写个php文档测试一把

结束

转自:编译安装nginx1.9.7+php7.0.0服务器环境

原文地址:https://www.cnblogs.com/kravis/p/5710693.html