Centos7 安装nginx+php7

3 篇文章 0 订阅

1. 获取软件包


wget http://nginx.org/download/nginx-1.14.2.tar.gz

wget https://www.php.net/distributions/php-7.3.4.tar.gz

 

2. 安装nginx

添加用户

useradd -s /sbin/nologin -M nginx

 yum安装nginx所需的扩展

  yum install openssl  openssl-devel  pcre pcre-devel

  tar -zxvf  nginx-1.14.2.tar.gz

  cd nginx-1.14.2

   ./configure --user=nginx \
    --group=nginx \
    --prefix=/usr/local/nginx \
    --with-http_stub_status_module \
    --with-http_ssl_module \
    --with-http_gzip_static_module \
    --with-ipv6

 make

make install

3. 安装PHP7

添加用户组和用户

groupadd www

useradd -s /sbin/nologin -g www www

安装所需依赖

yum -y install gcc gcc-c++ make automake autoconf
yum -y install libxml2-devel openssl-devel pcre-devel sqlite-devel libzip libzip-devel bzip2-devel libcurl-devel freetype-devel gd-devel readline-devel libmcrypt-devel libicu-devel

选择自己需要的PHP扩展,编译PHP。如果此时扩展少选了,后续还可以使用phpize安装扩展。

tar -zxvf cd php-7.3.4.tar.gz

cd cd php-7.3.4/

./configure  --prefix=/usr/local/php7  --disable-fileinfo  --with-pdo-mysql --with-mcrypt --with-bz2 --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir --with-readline --with-curl --with-pear --with-openssl --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-gd-native-ttf --enable-pcntl --enable-sockets --enable-soap --enable-session --enable-zip

编译时可能会提示某个依赖包版本较低比如下面的提示,都需要根据提示重新安装

a:  configure: error: Please reinstall the libzip distribution
b:  checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11

安装高版本libzip

yum remove libzip*

wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure

make

make install

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

解决完问题后重新编译PHP,并执行。如果在make过程中遇到问题并解决后执行make clean再make。

make

make install

4. 配置

设置软连接

ln -s /usr/local/php7/bin/php /usr/bin/php
ln -s /usr/local/php7/bin/phpize /usr/bin/phpize
ln -s /usr/local/php7/bin/pecl /usr/bin/pecl
ln -s /usr/local/php7/bin/php-config /usr/bin/php-config
ln -s /usr/local/php7/sbin/php-fpm /usr/bin/php-fpm

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

配置nginx,是请求转发至phpfpm

vim /usr/local/nginx/conf/nginx.conf

配置php

cd /usr/local/php7/etc/

mv php-fpm.conf.default  php-fpm.conf

cd /usr/local/php7/etc/php-fpm.d/

mv www.conf.default www.conf
 

5. 启动

php-fpm -D

nginx

如无报错则启动成功,可用ps查看服务状态

ps aux|grep nginx

ps aux|grep php-fpm

 

 

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值