LNMP架构环境搭建(Linux+Nginx+Mysql+PHP)

一、LNMP环境介绍


        LNMP代表的就是:Linux系统下“Nginx+Mysql+PHP”这种网站服务器架构。Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。MYSQL是一个小型关系型数据库管理系统。PHP是一种在服务器端执行的嵌入式HTML文本的脚本语言。这4种软件均为免费开源软件,组合到一起,就成为一个免费、高效、扩展性强的网站服务系统。

        搭建网站服务器环境有很多可选方案,例如微软的Windows2012、LAMP等。那么为什么要使用LNMP呢?LNMP的优势主要有以下4点。

      (1)作为web服务器:相比Apache,Nginx使用更少的资源,支持更多的并发连接,实现更高效的效率。

      (2)作为负载均衡服务器:Nginx既可以在内部直接支持Rails和PHP,也可以支持作为HTTP代理服务器对外进行服务。Nginx用C编写,不仅是系统资源开销还是CPU使用效率都比Perlbal要更好的多。

      (3)作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也就是作为邮件代理服务器),Last/fm描述了成功并且美妙的使用经验。

      (4)Nginx安装非常的简单,配置文件非常简洁,性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。

二、LNMP环境搭建


准备一台web服务器,

(一)安装配置部署Nginx

[root@localhost ~]# yum install -y nginx

[root@localhost ~]# systemctl start nginx

[root@localhost ~]# systemctl status nginx

测试

 

[root@localhost ~]# vim /etc/nginx/nginx.conf

location ~ \.php$ {

root /usr/share/nginx/html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

[root@localhost ~]# systemctl restart nginx

(二)php-fpm部署

[root@localhost ~]# yum -y install php-fpm php-mysql php-gd

[root@localhost ~]# systemctl start php-fpm

[root@localhost ~]# systemctl enable php-fpm

[root@localhost ~]# systemctl status php-rpm

[root@localhost ~]# netstat -anpt | grep 9000

 测试

[root@localhost ~]# vim /usr/share/nginx/html/index.php

<?php

phpinfo();

?>

(三)Mysql部署

[root@localhost ~]# yum install -y mariadb-server mariadb

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# systemctl enable mariadb.service

[root@localhost ~]# mysqladmin password '123123'

[root@localhost ~]# mysql -uroot -p123123

MariaDB [(none)]> create database bbs;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on bbs.* to phptest@'192.168.163.169' identified by '123123';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

测试

[root@localhost ~]# vim /usr/share/nginx/html/index.php

<?php

$link=mysql_connect('192.168.163.169','phptest','123123');

if ($link)

        echo "Successfuly";

else

        echo "Faile";

mysql_close( );

?>

(四)上线

[root@localhost ~]# wget https://cn.wordpress.org/wordpress-4.9.1-zh_CN.zip

[root@localhost ~]# unzip wordpress-4.9.1-zh_CN.zip

[root@localhost ~]# rm -rf /usr/share/nginx/html/*

[root@localhost ~]# rm -rf /usr/share/nginx/html/*

[root@localhost ~]# cp -rp /root/wordpress* /usr/share/nginx/html/

[root@localhost ~]# chown -R nginx.nginx /usr/share/nginx/html/*

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值