LNMP分离式部署步骤详解

1 .nginx编译安装参考nginx的
2 .mysql编译安装参考mysql的
3 .php安装要加一条安装支持
yum -y install openssl-devel openssl
1. 开始部署web端
1) 在根目录下创建一个目录www
mkdir /www
递归给www属主和属组为www
chown  -R www.www /www
2) vim /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;  
    server {
        listen       80;
        server_name  www.lijianjie.com;
            root   /www;
        location / {
            index index.php  index.html index.htm;
       }
        location ~.*\.(php|php5)?$ {
           fastcgi_pass  192.168.232.161:9000 ;
           fastcgi_index index.php;
           include        fastcgi.conf;
}
    }
}
或者在server 上面添加服务池
upstream     www_server {
                    server    ip地址
                    server    ip地址
                 }
然后再在php动态location下面插入
                fastcgi_pass   http://www_server;
3) 重启服务
/usr/local/nginx/sbin/nginx -s reload
4)在www目录下创建动态页面
touch /www/index.php
2. 部署PHP端
1) 在根目录下创建一个目录www
mkdir /www
递归给www属主和属组为www
chown  -R www.www /www
2) 在www下创建index.php
cd /www
echo "`hostname -I`  php" >index.php
3) 在windows下做映射
C:\Windows\System32\drivers\etc\hosts
记事本写入 web的IP地址  域名  保存
192.168.232.160   www.lijianjie.com
然后用浏览器打开域名,你看到的页面就是PHP动态页面内容
3. 部署mysql端
1) 创建用户
grant all on *.* to 'root'@'192.168.232.%' identified by'123456';
select user,host from mysql.user;
2) 在php端
cd /www
touch test_mysql.php
vim test_mysql.php
编译内容
<?php
    //$link_id=mysql_connect('主机名','用户','密码');
    $link_id=mysql_connect('192.168.232.159','root','123456'); #ip地址是mysql端的ip
    if($link_id){
        echo "mysql lianjiechengong";
    }else{
        echo mysql_error();
    }
?>
现在在浏览器输入测试网址就能看到数据库是否登录成功了
http://www.lijianjie.com/test_mysql.php
页面显示 :mysql lianjiechengong 说明成功了

猜你喜欢

转载自www.cnblogs.com/lijianjie/p/10084074.html