在樹莓派3B上搭建網(wǎng)站服務(wù)器環(huán)境,本次安裝基于:

一、安裝PHP 7.3
- 添加apt源。編輯apt源配置文件:
sudo vi /etc/apt/sources.list.d/raspi.list
在后面加入一行:
deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi
- 更新軟件包列表:
sudo apt update
- 安裝PHP7.3:
sudo apt install -y -t buster php7.3-fpm php7.3-curl php7.3-gd php7.3-intl php7.3-mbstring php7.3-mysql php7.3-imap php7.3-opcache php7.3-sqlite3 php7.3-xml php7.3-xmlrpc php7.3-zip
安裝過程中會提示某些服務(wù)需要重啟,選擇Yes即可。
- 測試是否安裝成功:
php -v
如果顯示php版本號,則安裝成功,如下:
PHP 7.3.2-3 (cli) (built: Feb 8 2019 15:05:54) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.2-3, Copyright (c) 1999-2018, by Zend Technologies
二、安裝Nginx
- 安裝nginx:
sudo apt-get install nginx
- 安裝完成后,網(wǎng)站根目錄在
/var/www/html, 編輯該目錄下的index.nginx-debian.html文件,寫入Hello, Nginx!。 - 測試是否安裝成功:打開瀏覽器輸入
http://127.0.0.1,能看到剛剛編輯的Hello, Nginx!說明安裝成功?;蛘呤褂妹钚?curl 127.0.0.1,也能夠輸出Hello, Nginx!。
三、配置Nginx解析PHP
-
編輯Nginx配置文件
sudo vi /etc/nginx/sites-enabled/default, 找到# pass PHP scripts to FastCGI server, 在后面加入以下代碼:location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.3-fpm.sock; }然后在
index指令后面加上index.php,修改后文件內(nèi)容如下:[圖片上傳中...(image-2a2aec-1562901999837-0)] 修改配置后需要重新加載Nginx配置才能生效:
sudo nginx -s reload-
測試解析PHP。創(chuàng)建一個文件
/var/www/html/index.php,寫入php代碼:<?php echo time();保存后執(zhí)行命令
curl 127.0.0.1,返回時間戳即說明Nginx成功解析了php。
四、安裝Mariadb數(shù)據(jù)庫
安裝數(shù)據(jù)庫:
sudo apt-get install mariadb-server mariadb-client執(zhí)行數(shù)據(jù)庫初始化安裝:
sudo mysql_secure_installation
根據(jù)提示設(shè)置root密碼等信息。-
嘗試登錄數(shù)據(jù)庫:
mysql -u root -p
輸入上一步設(shè)置的密碼,發(fā)現(xiàn)無法登錄,錯誤提示如下:ERROR 1698 (28000): Access denied for user 'root'@'localhost'原因: 數(shù)據(jù)庫默認(rèn)使用系統(tǒng)用戶登錄,需要修改為使用密碼登錄。
解決方案:sudo mysql -u root,登入數(shù)據(jù)庫后,依次執(zhí)行以下代碼:
use mysql #切換到mysql數(shù)據(jù)庫update user set plugin='mysql_native_password'; #修改plugin字段flush privileges; #刷新權(quán)限
exit; #退出數(shù)據(jù)庫再次使用
mysql -u root -p即可通過密碼登錄數(shù)據(jù)庫,無需root權(quán)限執(zhí)行。