栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

部署LNMP

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

部署LNMP

前言

  在nginx中,我们使用的是php-fpm来对php页面解析,PHP-FPM其实是PHP源代码的一个补丁,指在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,再编译安装PHP后才可以使用。

  从PHP5.3.3开始,PHP中直接整合了PHP-FPM,所以从PHP5.3.3版本以后,不需要下载PHP-FPM补丁包了

1、安装php 1.1、安装依赖包
yum -y install gcc autoconf  freetype gd libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel freetype-devel libjpeg-devel bzip2 bzip2-devel openssl openssl-devel
1.2、安装libmcrypt

上传软件包

tar zxf libmcrypt-2.5.7.tar.gz   #解压

cd libmcrypt-2.5.7   #进入libmcrypt软件包中

./configure --prefix=/usr/local/libmcrypt && make && make install  #预编译安装
1.3、解压PHP包
tar zxf php-5.6.36.tar.gz -C /usr/local/src  #将php包解压到/usr/local/src下
1.4、预编译
cd /usr/local/src/php-5.6.36/    #进入安装路径下

./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/usr/local/php5.6/etc/ --with-bz2 --enable-maintainer-zts    #预编译

参数说明

--prefix=/usr/local/php5.6   //安装位置

--with-mysql=mysqlnd     //支持mysql

--with-pdo-mysql=mysqlnd  //支持pdo模块

--with-mysqli=mysqlnd     //支持mysqli模块

注:上面的三选项的作用:数据库与php不在一个服务器上,指定此种方式,安装数据库连接驱动

--enable-mbstring                    #多字节字符串的支持

--with-curl                                #支持CURL

--with-gd                              #支持gd库

--with-config-file-path                  #设置配置文件路径

--with-openssl              #支持openssl模块

--enable-fpm                            #支持fpm模式

--enable-sockets             #启用socket支持

--enable-sysvshm                     #启用系统共享内存支持

--enable-mbstring                    #多字节字串、像我们的中文就是多字节字串

--with-freetype-dir                    #支持freetype、就要装freetype-devel、跟字体相关的、字体解析工具

--with-jpeg-dir

--with-png-dir

注:上面的二选项的作用:处理jpeg、png图片的、php可以动态生成jpeg图片

--with-zlib                                 #是个压缩库、在互联网传输时用来压缩传输的

--with-libxml-dir=/usr             #这个libxml是用来解析xml的、指定/usr下

--enable-xml                          #支持xml的

--with-mhash                         #支持mhash

--with-mcrypt=/usr/local/libmcrypt #libmcrypt-devel这个程序包所指定的

--with-config-file-path=/usr/local/php5.6/etc #指定配置文件的存放路径的

--with-config-file-scan-dir=/etc/php.d  #配置文件扫描路径

--with-bz2                        #支持BZip2

1.5编译安装

编译 make

安装 make install

1.6生成php.ini配置文件
cp /usr/local/src/php-5.6.36/php.ini-production  /usr/local/php5.6/etc/php.ini

1.7、修改fpm配置php-fpm.conf.default
 cd /usr/local/php5.6/etc/
cp php-fpm.conf.default php-fpm.conf
1.8、修改默认运行账户

修改默认账户为www组为www

vim php-fpm.conf

user = www

group = www

pid = run/php-fpm.pid

listen = 127.0.0.1:9000

pm.max_children =300

pm.start_servers =20

pm.min_spare_servers = 20

pm.max_spare_servers = 100

 1.9、复制php-fpm启动脚本到init.d
cp /usr/local/src/php-5.6.36/sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm           #赋予可执行权限

chkconfig --add php-fpm          #设置开机自启
chkconfig php-fpm on

/etc/init.d/php-fpm start      #启动服务

netstat -anptl | grep php-fpm     #查看端口监听状态

 2、在nginx.conf文件中server中增添下面的内容支持php

location / {

            root   html;

            index  index.php index.html index.htm; #添加index.php

        }

location ~ .*.(php|php5)?$ {

            root html;

            fastcgi_pass 127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

 3、配置nginx支持index.php文件

创建index.php文件

cd /var/www/html

vim index.php    #进入文件写入以下内容


————————————————————————————————————————————

vim test.php     #进入文件写入以下内容

4、创建mysql测试账号
mysql -uroot -p123456   #进入mysql

grant all on *.* test@'%' identified by '123456';

flush privileges;
 5、测试

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/944245.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号