其他分享
首页 > 其他分享> > 多机部署lnmp-1

多机部署lnmp-1

作者:互联网

第一台部署Nginx

[root@lnmp ~]# cat /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1


yum -y install nginx

systemctl start nginx

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

这个模块时nginx与php之间的联系

 location ~ \.php$ {        
        root           /web;
        fastcgi_pass   192.168.122.77:9000;     //ip为php主机ip  
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

nginx -t

nginx -s reload
第二台部署mysql

yum -y install mariadb-server

systemctl start mariadb

[root@mysql ~]# mysqladmin password "kailey"   //为数据库设置一个密码
[root@mysql ~]# mysql -uroot -p"kailey"

MariaDB [(none)]> grant all on *.* to phptest@'192.168.122.%' identified by '123';  //为php连接mysql授权,指定一个帐号密码
Query OK, 0 rows affected (0.00 sec)

第三台部署php

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

[root@localhost ~]# systemctl start php-fpm
[root@localhost ~]# mkdir /web
[root@localhost ~]# vim /web/a.php
[root@localhost ~]# cat /web/a.php           //写一个php首页
<?php
    phpinfo();
?>

[root@localhost web]# cat b.php
[root@html2 app]# cat b.php
<?php
$link=mysql_connect("192.168.122.222","phptest","123");   这里的是用户连接mysql的帐号密码,ip为mysql主机ip
if($link)
echo "Successfully";
else
echo "Failure";
?>                                   //测试php与mysql能否连接成功

[root@localhost web]# vim /etc/php-fpm.d/www.conf

listen = 192.168.122.77:9000    //监听主机,把前面ip改为php本机的ip

listen.allowed_clients = 192.168.122.10    //允许客户端ip改为nginx主机的ip

[root@localhost web]# systemctl restart php-fpm

测试访问192.168.122:/a.php  显示php首页     192.168.122:/b.php  显示successfully  表示部署成功

标签:web,部署,lnmp,192.168,nginx,多机,mysql,php,root
来源: https://www.cnblogs.com/momenglin/p/10384566.html