LNMP 示例详解(Nginx+Mariadb+PHP)
LNMP 拓扑
各个服务器配置
1、后端 Nginx-Server — 处理静态资源
1.1 安装 Nginx 并启动
[root@Neo_Tang html]# ifconfig | grep "inet 192" -C 1
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.13 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe7b:193f prefixlen 64 scopeid 0x20<link>
[root@Neo_Tang html]# rpm -q nginx # 已安装 Nginx
nginx-1.12.2-3.el7.x86_64
[root@Neo_Tang html]# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2019-09-27 23:04:36 EDT; 9h ago
1.2 在后端 Nginx-Server 上部署 phpMyAdmin
按照我们的方案设计思路:动态资源由前端代理 Nginx 反代至 Php-Server,但是用户在使用 phpMyAdmin 时,其有些资源(如图片,xml文件等)是静态的,无法反代至 Php-Server ,致使界面显示不全。所以需要在静态资源处理服务器(后端 Nginx-Server)上部署相应的 phpMyAdmin ,响应部分静态资源。
[root@Neo_Tang ~]# ll
total 7040
-rw-------. 1 root root 1260 Aug 10 15:26 anaconda-ks.cfg
-rw-r--r--. 1 root root 7203314 Sep 27 22:56 phpMyAdmin-4.0.10.20-all-languages.tar.gz
[root@Neo_Tang ~]#
[root@Neo_Tang ~]# mkdir /data/nginx/html/ -pv
mkdir: created directory ‘/data/nginx/html/’
[root@Neo_Tang ~]# tar xf phpMyAdmin-4.0.10.20-all-languages.tar.gz -C /data/nginx/html/
[root@Neo_Tang ~]# cd /data/nginx/html/
[root@Neo_Tang html]# ln -sv phpMyAdmin-4.0.10.20-all-languages pma
‘pma’ -> ‘phpMyAdmin-4.0.10.20-all-languages’
[root@Neo_Tang html]# ll
total 4
drwxr-xr-x. 9 root root 4096 Mar 28 2017 phpMyAdmin-4.0.10.20-all-languages
lrwxrwxrwx. 1 root root 34 Sep 27 22:58 pma -> phpMyAdmin-4.0.10.20-all-languages
[root@Neo_Tang html]# touch index.html
[root@Neo_Tang html]# vim index.html
[root@Neo_Tang html]# cat index.html # 设置默认页面
<h1>Nginx-Server 192.168.10.13 Static-Sources</h1>
[root@Neo_Tang html]# vim /etc/nginx/conf.d/neotang.conf
[root@Neo_Tang html]# cat /etc/nginx/conf.d/neotang.conf
server {
listen 80;
root /data/nginx/html; # 修改文档根目录
}
[root@Neo_Tang html]# nginx -t # 检查语法配置
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@Neo_Tang html]# systemctl start nginx.service
[root@Neo_Tang html]# ss -tnl # 查看服务端口已在监听
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
2、Php-server(Mariadb)— 处理动态资源
2.1 相关程序安装
[root@neo-neo ~]# ifconfig | grep "inet 192.168" -C 1
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.12 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe85:753f prefixlen 64 scopeid 0x20<link>
[root@neo-neo ~]# yum install php-fpm php-mysql php-mbstring php-mcrypt mariadb-server -y
[root@neo-neo ~]# yum info php-fpm php-mysql php-mbstring php-mcrypt mariadb-server
Name : mariadb-server
Arch : x86_64
Epoch : 1
Version : 5.5.64
Release : 1.el7
Repo : installed
Name : php-fpm
Arch : x86_64
Version : 5.4.16
Release : 46.el7
Repo : installed
Name : php-mbstring
Arch : x86_64
Version : 5.4.16
Release : 46.el7
Repo : installed
Name : php-mcrypt
Arch : x86_64
Version : 5.4.16
Release : 9.el7
Repo : installed
Name : php-mysql
Arch : x86_64
Version : 5.4.16
Release : 46.el7
Repo : installed
2.2 修改 Php-Server 相关配置文件
[root@neo-neo php-fpm.d]# pwd
/etc/php-fpm.d
[root@neo-neo php-fpm.d]# vim www.conf
listen = 0.0.0.0:9000
listen.allowed_clients = 0.0.0.0 # 代表监听本机所有地址的 9000 端口
user = apache
group = apache
pm.status_path = /status
ping.path = /ping
php_value[session.save_handler] = files
php_value[session.save_path] = /