如何在树莓派3B+的Raspbian系统中安装LNMP服务

在树莓派3B+上安装Nginx + Mariadb + PHP服务器,搭建网站服务器

一、安装配置Nginx

sudo apt-get install nginx

1. 配置新的路径

server{
listen 8000;
listen [::]:8000;
server_name xxxxx.hello.com;
index index.html index.htm index.php;
root /var/www/html;
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$ {
    # include snippets/fastcgi-php.conf;
    #
      
   # # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    # # With php-cgi (or other tcp sockets):
    # fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;    
    include fastcgi_params;
}}


然后检查语法错误

sudo nginx -t

# 没有错误的情况下重启nginx服务

sudo systemctl restart nginx

# 随即给防火墙添加端口

sudo ufw allow 8000
// sudo ufw reload
// 后来我发现不需要reload也可以生效

2. 修改文件夹权限

  1. Make sure all files are owned by the Apache group and user. In Ubuntu it is the www-data group and userchown -R www-data:www-data /path/to/webserver/www
  2. Next enabled all members of the www-data group to read and write fileschmod -R g+rw /path/to/webserver/www

二、安装php

# 查询php7.x的可用版本
sudo apt list | grep php7

# 安装
sudo apt-get install php7.x-fpm php7.x-cli php7.x-mysql php7.x-curl php7.x-gd php7.x-cgi


三、安装配置mariadb

# 安装
sudo apt-get install mariadb-server mariadb-client
# 启动数据库
sudo systemctl start mariadb
# 检查启动情况
sudo systemctl status mariadb
# 初始化-修改密码和进行基本配置
sudo mysql_secure_installation


四、收尾工作

# 设置开机启动
sudo systemctl enable nginx
sudo systemctl enable mariadb
# 设置防火墙端口
sudo ufw allow 80
sudo ufw reload

暂无评论

发表评论

您的电子邮件地址不会被公开,必填项已用*标注。

相关推荐