原文地址:http://blog.sina.com.cn/s/blog_150f554f50102yhra.html
一.安裝 Nginx 和 PHP7
1、安裝Nginx
sudo apt install -y nginx
sudo systemctl restart nginx
2、安裝PHP7
sudo apt install -y php7.0-fpm php7.0-cli php7.0-curl php7.0-gd php7.0-mcrypt php7.0-cgi php7.0-mysql
sudo systemctl restart php7.0-fpm
3、安裝成功,可通過 http://IP 訪問到 Nginx 的默認頁。Nginx 的根目錄在/var/www/html。
配置 Nginx 來讓 Nginx 能處理 PHP
4、編輯
sudo vim /etc/nginx/sites-available/default
# 將其中的如下內容
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
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.nginx-debian.html index.php;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~\.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
client_max_body_size 256m;
5、修改一下上傳文件大小限制:
# 打開配置文件
sudo vim /etc/php/7.0/fpm/php.ini
# 每個腳本運行的最長時間,單位秒,0為無限
max_execution_time = 0
# 每個腳本可以消耗的時間,單位也是秒
max_input_time = 300
# 腳本運行最大消耗的內存
memory_limit = 256M
# 表單提交最大數據為 8M,針對整個表單的提交數據進行限制的
post_max_size = 20M
# 上載文件的最大許可大小
upload_max_filesize = 10M
6、配置php-fpm
需要選擇Nginx連接到php服務的形式,tcp模式或者socket模式。
找到www.conf文件,不同的平台會導致文件位置不同。
我的在/etc/php/7.0/fpm/pool.d,
還有在etc/php-fpm.d的。
編輯www.conf文件參考:
vim /etc/php/7.0/fpm/pool.d/www.conf
找到參數listen = /run/php/php7.0-fpm.sock
如果參數對應的是XXXX.sock說明php-fpm是通過socket模式與Nginx聯絡的。
如果參數對應的是127.0.0.1說明php-fpm是通過socket模式與Nginx聯絡的。
可以根據自己的需要進行修改,請記住該參數,這將會在配置Nginx時用到。
7、重啟 Nginx
sudo service nginx restart
8、添加一個PHP測試文件
sudo vim /var/www/html/index.php
9、mysql配置遠程登錄的權限
方法一: 設置新遠程用戶
CREATE USER 'user'@'%' IDENTIFIED BY 'user';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'user' WITH GRANT OPTION;
FLUSH PRIVILEGES;
方法二: 直接修改root用戶的遠程權限
USE mysql;
UPDATE user SET host = '%' WHERE user = 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;
FLUSH PRIVILEGES;
‘[用戶名]’@’[可訪問的ip,%為全部]’ identified by ‘[密碼]’, 該表之后應該就不用授權了,但為了確保,我就又授權了一遍。
完成之后退出數據庫
exit;
打開 /etc/mysql/mariadb.conf.d/50-server.cnf
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
注釋掉bind-addres會改成0.0.0.0
10、安裝phpmyadmin
# 下載
wget https://files.phpmyadmin.net/phpMyAdmin/4.8.0.1/phpMyAdmin-4.8.0.1-all-languages.tar.gz
tar zxvf phpMyAdmin-4.8.0.1-all-languages.tar.gz
# 移動
sudo mv phpMyAdmin-4.8.0.1-all-languages /var/www/html/mysql
# 復制一個配置文件
cd /var/www/html/mysql
sudo cp config.sample.inc.php config.inc.php
# 並 `localhost` 修改為`127.0.0.1`
sudo nano config.inc.php
# 安裝php7.0-mbstring
sudo apt install -y php7.0-mbstring
三、相關命令
sudo chmod -R 777
sudo systemctl restart php7.0-fpm
sudo service nginx restart
/etc/init.d/nginx restart
/etc/init.d/php7-fpm restart
service mysql restart
樹莓派上的lnmp,建立網站》解決phpmyadmin無法訪問樹莓派上mysql的問題https://blog.csdn.net/qq_15947947/article/details/79638050
樹莓派UFW防火牆簡單設置
http://shumeipai.nxez.com/2014/06/09/simple-raspberry-pi-ufw-firewall-settings.html
https://www.cnblogs.com/jikexianfeng/p/6899572.html
樹莓派SSH連接-SSH服務安裝與開機自動啟動
https://blog.csdn.net/qq813480700/article/details/71597808
樹莓派設置中文顯示
https://blog.csdn.net/dear521520/article/details/78357705
樹莓派 中文亂碼 解決方法
https://blog.csdn.net/y511374875/article/details/73548195
(NGINX+PHP+MYSQL5.7)環境搭建
https://blog.csdn.net/kxwinxp/article/details/80299429