nginx php 源码安装,Nginx1.12.2加php7.2.0的编译安装
发布日期:2021-06-24 13:24:29 浏览次数:4 分类:技术文章

本文共 7460 字,大约阅读时间需要 24 分钟。

前言:

安装系统环境CentOS 6.8mini,用RPM安装了MySQL 5.7.20,接下来用tar源码包安装Nginx-1.12.2和PHP7.2.0,目前使用的都是最新的软件版本

1.下载安装包[root@XiaoFeng opt]# wget http://cn2.php.net/distributions/php-7.2.0.tar.gz

[root@XiaoFeng opt]# wget http://nginx.org/download/nginx-1.12.2.tar.gz

2.安装依赖包[root@XiaoFeng opt]# yum install -y gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel

[root@XiaoFeng opt]# tar -zxvf nginx-1.12.2.tar.gz

[root@XiaoFeng opt]# cd nginx-1.12.2

[root@XiaoFeng nginx-1.12.2]# useradd -s /sbin/nologin nginx  #创建Nginx运行用户和组

3.编译配置[root@XiaoFeng nginx-1.12.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-http_realip_module

[root@XiaoFeng nginx-1.12.2]# make && make install

[root@XiaoFeng nginx-1.12.2]# cd /usr/local/nginx/sbin

[root@XiaoFeng sbin]# ./nginx              //启动Nginx

[root@XiaoFeng sbin]# ./nginx -t         //验证配置文件是正确

[root@XiaoFeng sbin]# ./nginx -s reload  //重启Nginx

[root@XiaoFeng sbin]# ./nginx -s stop         //停止Nginx

参数说明:

nginx大部分常用模块,编译时./configure --help以--without开头的都默认安装。

--prefix=PATH : 指定nginx的安装目录。默认 /usr/local/nginx

--conf-path=PATH : 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf

--user=name: 设置nginx工作进程的用户。安装完成后,可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。--group=name类似

--with-http_v2_module  :支持http_v2协议

--with-pcre : 设置PCRE库的源码路径,如果已通过yum方式安装,使用--with-pcre自动找到库文件。使用--with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 - 8.30)并解压,剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。

--with-zlib=PATH : 指定 zlib(版本1.1.3 - 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。

--with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装

--with-http_stub_status_module : 用来监控 Nginx 的当前状态

--with-http_gzip_static_module :是针对nginx serve的静态文件,需要编译进去才能有。压缩效果更好的算法事先压好.gz文件

--with-http_realip_module : 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意义在于能够使得后台服务器记录原始客户端的IP地址

--add-module=PATH : 添加第三方外部模块,如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译(Tengine可以在新加入module时无需重新编译)

4.配置Nginx命令和服务并开机启动[root@XiaoFeng sbin]# vim /etc/init.d/nginx

复制一下代码到上面的文件#!/bin/sh

#

# nginx - this script starts and stops the nginx daemon

#

# chkconfig: - 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse \

#proxy and IMAP/POP3 proxy server

# processname: nginx

# config: /etc/nginx/nginx.conf

# config: /etc/sysconfig/nginx

# pidfile: /var/run/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

echo -n $"Starting $prog: "

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

killall nginx -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

killall -9 nginx

}

restart() {

configtest || return $?

stop

sleep 1

start

}

reload() {

configtest || return $?

echo -n $"Reloading $prog: "

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

case "$1" in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac

添加执行权限[root@XiaoFeng sbin]# chmod 755 /etc/init.d/nginx

[root@XiaoFeng sbin]# service nginx start

给网站目录添加权限[root@XiaoFeng sbin]# chown -R nginx:nginx ../html

[root@XiaoFeng sbin]# chmod 755 ../html

如果想让它开机启动,执行[root@XiaoFeng sbin]# chkconfig nginx on

查看是否开机启动:[root@XiaoFeng sbin]# chkconfig --list nginx

nginx          0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭

5.安装PHP7.2.0

安装依赖包[root@XiaoFeng opt]# yum install -y curl curl-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel php-mcrypt libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib

[root@XiaoFeng opt]# tar -zxvf php-7.2.0.tar.gz

[root@XiaoFeng opt]# cd php-7.2.0

[root@XiaoFeng php-7.2.0]#

创建运行的用户[root@XiaoFeng php-7.2.0]# useradd -s /sbin/nologin php-fpm  #创建php-fpm运行用户和组

编译配置./configure \

--prefix=/usr/local/php \

--exec-prefix=/usr/local/php \

--bindir=/usr/local/php/bin \

--sbindir=/usr/local/php/sbin \

--with-libdir=/usr/lib64 \

--enable-fpm \

--with-fpm-user=php-fpm \

--with-fpm-group=php-fpm \

--with-config-file-path=/etc \

--with-libxml-dir \

--with-openssl \

--with-mysqli \

--with-zlib \

--enable-bcmath \

--with-bz2 \

--enable-calendar \

--with-curl \

--enable-exif \

--with-pcre-dir \

--enable-ftp \

--with-openssl-dir \

--with-gd \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--enable-gd-jis-conv \

--with-gettext \

--with-gmp \

--with-mhash \

--enable-mbstring \

--with-libmbfl \

--with-onig \

--with-pdo-mysql \

--with-readline \

--enable-shmop \

--enable-soap \

--enable-sockets \

--enable-sysvmsg \

--enable-sysvsem \

--enable-sysvshm \

--enable-wddx \

--with-xmlrpc \

--with-xsl \

--enable-zip \

--with-pear \

--enable-mysqlnd \

--enable-shared \

--enable-inline-optimization \

--disable-debug \

--enable-xml \

--with-sqlite3 \

--with-iconv \

--with-cdb \

--enable-dom \

--enable-fileinfo \

--enable-filter \

--enable-json \

--enable-mbregex \

--enable-mbregex-backtrack \

--enable-pdo \

--with-pdo-sqlite \

--enable-session \

--enable-simplexml \

--enable-opcache

安装[root@XiaoFeng php-7.2.0]# make && make install

[root@XiaoFeng php-7.2.0]# cp /opt/php-7.2.0/php.ini-development /etc/php.ini

[root@XiaoFeng php-7.2.0]# cd /usr/local/php/etc/

[root@XiaoFeng etc]# cp php-fpm.conf.default php-fpm.conf

[root@XiaoFeng etc]# cp php-fpm.d/www.conf.default  php-fpm.d/www.conf

检验配置是否正确的方法为:

[root@XiaoFeng etc]# /usr/local/php/sbin/php-fpm -t

[04-Jan-2018 22:13:58] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful

启动php-fpm[root@XiaoFeng etc]# cp /opt/php-7.2.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@XiaoFeng etc]# chmod 755 /etc/init.d/php-fpm

[root@XiaoFeng etc]# service php-fpm start

Starting php-fpm  done

让它开机启动,执行:

[root@XiaoFeng etc]# chkconfig php-fpm on

[root@XiaoFeng etc]# chkconfig --list php-fpm

php-fpm        0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭

检测是否启动:

[root@XiaoFeng etc]# ps aux |grep php-fpm

PHP已经安装完了,接下来要配置nginx来支持php[root@XiaoFeng etc]# cd /usr/local/nginx/conf

[root@XiaoFeng conf]# vim nginx.conf

第一行是空的,就在第一行添加user nginx; 运行nginx的用户为nginx

第45行,设置默认访问的首页文件,添加index.php

第65行到71行,去掉注释,第69行中的/scripts 改成$document_root

代码如下:65         location ~ \.php$ {

66             root           html;

67             fastcgi_pass   127.0.0.1:9000;

68             fastcgi_index  index.php;

69             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

70             include        fastcgi_params;

71         }

在网站目录下写个php页面测试下[root@XiaoFeng conf]# vim ../html/index.php<?php

echo phpinfo();

重启nginx[root@XiaoFeng conf]# /usr/local/nginx/sbin/nginx  -s reload

打开浏览器看到PHP Version 7.2.0页面就完成了

5db658f23978248888c84ce838a8a445.png

转载地址:https://blog.csdn.net/weixin_33137081/article/details/115154339 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:php 删除字节,php – 删除无效/不完整的多字节字符
下一篇:hanlp java api_java分词工具hanlp介绍

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月18日 03时27分04秒