树莓派配置Nginx+PHP7+MySQL(MariaDB)环境
最近想⽤树莓派做⼀些web测试,没想到配置的过程⽐我想象的复杂,
我已经尝试写的很简洁了,各位看官随意
1.安装Nginx和php
sudo apt-get update #更新源
sudo apt-get install php7.3 php7.3-fpm php7.3-mysql php7.3-common
sudo apt-get install nginx
sudo service nginx start #重启nginx
sudo service php7.3-fpm restart  #重启php
第⼀⾏更新下载源
最后⼀⾏安装了PHP7.3主体,与Nginx对接的php7.3-fpm插件,与mysql对接的php7.3-mysql插件,常⽤函数⼯具php7.3-common插件.
2.安装MySQL(MariaDB)
sudo apt-get install  mariadb-client-10.0 mariadb-server-10.0
3.配置Nginx+PHP7+MySQL(MariaDB)
3.1.重启服务shell
/etc/init.d/nginx restart #重启nginx
sudo service php7.3-fpm restart  #重启php
service mysql restart
3.2.配置php-fpm
此处需要选择Nginx连接到php服务的形式,tcp模式或者socket模式。
⾸先要到f ⽂件,我的⽂件位置在/etc/php/7.3/fpm/pool.d
编辑f⽂件参考:
安装mysql时start service失败vim  /etc/php/7.3/fpm/pool.f
到参数listen = /run/php/php7.3-fpm.sock
请记住该参数,这将会在配置Nginx时⽤到。
3.3.配置Nginx
修改配置⽂件f参考:
vim /etc/f
#在HTTP{}内有
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
#修改为:
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
以default⽂件为模版,在sites-enabled⽂件夹下建⽴⽹站配置⽂件,shell参考如下:
cd  /etc/nginx/sites-enabled
cp f
f
配置站点信息,参考如下:
location / {
root /home/www;
index index.php index.html;
try_files $uri$uri/ =404;
}
location ~ \.php$ {
root /home/www;
fastcgi_pass  unix:/run/php/php7.3-fpm.sock;#socket mode
#fastcgi_pass  127.0.0.1:9000;#tcp mode
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
include        fastcgi_params;
建议先使⽤<?php phpinfo();?>进⾏测试⼀下
3.4.配置MySQL(MariaDB
php连接mysql失败:安装php7.0-mysql插件。
shell登录mysql:mysql -u root -p默认⽆密码,直接回车
select Host,User,plugin from mysql.user where User='root';
这个时候会发现plugin(加密⽅式)是unix_socket,
>>update mysql.user set plugin='mysql_native_password';  #重置加密⽅式
>>update mysql.user set password=PASSWORD("newpassword") where User='root';  #设置新密码>>  flush privileges;  #刷新权限信息
OK!
3.5.MySQL允许远程访问的设置
sudo vim/etc/f.d/50-serverf
将bind-address = 127.0.0.1 改为: bind-address = 0.0.0.0
update user set host='%'where user='root'and host='localhost';
flush privileges;
OK!
⾄此已全部配置完成

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。