为玩客云或树莓派安装LNMP和PhpMyAdmin
一、更換國內源,修改為清華鏡像源(PS. 如果不更換,可能…………)
備份原文件:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak更改系統源文件:
sudo vim /etc/apt/sources.list將原內容注釋掉,然后添加:
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi更改系統源:
sudo vim /etc/apt/sources.list.d/raspi.list將原內容注釋并改為
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui deb-src http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui玩客云:
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiversedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiversedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiversedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse更新軟件包索引
sudo apt-get update sudo apt-get upgrade一、安裝Nginx
安裝Nginx,輸入下面的命令
sudo apt-get install -y nginx安裝完畢后啟動nginx服務:
sudo service nginx restart二、安裝PHP
安裝PHP7.0,輸入下面的命令
sudo apt-get install -y nginx php7.0-fpm php7.0-cli php7.0-curl php7.0-gd php7.0-mcrypt php7.0-cgi php7.0-mysql php7.0-mbstring安裝完畢后啟動php7.0服務
sudo service php7.0-fpm restart三、安裝MySQL(MariaDB)
「重要前提」上面的 “更新軟件包索引” 必須執行成功之后,才能進行安裝
安裝MySQL(MariaDB)
sudo apt-get install mariadb-server運行 mysql_secure_installation 工具:
sudo mysql_secure_installation根據向導指引進行相關設置:
- 第一步: “輸入 root 的當前密碼:”,默認為空,直接按Enter即可;
- 第二步: “設置 root 密碼?”,這里請輸入 Y 并按 Enter。設置 root 登陸密碼確保數據安全。然后向導將要求輸入新密碼和確認密碼。
- 第三步: “刪除匿名用戶?”,輸入 Y 或 N 并按 Enter。
- 第四步: “禁止遠程 root 登錄?”,輸入 Y 或 N 并按 Enter;根據自己需要設置,我這里設置為N。
- 第五步: “刪除測試數據庫并訪問它?”,輸入 Y 或 N 并按 Enter。
開始盡情使用 MySQL 吧:
sudo mysql -u root -p輸入前面設置的密碼并回車,然后……就和我們平時使用的 mysql 一樣了!
四、配置Nginx+PHP+MySQL
1.配置Nginx讓它能處理 PHP
sudo nano /etc/nginx/sites-available/default找到下面這段代碼:
location / {# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.try_files $uri $uri/ =404; }在這段代碼的{}里面,添加一行代碼:index index.html index.htm index.php;
location / {# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.try_files $uri $uri/ =404;index index.html index.htm index.php; }再找到下面的代碼:
#location ~ \.php$ {# include snippets/fastcgi-php.conf;## # With php-fpm (or other unix sockets):# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;# # With php-cgi (or other tcp sockets):# fastcgi_pass 127.0.0.1:9000;#}改為:(注意要去掉location 和 }前面的“#”號)
location ~ \.php$ {# include snippets/fastcgi-php.conf;## # With php-fpm (or other unix sockets):fastcgi_pass unix:/run/php/php7.0-fpm.sock;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;# # With php-cgi (or other tcp sockets):# fastcgi_pass 127.0.0.1:9000;}Ctrl + O 保存再 Ctrl + X 退出。
最后重啟 Nginx 即可:
測試運行php文件,在/var/www/html/目錄下新建一個index.php文件,這里直接su獲取最高權限來完成:
pi@raspberrypi:~ $ su 密碼:《輸入你的root密碼》 root@raspberrypi:/home/pi# cat >/var/www/html/index.php #回車進入編輯狀態 <?php phpinfo(); ?>好了,用瀏覽器打開http:// 樹莓派的IP你就可以看到熟悉的頁面啦!
配置MySQL,允許遠程連接
用shell登錄mysql:
如果遠程連接提示“100061”錯誤,那就繼續修改/etc/mysql/mariadb.conf.d文件夾中的50-server.cnf文件
#用nano打開50-server.cnf sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf#修改其中的bind-address為 bind-address = 0.0.0.0#Ctrl + O 保存再 Ctrl + X 退出,并重啟mysql服務即可生效。 sudo service mysql restart五、安裝PhpMyAdmin
1.要將PHPMyAdmin軟件包安裝到樹莓派中,需要運行以下命令。
sudo apt install phpmyadmin2.PHPMyAdmin現在將開始安裝到樹莓派。在此過程中,系統將會詢問你已經運行的Web服務器類型。
我這里使用的是nginx,所以點擊Esc退出,你可以根據自己的情況選擇
安裝完畢后,再把phpmyadmin鏈接到/var/www/html目錄下
sudo ln -s /usr/share/phpmyadmin /var/www/html瀏覽器打開 http:// 樹莓派ip/phpmyadmin 就可以用root和新密碼登錄管理mysql數據庫了!!
好了,到這里就差不多結束了,遇到問題要多使用搜索引擎搜索哦!不要放棄,慢慢來。
總結
以上是生活随笔為你收集整理的为玩客云或树莓派安装LNMP和PhpMyAdmin的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Cool Edit Pro 2.1 专业
- 下一篇: Windows 10 使用 PowerS