1. 程式人生 > >在樹莓派3B上搭建LAMP

在樹莓派3B上搭建LAMP

style 1-1 實現 err like n) you likely doc

一、安裝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

三、安裝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環境配置完畢!

在樹莓派3B上搭建LAMP