在樹莓派3B上安裝web服務(wù)器環(huán)境PHP 7.3 + Nginx + Mariadb

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


Raspbian Buster v4.19版本 2019-06-20更新

一、安裝PHP 7.3

  1. 添加apt源。編輯apt源配置文件:
sudo vi /etc/apt/sources.list.d/raspi.list

在后面加入一行:

deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi
  1. 更新軟件包列表:
sudo apt update
  1. 安裝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即可。

  1. 測試是否安裝成功:
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

  1. 安裝nginx:
sudo apt-get install nginx
  1. 安裝完成后,網(wǎng)站根目錄在/var/www/html, 編輯該目錄下的index.nginx-debian.html文件,寫入Hello, Nginx!。
  2. 測試是否安裝成功:打開瀏覽器輸入http://127.0.0.1,能看到剛剛編輯的Hello, Nginx!說明安裝成功?;蛘呤褂妹钚? curl 127.0.0.1 ,也能夠輸出Hello, Nginx!。

三、配置Nginx解析PHP

  1. 編輯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)]

  2. 修改配置后需要重新加載Nginx配置才能生效:
    sudo nginx -s reload

  3. 測試解析PHP。創(chuàng)建一個文件/var/www/html/index.php,寫入php代碼:

    <?php  
    echo time();
    

    保存后執(zhí)行命令curl 127.0.0.1,返回時間戳即說明Nginx成功解析了php。

四、安裝Mariadb數(shù)據(jù)庫

  1. 安裝數(shù)據(jù)庫:
    sudo apt-get install mariadb-server mariadb-client

  2. 執(zhí)行數(shù)據(jù)庫初始化安裝:
    sudo mysql_secure_installation
    根據(jù)提示設(shè)置root密碼等信息。

  3. 嘗試登錄數(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í)行。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容