树莓派安装配置Nginx+PHP7+MariaDB

原文地址: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