centos7 nginx部署php,Centos7+Nginx+PHP 基础WEB运行环境手工部署

Centos7+nginx+php(php-fpm)基础web运行环境手工部署

准备工作

1.安装编译支持库

yum install -y gcc automake autoconf libtool make

yum install -y gcc gcc-c++

yum install -y openldap-devel libicu-devel libpng-devel libjpeg-devel curl-devel openssl-devel libxml2-devel libzip-devel

2.安装PCRE

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz

tar -xzf pcre-8.40.tar.gz -C ./

cd pcre-8.40

./configure --prefix=/usr/local/pcre

make && make install

cd ..

3.安装zlib

wget http://zlib.net/zlib-1.2.11.tar.gz

tar -xzf zlib-1.2.11.tar.gz -C ./

cd zlib-1.2.11

./configure --prefix=/usr/local/zlib

make && make install

cd ..

4.安装openssl

wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz

tar -xzf openssl-1.0.2k.tar.gz -C ./

#注意,这里不需要进行安装,后面步骤省略。

安装nginx

官方下载 http://nginx.org/en/download.html

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

tar -xzf nginx-1.12.0.tar.gz -C ./

cd nginx-1.12.0

./configure \

--prefix=/usr/local/nginx \

--sbin-path=/usr/local/nginx/nginx \

--conf-path=/usr/local/nginx/nginx.conf \

--pid-path=/usr/local/nginx/nginx.pid \

--with-http_ssl_module \

--with-pcre=/mnt/tools/pcre-8.40/ \

--with-zlib=/mnt/tools/zlib-1.2.11/ \

--with-openssl=/mnt/tools/openssl-1.0.2k/ \

--with-http_stub_status_module \

--with-http_realip_module \

--with-stream

#注:cpre、zlib、openssl等依赖包的路径是解压的源码路径不是安装后的路径。

make

make install

安装PHP

安装依赖扩展

yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel

官网下载 http://php.net/releases/index.php

官网安装文档 http://php.net/manual/zh/install.unix.nginx.php

【可选】扩展freetype库安装

wget https://cytranet.dl.sourceforge.net/project/freetype/freetype2/2.9.1/freetype-2.9.1.tar.gz

tar -xzf freetype-2.9.1.tar.gz

cd freetype-2.9.1

./configure --prefix=/usr/local/freetype/2.9.1/ --libdir=/usr/local/freetype/2.9.1/lib64 --with-static --with-shared

make && make install

wget http://php.net/get/php-5.6.29.tar.gz/from/this/mirror -O php-5.6.29.tar.gz

tar -xzf php-5.6.29.tar.gz -C ./

cd php-5.6.29

./configure --prefix=/usr/local/php/php5.6.29/\

--with-config-file-path=/usr/local/php/php5.6.29/\

--with-libdir=lib64\

--enable-fpm\

--with-fpm-user=php-fpm\

--with-fpm-group=www\

--enable-mysqlnd\

--with-mysql=mysqlnd\

--with-mysqli=mysqlnd\

--with-pdo-mysql=mysqlnd\

--enable-opcache\

--enable-pcntl\

--enable-mbstring\

--enable-soap\

--enable-zip\

--enable-calendar\

--enable-bcmath\

--enable-exif\

--enable-ftp\

--enable-intl\

--enable-sockets\

--with-openssl\

--with-zlib\

--with-curl\

--with-gd\

--with-zlib-dir=/usr/lib\

--with-png-dir=/usr/lib\

--with-jpeg-dir=/usr/lib\

--with-gettext\

--with-mhash\

--with-ldap

make && make install

[可选]编译freetype将参数追加到configure 后面

--with-freetype-dir=/usr/local/freetype/2.9.1/\

--enable-gd-native-ttf\

配置文件

创建PHP配置文件

#创建配置文件

cd /usr/local/php/php-5.6.29/

cp php.ini-development /usr/local/php/php5.6.29/php.ini

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

#复制php-fpm管理器脚本

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

修改配置文件

vi /usr/local/php/php5.6.29/php.ini

#需要着重提醒的是,如果文件不存在,则阻止 Nginx 将请求发送到后端的 PHP-FPM 模块,

#以避免遭受恶意脚本注入的攻击。

#定位到 cgi.fix_pathinfo= 并将其修改为如下所示:

cgi.fix_pathinfo=0

创建php-fpm运行用户,可通过配置查看当前配置用户及组名。

vi /usr/local/etc/php-fpm.conf

; Unix user/group of processes

; Note: The user is mandatory. If the group is not set, the default user's group

; will be used.

user = php-fpm

group = www

#创建用户

useradd -s /sbin/nologin -M php-fpm

#创建组

groupadd www

通过php-fpm脚本,启动php服务(停止、重启、重载)。

service php-fpm start

service php-fpm restart

service php-fpm stop

service php-fpm reload

配置nginx,使其支持PHP应用。

vi /usr/local/nginx/nginx.conf

修改默认的 location 块,使其支持 .php 文件:

location / {

root html;

index index.php index.html index.htm;

}

下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

include fastcgi_params;

}

测试运行

重启 Nginx

/usr/local/nginx/nginx -s stop

/usr/local/nginx/nginx

#注意前面应该启动 php-fpm ,如:service php-fpm start

echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/index.php

访问 http://www.example.com 已经成功。

本文注意细节已经在过程步骤中说明,留意查看。如有疑问,请在文末留言,谢谢。

更多关于nginx、apache等web服务环境部署及生成环境部署优化,欢迎关注本博客文章。

续篇文章

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值