Ubuntu安装typecho博客

Ubuntu安装typecho博客

简介

名称的来历

Typecho 是由 type 和 echo 两个词合成的,来自于开发团队的头脑风暴。

Type,有打字的意思,博客这个东西,正是一个让我们通过打字,在网络上表达自己的平台。Echo,意思是回声、反馈、共鸣,也是PHP里最常见、最重要的函数,相信大部分PHP爱好者都是从 echo 'Hello,world!'; 开始自己的PHP编程之路的。

Typecho 是国内开发者开发的一款开源免费的动态博客程序,可以运行在基于 PHP 环境的各种平台上。

相比于同为动态博客并且广为人知的 WordPress 来说,Typecho 的一大特点就是 “精简”。全部文件不足 500KB,但却也实现了完整的主题和插件支持。博客程序很轻量,资源占用也很低,原生支持 Markdown 语法。属于省心并且简洁的博客类型。

安装所需环境

# 安装PHP所需插件
# 添加ppa源
add-apt-repository ppa:ondrej/php
apt install nginx php7.4 php7.4-mysql php7.4-fpm

下载安装主程序

# 进入网站所在目录
root@cby:~# cd /var/www/html/
root@cby:/var/www/html# ls
index.nginx-debian.html  index.php  php.php
root@cby:/var/www/html# ll
total 20
drwxr-xr-x 2 root root 4096 Dec  6 16:29 ./
drwxr-xr-x 3 root root 4096 Dec  6 16:01 ../
-rw-r--r-- 1 root root  612 Dec  6 16:01 index.nginx-debian.html
-rw-r--r-- 1 root root   20 Dec  6 16:29 php.php
root@cby:/var/www/html# 

# 下载安装包
root@cby:/var/www/html# wget https://mirrors.chenby.cn/https://github.com/typecho/typecho/releases/latest/download/typecho.zip
--2023-12-06 16:35:48--  https://mirrors.chenby.cn/https://github.com/typecho/typecho/releases/latest/download/typecho.zip
Resolving mirrors.chenby.cn (mirrors.chenby.cn)... 172.67.134.246, 104.21.25.253, 2606:4700:3032::ac43:86f6, ...
Connecting to mirrors.chenby.cn (mirrors.chenby.cn)|172.67.134.246|:443... connected.
HTTP request sent, awaiting response... 302 Found
Cookie coming from mirrors.chenby.cn attempted to set domain to github.com
Cookie coming from mirrors.chenby.cn attempted to set domain to github.com
Location: /https://github.com/typecho/typecho/releases/download/v1.2.1/typecho.zip [following]
--2023-12-06 16:35:49--  https://mirrors.chenby.cn/https://github.com/typecho/typecho/releases/download/v1.2.1/typecho.zip
Reusing existing connection to mirrors.chenby.cn:443.
HTTP request sent, awaiting response... 200 OK
Length: 610472 (596K) [application/octet-stream]
Saving to: ‘typecho.zip’

typecho.zip                           100%[=======================================================================>] 596.16K   935KB/s    in 0.6s    

2023-12-06 16:35:50 (935 KB/s) - ‘typecho.zip’ saved [610472/610472]

# 解压安装包
root@cby:/var/www/html# unzip typecho.zip 
Archive:  typecho.zip
  inflating: LICENSE.txt             
   creating: admin/
  inflating: admin/editor-js.php     
  inflating: admin/table-js.php      
  inflating: admin/options-general.php  
      ******略******
  inflating: var/Widget/Contents/Page/Rows.php  
  inflating: var/Widget/Contents/Page/Admin.php  
  inflating: var/Widget/Contents/Page/Edit.php  
  inflating: var/Widget/XmlRpc.php   
root@cby:/var/www/html# 
root@cby:/var/www/html# 
root@cby:/var/www/html# 

# 添加权限
root@cby:/var/www/html# chmod 777 * -R

修改配置

# 修改NGINX配置
vim /etc/nginx/nginx.conf
#添加路由信息
--------------- 略 ---------------
        if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
            }
            if (-f $request_filename/index.php) {
            rewrite (.*) $1/index.php;
            }
            if (!-f $request_filename) {
            rewrite (.*) /index.php;
            }
            
        location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                    include        fastcgi_params;
                    fastcgi_intercept_errors  on;
            }
--------------- 略 ---------------

重启服务

# 设置开机自启
root@cby:~# systemctl enable nginx
Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nginx
# 重启NGINX
root@cby:~# systemctl restart nginx
# 查看状态
root@cby:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-12-08 10:09:31 CST; 42s ago
       Docs: man:nginx(8)
    Process: 632604 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 632605 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 632606 (nginx)
      Tasks: 5 (limit: 3943)
     Memory: 112.5M
        CPU: 108ms
     CGroup: /system.slice/nginx.service
             ├─632606 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ├─632607 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─632608 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─632609 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             └─632610 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Dec 08 10:09:31 cby systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 08 10:09:31 cby systemd[1]: Started A high performance web server and a reverse proxy server.
root@cby:~# 


# 设置开机自启
root@cby:~# systemctl enable php7.4-fpm
Synchronizing state of php7.4-fpm.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable php7.4-fpm
# 重启PHP-FPM
root@cby:~# systemctl restart php7.4-fpm
# 查看状态
root@cby:~# systemctl status php7.4-fpm.service 
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-12-08 10:11:02 CST; 2s ago
       Docs: man:php-fpm7.4(8)
    Process: 633187 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/SUCCESS)
   Main PID: 633184 (php-fpm7.4)
     Status: "Ready to handle connections"
      Tasks: 3 (limit: 3943)
     Memory: 11.0M
        CPU: 64ms
     CGroup: /system.slice/php7.4-fpm.service
             ├─633184 "php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─633185 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             └─633186 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >

Dec 08 10:11:02 cby systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
Dec 08 10:11:02 cby systemd[1]: Started The PHP 7.4 FastCGI Process Manager.
root@cby:~# 

我的NGINX配置文件

# NGINX配置文件
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
}

http {

    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;


    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;

    log_format  main '{ "@timestamp": "$time_local", '
                        '"remote_addr": "$remote_addr",'
                        '"remote_port": "$remote_port",'
                        '"scheme": "$scheme",'
                        '"request_uri": "$request_uri",'
                        '"request_method": "$request_method",'
                        '"request_time": "$request_time",'
                        '"request_length": "$request_length",'
                        '"response_status": "$status",'
                        '"body_bytes_sent": "$body_bytes_sent",'
                        '"http_referer": "$http_referer",'
                        '"http_user_agent": "$http_user_agent",'
                        '"http_x_forwarded_for": "$http_x_forwarded_for",'
                        '"upstream_addr": "$upstream_addr",'
                        '"upstream_response_time": "$upstream_response_time",'
                        '"request_body": "$request_body"}';


    server {
        listen 80 default_server;
        listen [::]:80 default_server;
            
        listen 443 ssl http2;
        listen [::]:443 ssl http2;

        ssl_certificate    /ssl/cert.pem;
        ssl_certificate_key    /ssl/cert.key;
        ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
        ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256;
        ssl_prefer_server_ciphers on;
        ssl_session_timeout 10m;
        ssl_session_cache shared:SSL:10m;
        ssl_buffer_size 2k;
        add_header Strict-Transport-Security max-age=15768000;
        ssl_stapling on;
        ssl_stapling_verify on;


        error_log /var/logs/nginx-error.log info;
        access_log /var/logs/nginx-access.log main;

        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        
        server_name _;
        
        location / {
            try_files $uri $uri/ =404;
        }
            
        if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
            }
            if (-f $request_filename/index.php) {
            rewrite (.*) $1/index.php;
            }
            if (!-f $request_filename) {
            rewrite (.*) /index.php;
            }
            
        location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                    include        fastcgi_params;
                    fastcgi_intercept_errors  on;
            }
    }
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,684评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,143评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,214评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,788评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,796评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,665评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,027评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,679评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,346评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,664评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,766评论 1 331
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,412评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,015评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,974评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,073评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,501评论 2 343

推荐阅读更多精彩内容