mariadb简单介绍与PHP环境

nginx与PHP之间的关系

[root@web01 ~]# cat /etc/nginx/conf.d/02-blog.conf
server   {
    listen       80;
    server_name  blog.oldboy.com;
    access_log  /var/log/nginx/access_blog.log  main;
    root   /usr/share/nginx/html/blog; 
    location / {
    index  index.php index.html index.htm;
    }
   location ~* \.(php|php5)$ {
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       include        fastcgi_params;
   }

}

fastcgi_pass 127.0.0.1:9000; 通过php(9000端口)静态的资源自己处理 动态的通过fastcgi_pass给中介(fastcgi)
fastcgi_index index.php; 站点目录
fastcgi_param
SCRIPT_FILENAME 脚本名字
document_root 网站站点目录
fastcgi_script_name 请求连接的URI

Mariadb数据库

1.提前安装MySQL,重启MySQL的mariadb服务
2.查看进程号ss -lntup |grep mysql
3.查看进程 ps -ef |grep mysql
4.然后执行mysql命令进入

image

查看系统中所有数据库的命令

show databases;

结尾要加分号

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

MariaDB [(none)]> 

查看数据库表(行)

MariaDB [(none)]> show tables from mysql;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.00 sec)

查看系统中所有的用户信息

查看user表中的user和host字段

select user,host from mysql.user;

显示出user和host两个字段 在mysql数据库中 的user表中进行查找。

MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
|      | localhost |
| root | localhost |
|      | web01     |
| root | web01     |
+------+-----------+
6 rows in set (0.00 sec)

MariaDB [(none)]> 

MariaDB [(none)]> #select * from wordpress.wp_posts\G   #查看所有表让内容对齐
MariaDB [(none)]> #select * from wordpress.wp_posts limit 1 \G  #只查看一列让内容对齐
MariaDB [(none)]> #select user,host from mysql.user;    #查看user表中的user和host字段(查看系统中所有的用户信息)
MariaDB [(none)]> #use mysql;   #切换到数据库表
MariaDB [mysql]> #select user,host from user;   #进入表后就不用加绝对路径mysql,直接查看相对路径的user和host字段

创建一个新的数据库wordpress

create database wordpress;

最后为数据库名字

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| wordpress          |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> 

创建用户 并给权限,密码,允许谁登录

grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456';
grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';

>grant   创建用户并给权限
>all     所有权限
>on      指定的是
>wordpress.*    wordpress数据库的.所有表
>
>'wordpress'@'localhost'     ‘用户名'@'ip.登录' (%==*)
>identified by '123456';      密码是 '123456';

MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456';
Query OK, 0 rows affected (0.04 sec)

MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user,host from mysql.user;
+-----------+------------+
| user      | host       |
+-----------+------------+
| root      | 127.0.0.1  |
| wordpress | 172.16.1.% |
| root      | ::1        |
|           | localhost  |
| root      | localhost  |
| wordpress | localhost  |
|           | web01      |
| root      | web01      |
+-----------+------------+
8 rows in set (0.00 sec)

删除(谨慎操作)

删除表: drop database lcx;
删除用户: drop user lcx@'172.16.1.%';
删除空用户: drop user ''@'localhost';

刷新权限信息

flush privileges;

修改用户信息之后需要更新权限信息

ctrl c退出mysql,重新进入新创建的数据库用户

mysql -uwordpress -p

-p后直接输入密码也可以
-u与-p后不能加空格

-u:连接MySQL服务器的用户名
-p:连接MySQL服务器的密码
image

数据库备份

  1. 打包 + 定时任务 +rsync
  1. 备份:
    备份全部表:
    mysqldump -uroot -p -A >/root/all.sql
    备份wordpress表:
    mysqldump -uwordpress -p123456 -A >/root/wordpress.sql
    备份并压缩
    mysqldump -uroot -p -A|gzip >/root/all-gzip.sql.gz
  1. 将备份的数据库恢复: mysql -uroot -p

搭建PHP环境

1.修改/etc/php-fpm.d/www.conf中的user与group为nginx

2.检查 用户与用户组是否为nginx

egrep -n 'user|group' /etc/php-fpm.d/www.conf

3.重启 php-fpm.service 服务

systemctl restart php-fpm.service

4.查看端口号与进程(9000)

ss -lntup|grep 9000
ps -ef |grep php

[12:45 root@web01 /etc/nginx/conf.d]# egrep -n '^user|^group' /etc/php-fpm.d/www.conf
8:user = nginx
10:group = nginx
[12:45 root@web01 /etc/nginx/conf.d]#  systemctl restart php-fpm.service 
[12:45 root@web01 /etc/nginx/conf.d]# ss -lntup|grep 9000
tcp    LISTEN     0      128    127.0.0.1:9000                  *:*                   users:(("php-fpm",pid=9013,fd=9),("php-fpm",pid=9012,fd=9),("php-fpm",pid=9011,fd=9),("php-fpm",pid=9010,fd=9),("php-fpm",pid=9009,fd=9),("php-fpm",pid=9008,fd=7))
[12:45 root@web01 /etc/nginx/conf.d]# ps -ef |grep php 
root       9008      1  1 12:45 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
nginx      9009   9008  0 12:45 ?        00:00:00 php-fpm: pool www
nginx      9010   9008  0 12:45 ?        00:00:00 php-fpm: pool www
nginx      9011   9008  0 12:45 ?        00:00:00 php-fpm: pool www
nginx      9012   9008  0 12:45 ?        00:00:00 php-fpm: pool www
nginx      9013   9008  0 12:45 ?        00:00:00 php-fpm: pool www
root       9017   7472  0 12:45 pts/1    00:00:00 grep --color=auto php

Nginx与PHP之间:

image

5. 切换到blog站点目录下,添加以php结尾的文件
vim info.php
注意php的语法格式

[12:50 root@web01 /etc/nginx/conf.d]# cd /usr/share/nginx/html/blog/
[12:50 root@web01 /usr/share/nginx/html/blog]# vim info.php


浏览器查看网页http://10.0.0.7/info.php

mariadb简单介绍与PHP环境_第1张图片
image.png

如果访问没有显示出来,主要原因就是Nginx没有将请求抛给PHP,主要去看nginx的配置

首先保证02-blog.conf配置文件是在第一位,把其他的配置模块先压缩或注释掉。

image

第二种就是配置的内容是否有错误,是否生效

image

PHP与MySQL之间:

image

6.在blog站点目录下创建第二个文件mysqli.php

[root@web01 /blog]# vim mysqli.php 


然后用浏览器访问网站

http://10.0.0.7/mysqli.php

mariadb简单介绍与PHP环境_第2张图片
image.png

搭建wordpress博客

官网:https://cn.wordpress.org/
wordpress开源博客压缩包链接:
https://pan.baidu.com/s/1KOI3FZV8VY22rxD731pp0g 提取码: 7naq

mariadb简单介绍与PHP环境_第3张图片
image.png

解压后将wordpress下的所有内容移动到blog站点目录下

image

修改权限blog站点目录的属主属组为nginx

[root@web01 ~]#  chown  -R nginx.nginx /usr/share/nginx/html/blog/
[root@web01 ~]# ll -d /usr/share/nginx/html/blog/
drwxr-xr-x 5 nginx nginx 4096 Jun  6 21:03 /usr/share/nginx/html/blog/

浏览器输入网址http://10.0.0.7

image

你可能感兴趣的:(mariadb简单介绍与PHP环境)