LNMP详解

时间:2023-03-08 17:57:01
LNMP详解

目录

Nginx配置    1

PHP解析    1

Mysql操作    3

服务安装    3

连接测试    3

数据配置    3

Blogs建立    4

 

LNMP

环境

Mysql:192.168.10.10

Nginx、PHP:192.168.10.11

 

在服务都部署好之后,对其进行关联;

相关操作命令:

# /usr/local/nginx/sbin/nginx -t

# /usr/local/nginx/sbin/nginx -s reload

Nginx配置

[root@c1 /usr/local/nginx/conf]# cat 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 localhost;

location / {

root html;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

include extra/kazihuo.conf;

}

PHP解析

[root@c1 /usr/local/nginx/conf/extra]# cat kazihuo.conf

server {

    listen 80;

    server_name www.kazihuo.com;

    location / {

    root html/kazihuo;

     index index.php index.html index.htm;

    }    

 

    location ~ .*\.(php|php5)?$ {

     root html/kazihuo;

     fastcgi_pass 127.0.0.1:9000;

     fastcgi_index index.php;

     include fastcgi.conf;

    }

}

[root@c1 /usr/local/nginx/html/kazihuo]# cat index.php

<?php phpinfo(); ?>

# 以上代码是显示PHP配置信息

 

测试:

现在本地电脑做好解析,打开浏览器http://www.kazihuo.com/index.php

 

Mysql操作

服务安装

详细步骤见博文MYSQL汇总;

连接测试

[root@c1 /usr/local/nginx/html/kazihuo]# cat test_mysql.php

<?php

    //$link_id=mysql_connect('主机名','用户','密码');

    $link_id=mysql_connect('192.168.10.10','root','000000') or mysql_error();

    if ($link_id) {

        echo "mysql successful by kazihuo !";

    }

    else{

        echo mysql_error();

        }

// 单行注释

/* 多行注释 */

?>

 

测试结果:

LNMP详解

数据配置

# mysql -uroot -p000000

> create database wordpress;

> grant all on wordpress.* to wordpress@'192.168.10.%' identified by '123456';6';

> flush privileges;

> show grants for wordpress@'192.168.10.%';

+---------------------------------------------------------------------+

| Grants for wordpress@192.168.10.% |

+---------------------------------------------------------------------+

| GRANT USAGE ON *.* TO 'wordpress'@'192.168.10.%' |

| GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wordpress'@'192.168.10.%' |

+---------------------------------------------------------------------+

> select user,host from mysql.user;

+-----------+--------------+

| user | host |

+-----------+--------------+

| root | % |

| root | 127.0.0.1 |

| wordpress | 192.168.10.% |

| mysql.sys | localhost |

| root | localhost |

+-----------+--------------+

Blogs建立

# wget https://cn.wordpress.org/wordpress-4.9.1-zh_CN.tar.gz

# tar -axvf wordpress-4.9.1-zh_CN.tar.gz

[root@c1 /usr/local/nginx/html/kazihuo]# rm -rf index.php test_mysql.php #此步骤是删除之前的测试文件

# cd wordpress/

# mv * /usr/local/nginx/html/kazihuo/

[root@c1 /usr/local/nginx/html]# chown -R nginx.nginx kazihuo

 

测试:

浏览器输入:www.kazihuo.com

LNMP详解