LNMP的搭建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LNMP的搭建相关的知识,希望对你有一定的参考价值。
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
[[email protected] php-5.6.39]# ls /usr/local/php-fpm/etc/
pear.conf php-fpm.conf.default
[[email protected] php-5.6.39]# cp php.ini-production /usr/local/php-fpm/etc/php.ini
[[email protected] php-5.6.39]# cd /usr/local/php-fpm/etc/
[[email protected] etc]# ls
pear.conf php-fpm.conf.default php.ini
[[email protected] 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
[[email protected] nginx-1.15.5]# vim /etc/init.d/nginx
[[email protected] nginx-1.15.5]# chmod 755 /etc/init.d/nginx
[[email protected] nginx-1.15.5]# chkconfig --add nginx
[[email protected] nginx-1.15.5]# chkconfig nginx on
[[email protected] nginx-1.15.5]# cd /usr/local/nginx/conf/
[[email protected] 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
[[email protected] conf]# mv nginx.conf nginx.conf.bak
[[email protected] conf]# vim nginx.conf
[[email protected] 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
[[email protected] conf]# /etc/init.d/nginx start
Starting nginx (via systemctl): [ 确定 ]
[[email protected] 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
[[email protected] conf]#
测试php的解释:
vi /usr/local/nginx/html/1.php //加入如下内容
<?php
echo "test php scripts.";
?>
curl localhost/1.php
以上是关于LNMP的搭建的主要内容,如果未能解决你的问题,请参考以下文章