php7.0搭配nginx,centos7nginx+php7环境搭建及权限配置

一.安装nginx

1.安装yum源

rpm -Uvh

http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.安装nginx

yum install -y nginx

3.启动nginx并设置开机自动运行

systemctl start nginx #启动,restart-重启,stop-停止

systemctl enable nginx #开机启动

4.查看版本及运行状态

nginx -v #查看版本

ps -ef | grep nginx #查看运行状态

二.安装php7

1.安装yum源

rpm -Uvh

https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh

https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2.查看php7

yum组件,示例安装php7.2

# yum search php72w #显示如下结果

……

……

mod_php72w.x86_64 : PHP module for the Apache HTTP

Server

php72w-bcmath.x86_64 : A module for PHP applications for using

the bcmath library

php72w-cli.x86_64 : Command-line interface for PHP

php72w-common.x86_64 : Common files for PHP

php72w-dba.x86_64 : A database abstraction layer module for

PHP applications

php72w-devel.x86_64 : Files needed for building PHP

extensions

php72w-embedded.x86_64 : PHP library for embedding in

applications

php72w-enchant.x86_64 : Enchant spelling extension for PHP

applications

php72w-fpm.x86_64 : PHP FastCGI Process Manager

php72w-gd.x86_64 : A module for PHP applications for using the

gd graphics library

php72w-imap.x86_64 : A module for PHP applications that use

IMAP

php72w-interbase.x86_64 : A module for PHP applications that

use Interbase/Firebird databases

php72w-intl.x86_64 : Internationalization extension for PHP

applications

php72w-ldap.x86_64 : A module for PHP applications that use

LDAP

php72w-mbstring.x86_64 : A module for PHP applications which

need multi-byte string handling

php72w-mysql.x86_64 : A module for PHP applications that use

MySQL databases

php72w-mysqlnd.x86_64 : A module for PHP applications that use

MySQL databases

php72w-odbc.x86_64 : A module for PHP applications that use

ODBC databases

php72w-opcache.x86_64 : An opcode cache Zend extension

php72w-pdo.x86_64 : A database access abstraction module for

PHP applications

php72w-pdo_dblib.x86_64 : MSSQL database module for PHP

php72w-pear.noarch : PHP Extension and Application Repository

framework

php72w-pecl-apcu.x86_64 : APCu - APC User Cache

php72w-pecl-apcu-devel.x86_64 : APCu developer files

(header)

php72w-pecl-geoip.x86_64 : Extension to map IP addresses to

geographic places

php72w-pecl-igbinary.x86_64 : Replacement for the standard PHP

serializer

php72w-pecl-igbinary-devel.x86_64 : Igbinary developer files

(header)

php72w-pecl-imagick.x86_64 : Provides a wrapper to the

ImageMagick library

php72w-pecl-imagick-devel.x86_64 : Imagick developer files

(header)

php72w-pecl-libsodium.x86_64 : Wrapper for the Sodium

cryptographic library

php72w-pecl-memcached.x86_64 : Extension to work with the

Memcached caching daemon

php72w-pecl-mongodb.x86_64 : PECL package MongoDB driver

php72w-pecl-redis.x86_64 : Extension for communicating with

the Redis key-value store

php72w-pecl-xdebug.x86_64 : PECL package for debugging PHP

scripts

php72w-pgsql.x86_64 : A PostgreSQL database module for

PHP

php72w-phpdbg.x86_64 : Interactive PHP debugger

php72w-process.x86_64 : Modules for PHP script using system

process interfaces

php72w-pspell.x86_64 : A module for PHP applications for using

pspell interfaces

php72w-recode.x86_64 : A module for PHP applications for using

the recode library

php72w-snmp.x86_64 : A module for PHP applications that query

SNMP-managed devices

php72w-soap.x86_64 : A module for PHP applications that use

the SOAP protocol

php72w-sodium.x86_64 : Wrapper for the Sodium cryptographic

library

php72w-tidy.x86_64 : Standard PHP module provides tidy library

support

php72w-xml.x86_64 : A module for PHP applications which use

XML

php72w-xmlrpc.x86_64 : A module for PHP applications which use

the XML-RPC protocol

3.选择自己需要的组件安装,php72w.x86_64 和 php72w-fpm.x86_64 为核心程序必装

yum install php72w.x86_64 php72w-fpm.x86_64 php72w-cli.x86_64

php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64

php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysql.x86_64

php72w-pdo.x86_64 php72w-pecl-redis.x86_64

4.启动php并设为开机启动

systemctl start php-fpm #启动,restart-重启,stop-停止

systemctl enable php-fpm #开机启动

5.查看版本及运行状态

php-fpm -v #查看版本

ps -ef | grep php-fpm #查看运行状态

进行完以上步骤之后,读者自行在nginx中配置web目录,已经可以正常运行了,但是此时nginx和php是以root身份运行,以最高权限运行web文件会给系统带来安全隐患,以下为权限配置示例

三.配置权限

1.建立www用户及www用户组,将www用户同时加入www用户组和root组

adduser www #建立www用户

groupadd www #建立www用户组

usermod -G www www #将www用户加入www用户组同时从其他组移除

usermod -a -G root www #将www用户加入root用户组,有-a参数不从其他组移除,此时www同时属于www和root组

2.将nginx以www用户及www用户组运行,修改nginx.conf文件,在文件头部:

user www www; #以www身份运行

3.将web目录的拥有者改为www:www,权限改为755

chown www:www web目录 -R #修改拥有者

chmod 755 web目录 -R #修改权限

4.重载nginx配置

nginx -t #测试

nginx -s reload #重载配置

如果此时出现静态文件可以访问而php文件显示无权限访问的话,需要检查SELinux,将其关闭即可正常运行。

---------------------

nginx配置的时候注意错误日志的路径,当你的php运行出现未知错误的时候,可以查看日志检查错误原因。

原文:https://blog.csdn.net/qq_18358973/article/details/81475217

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值