码迷,mamicode.com
首页 > 其他好文 > 详细

LNMP的搭建

时间:2019-05-14 23:13:09      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:cal   pid   default   res   静态   open   clean   转发   rod   

LNMP的介绍:

和LAMP不同的是,提供web服务的是Nginx
并且php是作为一个独立服务存在的,这个服务叫做php-fpm
Nginx直接处理静态请求,动态请求会转发给php-fpm

Mysql的安装:

这里参考前面LAMP的mysql的安装

PHP的安装:

和LAMP安装PHP方法有差别,需要开启php-fpm服务

如果之前安装LAMP的时候安装过php,可以到之前的包里面执行 make clean 清除之前的安装参数。
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
tar zxf php-5.6.30.tar.gz
useradd -s /sbin/nologin php-fpm
cd php-5.6.30
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl

make && make install
cp php.ini-production /usr/local/php-fpm/etc/php.ini
vi /usr/local/php/etc/php-fpm.conf //写入如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/php-fpm.conf)
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
service php-fpm start
ps aux |grep php-fpm

[root@aming01 php-5.6.39]# ls /usr/local/php-fpm/etc/
pear.conf php-fpm.conf.default
[root@aming01 php-5.6.39]# cp php.ini-production /usr/local/php-fpm/etc/php.ini
[root@aming01 php-5.6.39]# cd /usr/local/php-fpm/etc/
[root@aming01 etc]# ls
pear.conf php-fpm.conf.default php.ini
[root@aming01 etc]# vim php-fpm.conf //写入如下的配置文件内容

[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

Nginx

Nginx官网 nginx.org,最新版1.13,最新稳定版1.12
Nginx应用场景:web服务、反向代理、负载均衡
Nginx著名分支,淘宝基于Nginx开发的Tengine,使用上和Nginx一致,服务名,配置文件名都一样,和Nginx的最大区别在于Tenging增加了一些定制化模块,在安全限速方面表现突出,另外它支持对js,css合并
Nginx核心+lua相关的组件和模块组成了一个支持lua的高性能web容器openresty,参考http://jinnianshilongnian.iteye.com/blog/2280928

nginx的安装:

cd /usr/local/src
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar zxf nginx-1.12.1.tar.gz
./configure --prefix=/usr/local/nginx
make && make install
vim /etc/init.d/nginx //复制如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx )

chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
cd /usr/local/nginx/conf/; mv nginx.conf nginx.conf.bak
vim nginx.conf //写入如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/nginx.conf)
/usr/local/nginx/sbin/nginx -t
/etc/init.d/nginx start
netstat -lntp |grep 80

[root@aming01 nginx-1.15.5]# vim /etc/init.d/nginx
[root@aming01 nginx-1.15.5]# chmod 755 /etc/init.d/nginx
[root@aming01 nginx-1.15.5]# chkconfig --add nginx
[root@aming01 nginx-1.15.5]# chkconfig nginx on
[root@aming01 nginx-1.15.5]# cd /usr/local/nginx/conf/
[root@aming01 conf]# ls
fastcgi.conf koi-utf nginx.conf uwsgi_params
fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default
fastcgi_params mime.types scgi_params win-utf
fastcgi_params.default mime.types.default scgi_params.default
[root@aming01 conf]# mv nginx.conf nginx.conf.bak
[root@aming01 conf]# vim nginx.conf
[root@aming01 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@aming01 conf]# /etc/init.d/nginx start
Starting nginx (via systemctl): [ 确定 ]
[root@aming01 conf]# ps aux|grep nginx
root 5697 0.0 0.0 20552 628 ? Ss 10:15 0:00 nginx: master process /usr/local/ngin/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 5701 0.0 0.3 23040 3212 ? S 10:15 0:00 nginx: worker process
nobody 5702 0.0 0.3 23040 3212 ? S 10:15 0:00 nginx: worker process
root 5708 0.0 0.0 112724 988 pts/0 S+ 10:15 0:00 grep --color=auto nginx
[root@aming01 conf]#

测试php的解释:

vi /usr/local/nginx/html/1.php //加入如下内容
<?php
echo "test php scripts.";
?>
curl localhost/1.php

LNMP的搭建

标签:cal   pid   default   res   静态   open   clean   转发   rod   

原文地址:https://blog.51cto.com/13227377/2394648

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!