标签归档:php

树莓派 Web服务器 LNSP

采用LNSP配置(Linux + Nginx + Sqlite + PHP)

1. Nginx

sudo apt-get install nginx,安装

sudo /etc/init.d/nginx start,启动服务

修改 sudo vim /etc/nginx/sites-available/default 其中的部分内容,其他保持不变。

  1. listen 改为8080端口(为了防止和80端口冲突)
  2. index 增加 index.php
  3. 去除php段落的部分注释
  4. html 所在默认路径, root /var/www/html;
server {
    listen 8080 default_server;
    #listen [::]:8080 default_server;    
 
    root /var/www/html; 

    # Add index.php to the list if you are using PHP 
    index index.php 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; 
    } 

    # pass PHP scripts to FastCGI server 
    # 
    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; 
    } 

    # deny access to .htaccess files, if Apache's document root 
    # concurs with nginx's one 
    # 
    #location ~ /\.ht { 
    #       deny all; 
    #} 
}

sudo /etc/init.d/nginx reload,重载。

这时通过系统自带的浏览器访问127.0.0.1:8080,可以看见nginx初始页面。

2. php和sqlite

sudo apt-get install php-fpm php-sqlite3,安装php和sqlite3。

注意使用 php-fpm 和 php-sqlite3 作为默认参数,可以安装最新版本。

在html所在默认路径,新建文件index.php

<?php echo phpinfo(); ?>

期间遇到了一些问题,最初以为是ngnix和php配置的问题,最后发现是因为最初index.php文件里的语法问题,返回HTTP 500的错误。
通过修改sudo vim /etc/php/7.3/fpm/php.ini 文件中 display_errors = On,可以显示出错误所在,进行修正。

3. 反向代理

使用frp作为内网穿透,因为没有多余的域名,只能通过IP访问,所以在frpc.ini 中添加

[Web]
type = tcp
local_ip = 127.0.0.1
local_port = 8080
remote_port = [remote_port]

使用frp的 server_IP:[remote_port]即可以从外网访问处于内网上的树莓派。

4. nginx和php相关指令

/etc/init.d/php-fpm7.3 {start|stop|status|restart|reload|force-reload}
nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}
0

安装配置vim

检查是否已经安装过vim , 输入rpm -qa|grep vim

  • vim-common
  • vim-enhanced
  • vim-minimal
  • vim-filesystem

表示安装成功,有的centos系统,默认包名不同。

:如果缺少vim-enhanced这个包,执行:yum -y install vim-enhanced 命令,它会自动下载安装。

下载完后,yum -y install vim* 安装

配置方法:

新建 vim ~/.vimrc

编辑内容为:

set nu          "设置行号
set hlsearch        "查找字符串的反白设置值
set autoindent      "自动缩进set cindent
set ruler
set showmode        "显示左下角的状态栏
syntax on       "语法高亮
set smartindent     "为C程序提供自动缩进

"设置缩进为4个空格
set tabstop=4
set softtabstop=4
set shiftwidth=4

参考:

  1. Linux Centos下安装与设置Vim编辑器和基本配置
0

Typecho通过页面模板实现分类、归档标签页

通过独立页面的模板实现导航栏的分类和归档

步骤:

  1. 创建php文件,例 page-category.php, 但文件名不重要
  2. 编辑php内容如下,文章分类、文章归档、标签模板
  3. 上传php文件到 theme/default
  4. 进入typecho后台,创建独立页面,选择模板,ok
  • 文章分类
0