在lnmp上部署phpMyAdmin
前言:以前,我们实现过在lamp架构上部署wordpress博客系统,httpd服务本身支持模块化和fastcgi两种形式连接到php应用(其他方式博主没用过就不提了)。而nginx作为web服务器的话就只能通过fastcgi连接到php应用了。当然,nginx还有一个常用的用处就是作为反向代理,这是后话,以后在提。
正文:
当web服务承载的用户数量越来越大时,如果我们依然把整个lnmp都部署在一台主机上,肯定是有问题的,所以今天我们直接来实现把nginx,fpm和mysql分别部署在不同的服务器上。我们的环境是有三台centos7主机,172.16.53.100部署nginx服务,172.16.53.101部署fpm,172.16.53.102部署mysql。我们现在三个主机上安装相应的程序。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#172.16.53.100
yum install nginx -y
vim /etc/nginx/nginx.conf 把默认配置先注释掉~不然影响测试。
# server {
# listen 80 default_server;
# listen [::]:80 default_server;
# server_name_;
# root /usr/share/nginx/html;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# root /var/nginx;
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
vim /etc/nginx/ 创建一个单独的配置文件
server {
listen 80; 监听所有接口的80端口
server_name
location/ {
root /var/nginx/phpMyAdmin; 静态文件存放的位置
index index.php; 自动加载index.php的主页文件
}
location ~ \.php$ { 设置动态php文件去172.16.53.101找
fastcgi_pass 172.16.53.101:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/nginx/phpMyAdmin/$fastcgi_script_name;
include fastcgi_params;
}
}
systemctl start nginx
iptable -vnL 清空防火墙规则
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#172.16.53.101
yum install php-fpm php php-mysqlphp-mbstring -y
分别是fastcgi模块,php环境 连接mysql的模块 中文支持模块
vim /etc/php-fpm.d/
listen 0.0.0.0:9000 监听所有端口
listen.allowed_clients = 172.16.53.100 运行100主机的访问
mkdir /var/nginx 我们在此目录下放php程序,请自行下载phpMyAdmin程序
cd /var/nginx
unzip phpMyAdmin-4.4.14.1-all-languages.zip 解压
mv phpMyAdmin-4.4.14.1-all-languages phpMyAdmin 重命名
cp config.sample.inc.php config.inc.php 以默认的配置文件得到我们需要的配置文件
vim config.inc.php 修改配置文件,只用修改一条。
$cfg['Servers'][$i]['host'] = '172.16.53.102'; 要管理的数据库ip地址。
systemctl start php-fpm
iptable -vnL 清空防火墙规则
1
2
3
4
5
6
#172.16.53.102
yum install mariadb-server
systemctl start mariadb
mysql 用mysql命令连接到本地数据库
mysql>grant all on *.* to 'root'@'172.16.%.%' identified by '1234';设置允许同网段的ip,连接到数据库。
iptable -vnL 清空防火墙规则
配置的过程中遇到最多的问题就是防火墙。。。。
dang所有都配置好之后,首先我们要测试能不能显示phpMyAdmin的页面,然后测试能不能连接到数据库。如果是50x错误,应该是location ~ \.php 这个没配置好,或者php-fpm端iptables规则限制访问,如果是404错误,估计是php-fpm端的目录有问题之类的。
像我们的配置是吧静态文件和php文件放在两个服务器上,这样在某些php程序上还是有问题的。比如博主在安装wordpress的时候,当我们安装的时候,或者上传静态文件,比如图片的时候会把这些静态资源传到php-fpm所在的服务器。因此当我们需要访问静态资源而nginx服务器上没有的时候,就会遇到许多问题。
页:
[1]