centos7.2编译安装php7.2 nginx

    • 环境

    • 系统:Centos7.2 
    • 服务:Nginx

1:下载PHP7.0.2的安装包解压,编译,安装:

?

1

2

3

4

$ cd /usr/src/

$ wget http://cn2.php.net/distributions/php-7.0.2.tar.gz

$ tar -xzxvf php-7.0.2.tar.gz

$ cd php-7.0.2

1.1编译前检查

请检查是否安装了gcc ,没有的话执行yum install gcc

检查是否安装了libxml2 ,没有的话执行yum install libxml2

检查是否安装了libxml2-devel,没有的话执行yum install libxml2-devel

注:因为改为用nginx了,所以编译参数中的--with-apxs2=/usr/bin/apxs去掉了,如果要配置apache用,安装PHP前,请先安装apache。*

2:编译参数配置

复制代码代码如下:

./configure --prefix=/usr/local/php7.2 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl  --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr  --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu/ --enable-ftp --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --with-iconv --with-xpm-dir=/usr

 

3:错误集合

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

报错 Cannot find OpenSSL's <evp.h>

 执行 yum install openssl openssl-devel

报错 Please reinstall the libcurl distribution

 执行 yum -y install curl-devel

错误 jpeglib.h not found

 执行 yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y

 和执行 yum install libjpeg-devel

错误:checking for BZip2 in default path... not found configure: error: Please reinstall the BZip2 distribution 这是bzip2软件包没有安装

 执行 yum install bzip2-devel.x86_64 -y

错误:configure: error: xpm.h not found.

 执行 yum install libXpm-devel

错误: Unable to locate gmp.h

 执行 yum install gmp-devel

错误:Unable to detect ICU prefix or /usr//bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works

 执行 yum install -y icu libicu libicu-devel

错误:mcrypt.h not found. Please reinstall libmcrypt.

 执行 yum install php-mcrypt libmcrypt libmcrypt-devel

错误: configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

 执行 yum install postgresql-devel

错误: configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

 执行 yum install libxslt-devel

4:编译

?

1

make clean && make && make install

5:PHP配置

5.1安装完成后,我们要把源码包中的配置文件复制到PHP安装目录下,源码包中有两个配置 php.ini-development php.ini-production ,看名字就知道,一个是开发环境,一个是生产环境,我们这里就复制开发环境的

?

1

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

5.2另外还需要设置环境变量 :修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码

?

1

2

PATH=$PATH:/usr/local/php/bin

export PATH

5.3 然后执行生效命令

?

1

source /etc/profile

5.4查看PHP版本信息

?

1

php -v

6:配置PHP-fpm

?

1

2

3

4

5

6

7

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

cp /usr/src/php-7.0.2/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

6.1 启动php-fpm:

?

1

/etc/init.d/php-fpm start

6.2 如果出现错误:ERROR: [pool www] cannot get uid for user 'www-data'

则新建www-data 用户组:

?

1

2

groupadd www-data

useradd -g www-data www-data

6.3 重启php-fpm

?

1

/etc/init.d/php-fpm restart

安装所需环境

Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境。

一. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

yum install gcc-c++

二. PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:

yum install -y pcre pcre-devel

三. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

yum install -y zlib zlib-devel

四. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。

yum install -y openssl openssl-devel

官网下载

1.直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html

2.使用wget命令下载(推荐)。确保系统已经安装了wget,如果没有安装,执行 yum install wget 安装。

wget -c https://nginx.org/download/nginx-1.12.0.tar.gz

我下载的是1.12.0版本,这个是目前的稳定版。

解压

依然是直接命令:

tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0

配置

其实在 nginx-1.12.0 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。
1.使用默认配置

./configure

2.自定义配置(不推荐)

./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录

编译安装

make
make install

查找安装路径:

whereis nginx

启动、停止nginx

cd /usr/local/nginx/sbin/
./nginx 
./nginx -s stop
./nginx -s quit
./nginx -s reload

启动时报80端口被占用:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 

 解决办法:1、安装net-tool 包:yum install net-tools

 

./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。

查询nginx进程:

ps aux|grep nginx

重启 nginx

1.先停止再启动(推荐):
对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:

./nginx -s quit
./nginx

2.重新加载配置文件:
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload

启动成功后,在浏览器可以看到这样的页面:

nginx-welcome.png

开机自启动

即在rc.local增加启动代码就可以了。

vi /etc/rc.local

增加一行 /usr/local/nginx/sbin/nginx
设置执行权限:

chmod 755 rc.local

nginx-rclocal.png

猜你喜欢

转载自blog.csdn.net/zhaosiwenzhaosiwen/article/details/81207229
今日推荐