樹莓派介紹:PHP開發環境搭建(LAMP)

在樹莓派中搭建PHP開發環境,需要安裝apache2, MariaDB, php7

準備

硬件:樹莓派3B+

系統:Linux raspberrypi 4.19.57

更新源

sudo apt-get update
樹莓派介紹:PHP開發環境搭建(LAMP)

搭建LAMP

  • 安裝apache2
\tsudo apt-get install apache2

測試apache是否安裝成功

\thttp://樹莓派的IP
樹莓派介紹:PHP開發環境搭建(LAMP)

  • 安裝MariaDB

MariaDB數據庫管理系統是MySQL的一個分支,主要由開源社區在維護,採用GPL授權許可。開發這個分支的原因之一是:甲骨文公司收購了MySQL後,有將MySQL閉源的潛在風險,因此社區採用分支的方式來避開這個風險。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕鬆成為MySQL的代替品。

MariaDB由MySQL的創始人麥克爾·維德紐斯主導開發,他早前曾以10億美元的價格,將自己創建的公司MySQL賣給了SUN,此後,隨著SUN被甲骨文收購,MySQL的所有權也落入Oracle的手中。

如果想安Mysql, 目前是沒有源可以安裝。

sudo apt-get install mariadb-server

測試MariaDB是否安裝成功

sudo mysql

出現如下信息,就代表安裝成功

Welcome to the MariaDB monitor. Commands end with ; or \\g.

Your MariaDB connection id is 42

Server version: 10.3.15-MariaDB-1 Raspbian testing-staging

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.

MariaDB [(none)]>

  • 安裝PHP

因php5沒有源可以安裝,默認安裝是php7的版本.

sudo apt-get install php-pear
  • 安裝phpmyadmin
sudo apt-get install phpmyadmin
sudo chmod 777 /var/www/html
sudo a2enmod rewrite
sudo ln –s /usr/share/phpmyadmin /var/www/html

安裝過程中出現的對話框選擇:

第一次的彈框有apache和lightd兩個選項,按空格選中Apache2,按回車。第二次選擇no。

樹莓派介紹:PHP開發環境搭建(LAMP)

  • 配置密碼訪問MariaDB
sudo mysql
use mysql;
UPDATE user SET password=password(‘密碼’) WHERE user = ‘root’;
UPDATE user SET password=’mysql_native_password’ WHERE user = ‘root’;
flush privileges;
exit

以上執行完成後,重啟服務

Sudo systemctl restart mariadb

重啟完成後,用密碼進行mariadb登錄,驗證是否修改成功

mysql –u root –p
  • 配置遠程連接MariaDB

MariaDB默認只監聽了127.0.0.1這個IP地址,這個時候是無法從外部連接到樹莓派上的MariaDB。打開配置文件:

suto nano /etc/mysql/mariadb.conf.d/50-server.cnf

# Instead of skip-networking the default is now to listen only on

# localhost which is more compatible and is not less secure.

# bind-address = 127.0.0.1

bind-address表示只監聽了127.0.0.1這個IP,將這一行的前面加上# 將這一行註釋起來,這樣MariaDB就監聽了所有的IP。

最後,測試,遊覽器訪問:

http://樹莓派ip地址/phpmyadmin

樹莓派介紹:PHP開發環境搭建(LAMP)

在/var/www/html 中創建一個test.php

test.php寫入以下代碼

 echo phpinfo(); 

?>

在瀏覽器中輸入: http://樹莓派ip地址/test.php,出現以下圖,代表php開發搭建環境全部完成。

樹莓派介紹:PHP開發環境搭建(LAMP)


分享到:


相關文章: