nginx php root,服务器篇06-Nginx配置PHP环境

PHP官网下载地址

wget http://cn2.php.net/get/php-7.0.7.tar.bz2/from/this/mirror/php-7.0.7.tar.bz2

解压从官方下载的压缩包

tar xvf php-7.0.7.tar.bz2

安装相应的组件库,可根据需求更改

yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel yum -y install ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel

执行编译安装,可根据需求更改

./configure --prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--enable-mysqlnd \--with-mysqli

\--with-pdo-mysql \--enable-fpm \--with-gd \--with-iconv \--with-zlib \--enable-xml \--enable-shmop \--enable-sysvsem \--enable-inline-optimization \--enable-mbregex \--enable-mbstring \--enable-ftp \--enable-gd-native-ttf \--with-openssl \--enable-pcntl \--enable-sockets \--with-xmlrpc \--enable-zip \--enable-soap \--without-pear \--with-gettext \--enable-session \--with-curl \--with-jpeg-dir \--with-freetype-dir \--enable-opcache

make && make install

拷贝一份PHP默认配置文件模板

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

cp www.conf.default www.conf

cd /usr/local/php/etc/

cp php-fpm.conf.default php-fpm.conf

修改进程默认用户

vim /usr/local/php/etc/php-fpm.d/www.conf

#将user和group更改为设置的网站管理用户

在网站目录中建立php测试文件用于页面访问php测试

vim /wwwroot/html/www.test.com/index.php

赋予站点目录及以下文件权限为读取和执行

chmod -R 755 /wwwroot

启用php服务并加入开机自启

/usr/local/php/sbin/php-fpm

echo '/usr/local/php/sbin/php-fpm' >> /etc/rc.local

更改nginx配置文件使其可以访问php文件

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

server

{

listen 80 ;

server_name www.test.com test.com;

index index.html index.htm index.php;

root /wwwroot/html/www.test.com;

location ~ \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;

include fastcgi_params;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 12h;

}

location ~ /\.

{

deny all;

}

error_log /wwwroot/wwwlogs/www.test.com.error.log;

access_log /wwwroot/wwwlogs/www.test.com.access.log;

}

重新加载nginx配置文件就可以host绑定用浏览器访问测试了

/usr/local/nginx/sbin/nginx -s reload

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值