#LNMP组成介绍
LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。
#LNMP工作原理
- ①浏览器发送 http request 请求到服务器(Nginx),服务器响应并处理 Web 请求,将一些静态资源(CSS、图片、视频等)保存在服务器上。
- ②将PHP脚本通过接口传输协议(网关协议)PHP-FCGI(FastCGI)传输给PHP FPM(进程管理程序),PHP-FPM 不做处理。然后PHP-FPM调用 PHP解析器进程 PHP 解析器解析 PHP 脚本信息。PHP解析器进程可以启动多个,进行并发执行。
- ③将解析后的脚本返回到PHP-FPM,PHP-FPM 再通过FastCGI的形式将脚本信息传送给Nginx。
- ④服务器再通过http response的形式传送给浏览器,浏览器再进行解析与渲染,最后进行呈现。
实战
- 安装环境
[root@localhost ~]# hostnamectl set-hostname lnmp
[root@localhost ~]# bash
[root@lnmp ~]# yum install -y wget
[root@lnmp ~]# wget http://soft.vpser.net/lnmp/lnmp1.8.tar.gz
[root@lnmp ~]# tar zxf lnmp1.8.tar.gz
[root@lnmp ~]# ls
anaconda-ks.cfg lnmp1.8 lnmp1.8.tar.gz
[root@lnmp ~]# cd lnmp1.8
[root@lnmp lnmp1.8]# ./install.sh
============================== Check install ==============================
Checking ...
Nginx: OK
MySQL: OK
PHP: OK
PHP-FPM: OK
Clean Web Server src directory...
+------------------------------------------------------------------------+
| LNMP V1.8 for CentOS Linux Server, Written by Licess |
+------------------------------------------------------------------------+
| For more information please visit https://lnmp.org |
+------------------------------------------------------------------------+
| lnmp status manage: lnmp {start|stop|reload|restart|kill|status} |
+------------------------------------------------------------------------+
| phpMyAdmin: http://IP/phpmyadmin/ |
| phpinfo: http://IP/phpinfo.php |
| Prober: http://IP/p.php |
+------------------------------------------------------------------------+
| Add VirtualHost: lnmp vhost add |
+------------------------------------------------------------------------+
| Default directory: /home/wwwroot/default |
+------------------------------------------------------------------------+
| MySQL/MariaDB root password: 123456 |
+------------------------------------------------------------------------+
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
nginx (pid 94339) is running...
php-fpm is runing!
SUCCESS! MySQL running (94891)
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 :::22 :::*
Install lnmp takes 13 minutes.
Install lnmp V1.8 completed! enjoy it.
- 部署Wordpress应用
- 配置数据库
[root@lnmp lnmp1.8]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.62-log Source distribution
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on *.* to root@localhost identified by '123456' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to root@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
- 下载wordpres包
[root@lnmp lnmp1.8]# cd
[root@lnmp ~]# wget https://cn.wordpress.org/latest-zh_CN.zip
[root@lnmp ~]# unzip latest-zh_CN.zip
#删除nginx默认的Index.html文件
[root@lnmp ~]# cd /home/wwwroot/default/
[root@lnmp default]# ls
index.html lnmp.gif ocp.php phpinfo.php phpmyadmin p.php
[root@lnmp default]# rm -rf index.html
[root@lnmp wordpress]# cd /root/wordpress/
[root@lnmp wordpress]# cp -rvf * /home/wwwroot/default/
[root@lnmp wordpress]# chmod 777 /home/wwwroot/default/*
[root@lnmp default]# cp wp-config-sample.php wp-config.php
[root@lnmp default]# vim wp-config.php
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** Database username */
define( 'DB_USER', 'root' );
/** Database password */
define( 'DB_PASSWORD', '123456' );
/** Database hostname */
define( 'DB_HOST', '127.0.0.1' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
- 浏览器访问测试
进入博客首页后,可以在这里发表文章,记录事件等。