日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

为玩客云或树莓派安装LNMP和PhpMyAdmin

發(fā)布時(shí)間:2023/12/29 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 为玩客云或树莓派安装LNMP和PhpMyAdmin 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、更換國內(nèi)源,修改為清華鏡像源(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

更改系統(tǒng)源文件:

sudo vim /etc/apt/sources.list

將原內(nèi)容注釋掉,然后添加:

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

更改系統(tǒng)源:

sudo vim /etc/apt/sources.list.d/raspi.list

將原內(nèi)容注釋并改為

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

安裝完畢后啟動(dòng)nginx服務(wù):

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

安裝完畢后啟動(dòng)php7.0服務(wù)

sudo service php7.0-fpm restart

三、安裝MySQL(MariaDB)

「重要前提」上面的 “更新軟件包索引” 必須執(zhí)行成功之后,才能進(jìn)行安裝

安裝MySQL(MariaDB)

sudo apt-get install mariadb-server

運(yùn)行 mysql_secure_installation 工具:

sudo mysql_secure_installation

根據(jù)向?qū)е敢M(jìn)行相關(guān)設(shè)置:

  • 第一步: “輸入 root 的當(dāng)前密碼:”,默認(rèn)為空,直接按Enter即可;
  • 第二步: “設(shè)置 root 密碼?”,這里請輸入 Y 并按 Enter。設(shè)置 root 登陸密碼確保數(shù)據(jù)安全。然后向?qū)⒁筝斎胄旅艽a和確認(rèn)密碼。
  • 第三步: “刪除匿名用戶?”,輸入 Y 或 N 并按 Enter。
  • 第四步: “禁止遠(yuǎn)程 root 登錄?”,輸入 Y 或 N 并按 Enter;根據(jù)自己需要設(shè)置,我這里設(shè)置為N。
  • 第五步: “刪除測試數(shù)據(jù)庫并訪問它?”,輸入 Y 或 N 并按 Enter。

開始盡情使用 MySQL 吧:

sudo mysql -u root -p

輸入前面設(shè)置的密碼并回車,然后……就和我們平時(shí)使用的 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 即可:

sudo service nginx restart

測試運(yùn)行php文件,在/var/www/html/目錄下新建一個(gè)index.php文件,這里直接su獲取最高權(quán)限來完成:

pi@raspberrypi:~ $ su 密碼:《輸入你的root密碼》 root@raspberrypi:/home/pi# cat >/var/www/html/index.php #回車進(jìn)入編輯狀態(tài) <?php phpinfo(); ?>

好了,用瀏覽器打開http:// 樹莓派的IP你就可以看到熟悉的頁面啦!

配置MySQL,允許遠(yuǎn)程連接
用shell登錄mysql:

#默認(rèn)無密碼,直接回車 mysql -u root -p#設(shè)置允許遠(yuǎn)程連接并修改root密碼,123456為root用戶的新密碼,%代表所有主機(jī) UPDATE mysql.user SET host='%',authentication_string=PASSWORD('123456'), PLUGIN='mysql_native_password' WHERE USER='root';#刷新權(quán)限 FLUSH PRIVILEGES;#退出myslq exit#重啟mysql服務(wù) sudo service mysql restart

如果遠(yuǎn)程連接提示“100061”錯(cuò)誤,那就繼續(xù)修改/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服務(wù)即可生效。 sudo service mysql restart

五、安裝PhpMyAdmin

1.要將PHPMyAdmin軟件包安裝到樹莓派中,需要運(yùn)行以下命令。

sudo apt install phpmyadmin

2.PHPMyAdmin現(xiàn)在將開始安裝到樹莓派。在此過程中,系統(tǒng)將會(huì)詢問你已經(jīng)運(yùn)行的Web服務(wù)器類型。

我這里使用的是nginx,所以點(diǎn)擊Esc退出,你可以根據(jù)自己的情況選擇

安裝完畢后,再把phpmyadmin鏈接到/var/www/html目錄下

sudo ln -s /usr/share/phpmyadmin /var/www/html

瀏覽器打開 http:// 樹莓派ip/phpmyadmin 就可以用root和新密碼登錄管理mysql數(shù)據(jù)庫了!!

好了,到這里就差不多結(jié)束了,遇到問題要多使用搜索引擎搜索哦!不要放棄,慢慢來。

總結(jié)

以上是生活随笔為你收集整理的为玩客云或树莓派安装LNMP和PhpMyAdmin的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。