多机部署lnmp-1
Posted momenglin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多机部署lnmp-1相关的知识,希望对你有一定的参考价值。
第一台部署nginx
[[email protected] ~]# 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
[[email protected] ~]# 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
[[email protected] ~]# mysqladmin password "kailey" //为数据库设置一个密码
[[email protected] ~]# mysql -uroot -p"kailey"
MariaDB [(none)]> grant all on *.* to [email protected]‘192.168.122.%‘ identified by ‘123‘; //为php连接mysql授权,指定一个帐号密码
Query OK, 0 rows affected (0.00 sec)
第三台部署php
[[email protected]~]# yum -y install php php-fpm php-mysql php-gd gd
[[email protected] ~]# systemctl start php-fpm
[[email protected] ~]# mkdir /web
[[email protected] ~]# vim /web/a.php
[[email protected] ~]# cat /web/a.php //写一个php首页
<?php
phpinfo();
?>
[[email protected] web]# cat b.php
[[email protected] 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能否连接成功
[[email protected] 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
[[email protected] web]# systemctl restart php-fpm
测试访问192.168.122:/a.php 显示php首页 192.168.122:/b.php 显示successfully 表示部署成功
以上是关于多机部署lnmp-1的主要内容,如果未能解决你的问题,请参考以下文章