在Manjaro Linux上部署Typecho开发环境

因为后面主题的开发就需要实时修改php文件查看效果了,为了方便开发,我决定在自己的电脑上面设置一个基本的Nginx+PHP环境。对于数据库就使用sqlite好了,只是为了搭建一个本地的typecho作为测试平台。
在配置期间踩了几个坑,记录一下。

软件的安装

非常简单,一条命令梭哈:

pacman -S nginx php php-fpm php-sqlite php-gd

配置软件

因为manjaro和其他发行版不太一样,并且我需要这个web服务器以我的用户权限进行运行,方便我更新文件,所以我们需要做出一些更改。

php.ini

首先是php的配置文件,文件位于/etc/php/php.ini找到下面的部分进修改:
上传大小限制:

upload_max_filesize = 2M

改为

upload_max_filesize = 16M

然后启用必要的模块,找到以下部分取消注释:

extension=curl
extension=gd
extension=gettext
extension=pdo_sqlite

www.conf

然后是php的另一个配置文件,让php-fpm以用户身份运行,文件位于/etc/php/php-fpm.d/www.conf找到下面的部分进修改:

user = chocola   ; <--- 修改这里
group = chocola  ; <--- 修改这里

listen.owner = chocola  ; <--- 修改这里,确保 Nginx 能和 PHP 通讯
listen.group = chocola  ; <--- 修改这里

nginx.conf

将Nginx的配置文件修改为如下所示:


user chocola;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


# Load all installed modules
include modules.d/*.conf;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


        root   /run/media/chocola/DATA/wwwroot;
        index  index.php index.html index.htm;


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ .*\.php(\/.*)*$ {
            # 你的网站根目录 (如果 server 块里已经写了 root,这行可以省略,但加上保险)
            root           /run/media/chocola/DATA/wwwroot;

            fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;

            # 修改点 2:开启路径分割,把 /index.php/action/login 分成两部分
            fastcgi_split_path_info ^(.+?.php)(/.*)$;

            # 修改点 3:重新定义 SCRIPT_FILENAME,使用分割后的变量
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            # 修改点 4:这一行是 Typecho 后台必须的!告诉 PHP 具体的路径信息
            fastcgi_param  PATH_INFO        $fastcgi_path_info;

            include        fastcgi_params;
        }

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


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

主要是让nginx以用户的身份进行运行,并且修改php部分的处理逻辑,以符合Typecho的要求。

设置完成后,就可以把Typecho的安装包丢到目标目录进行安装了!