Centos7.6上手动编译安装 Nginx1.16 和 php7.2

尽管市面上有很多Linux + Nginx + Mysql + PHP 的一健安装包,但在生产环境下,还是最好自己动手去编译。

安装依赖

yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel

下载 Nginx

cd /usr/local/src/
wget -cO nginx-1.16.0.tar.gz https://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0/

创建用户和组

groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M

配置编译选项

./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_mp4_module  \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre

编译安装

make && make install

启动 Nginx

/usr/local/nginx/sbin/nginx            # 启动
/usr/local/nginx/sbin/nginx -s reload  # 重启
/usr/local/nginx/sbin/nginx -s stop    # 停止

注意:启动时,如果 mkdir /var/tmp/nginx/client 报错,请手动创建改目录结构。mkdir /var/tmp/nginx/client -p

测试 Nginx 服务器

直接在浏览器访问服务器的 IP 地址,如果能看到 Welcome to nginx! 页面,说明安装成功,否则检查一下服务器防火墙。
在服务器上可以用 curl -I 127.0.0.1 检查,如果能看到 HTTP 的头部信息,基本可以确定是防火墙的问题。

[root@ecs-4895 nginx-1.16.0]# curl -I localhost
HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Thu, 30 May 2019 04:44:03 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 30 May 2019 04:17:17 GMT
Connection: keep-alive
ETag: "5cef594d-264"
Accept-Ranges: bytes

[root@ecs-4895 nginx-1.16.0]# 

 

 

编译 PHP7.2

php 已经集成了 php-fpm,不需要单独安装。

安装依赖

yum install -y autoconf libtool libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxslt libxslt-devel bzip2 bzip2-devel glibc glibc-devel libzip libzip-devel
yum install -y glib2 glib2-devel ncurses ncurses-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel bison bison-devel libmcrypt-devel mcrypt mhash-devel libcurl-devel readline-devel libedit-devel sqlite-devel libidn libidn-devel libicu-devel

创建用户和组 

groupadd www
useradd -g www www

下载 PHP7.2.8

下载地址:
链接: https://pan.baidu.com/s/1mzX5AqgXootZbVD8P-7scg 提取码: 9fz7

文件校验:
php7.1: bdd0e1707100c8b87f1be516f5b95a26e3eb4114d4316eaf0663bf292ead35bb
php7.2: 48aeb291814f3cd3ba03c52e79e8e61896d0271fd4c228198f80a072e568f84b
php7.3: c953749b7f3310a3a74f920ef698f6d1c04636d11656ac9ffb3ab10d34e30e1e

配置编译选项

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-config-file-scan-dir=/usr/local/php/conf.d \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libzip \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--enable-pcntl \
--enable-ftp \
--with-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-xsl

常见错误:

  1. configure: error: system libzip must be upgraded to version >= 0.11
  2. configure: error: Please reinstall the libzip distribution
  3. configure: error: off_t undefined; check your library configuration
  4. fatal error: zipconf.h: No such file or directory

解决方法:

  1. 升级 libzip
  2. 重新安装 libzip
  3. 添加检索位置配置
  4. 此错误建议在 make 前先处理,如下:
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

详见 https://blog.qzze.com/820.html

编译安装

make && make install

 

你可能感兴趣的:(Centos)