zoukankan      html  css  js  c++  java
  • 在树莓派3B上搭建LAMP

    一、安装apache2

    sudo apt-get install apache2

    在电脑上输入树莓派的网址会有如下显示

    二、安装Mysql

    sudo apt-get install mysql-server

    安装过程中需要输入管理员密码

    1. 测试mysql

    pi@raspberrypi:~ $ mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 43
    Server version: 5.5.57-0+deb8u1 (Raspbian)
    
    Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    进入mysql数据库,并输入密码。

    mysql> show databases
        -> ;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.00 sec)

    查看已经建立的数据库

    2.创建一个新的数据库和表单

    以上数据库都是系统建立的数据库,要想开始插入数据,首先需要建立新的数据库和表单。这里假设要实现一个CPU温度记录的功能,存放在名为"sensordb"的数据库中。使用以下命令建立数据库:

    mysql> create database sensordb
        -> ;
    Query OK, 1 row affected (0.00 sec)

    查看数据库是否建立成功:

    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sensordb           |
    +--------------------+
    4 rows in set (0.00 sec)

    在sensordb数据库下创建一个表单(table),该表单包含两个域(fields):日期和当天平均CPU温度。时间域使用的数据格式为DATE;而温度使用DECIMAL(4,1),即最大三位整数加一位小数。

    mysql> use sensordb
    Database changed
    mysql> create table cputemptable(recordtime DATE, temp DECIMAL(4,1));
    Query OK, 0 rows affected (0.01 sec)

    查看表单是否建立成功:

    mysql> show tables
        -> ;
    +--------------------+
    | Tables_in_sensordb |
    +--------------------+
    | cputemptable       |
    +--------------------+
    1 row in set (0.00 sec)

    查看表单的域名称与类型:

    mysql> describe cputemptable
        -> ;
    +------------+--------------+------+-----+---------+-------+
    | Field      | Type         | Null | Key | Default | Extra |
    +------------+--------------+------+-----+---------+-------+
    | recordtime | date         | YES  |     | NULL    |       |
    | temp       | decimal(4,1) | YES  |     | NULL    |       |
    +------------+--------------+------+-----+---------+-------+
    2 rows in set (0.00 sec)

    3.向数据库中插入测试数据

    在上一步中已经成功建立了用于CPU温度采集的数据库和表单,但是因为没有任何数据,所以该表单中没有任何内容。现在通过手动插入的方式向该表单中插入若干数据,测试是否可以正常运行。

    mysql> insert into cputemptable
        -> values('2018-01-11', 36.5);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> insert into cputemptable
        -> values('2018-01-12', 39.0);
    Query OK, 1 row affected (0.01 sec)

    查看数据库的结果

    为了验证以上数据是否成功插入,可以通过select语句检索数据库:

    mysql> select * from cputemptable;
    +------------+------+
    | recordtime | temp |
    +------------+------+
    | 2018-01-11 | 36.5 |
    | 2018-01-12 | 39.0 |
    +------------+------+
    2 rows in set (0.00 sec)

    可以看到之前的两条数据已经成功插入到cputemptable数据表中。最后使用quit退出交互系统:

    mysql> quit
    Bye

     4.支持远程连接

    默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件。

    一、修改/etc/mysql/my.conf
    找到bind-address = 127.0.0.1这一行
    改为bind-address = 0.0.0.0即可

    二、为需要远程登录的用户赋予权限
    1、新建用户远程连接mysql数据库
    grant all on *.* to admin@'%' identified by '123456' with grant option; 
    flush privileges;
    允许任何ip地址(%表示允许任何ip地址)的电脑用admin帐户和密码(123456)来访问这个mysql server。
    注意admin账户不一定要存在。

    2、支持root用户允许远程连接mysql数据库
    grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
    flush privileges;

    三、安装PHP

    安装PHP和PHP的MySQL插件

    sudo apt-get install php5 php5-mysql

    安装phpmyadmin,用于管理数据库

    sudo apt-get install phpmyadmin

    这里要选择一下我们刚才安装的Apache2,按空格选择哦,选中后前面会多出一个*星号

    没看懂是什么,建议选否

    The phpmyadmin package must have a database installed and configured before it can be used.
    phpmyadmin包必须在它被使用之前安装和配置一个数据库。
    
    This can be optionally handled with dbconfig-common.
    可以使用dbconfig-common来处理这一问题。
    
    If you are an advanced database administrator and know that you want to perform this configuration manually, or if your database has already been installed and configured, you should refuse this option.
    如果您是一个高级的数据库管理员,并且知道您想要手动执行这个配置,或者您的数据库已经安装和配置好了,那么您应该拒绝这个选项。
    
    Details on what needs to be done should most likely be provided in /usr/share/doc/phpmyadmin.
    具体需要做什么最有可能应该/usr/share/doc/phpmyadmin中提供。
    View Code

    至此,一个Apache2+PHP+MySQL+phpyadmin环境配置完毕!

    无欲速,无见小利。欲速,则不达;见小利,则大事不成。
  • 相关阅读:
    文件操作小练习
    阶段练习1
    copy小练习
    小练习
    str 小列题
    条款50:使用自定义的new以及delete的时机会
    条款49:了解new-handle行为
    简单的说一下:tarits技法就是一种模板元编程,起可以将本来处于运行期的事拉到编译期来做,增加了运行效率。 看以非模板元编程的例子,就是前面的那个例子:
    条款47:请使用traits class表示类型信息
    条款46:需要类型转换的时候请为模板定义非成员函数
  • 原文地址:https://www.cnblogs.com/ch122633/p/8267025.html
Copyright © 2011-2022 走看看