Typemill 自托管

又一个轻量 CMS

环境

  • Debian 11
    • PHP 7.4
    • Nginx

参考

步骤

运行环境准备

安装 PHP 7.4、Composer 和 Nginx

apt install nginx
apt install php7.4 php7.4-{common,curl,fileinfo,fpm,gd,mbstring,xmlrpc,soap,sqlite3,xml,zip}
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

mv composer.phar /usr/local/bin/composer

配置 Typemill

获取源码

cd /var/www
git clone https://github.com/typemill/typemill.git

安装 PHP 依赖

cd typemill
composer update

设置访问权限

chown -R www-data:www-data typemill/
cd typemill
chmod -R 774 ./cache ./content ./media ./settings

配置 Nginx

在 /etc/nginx/sites-available 下新建配置文件 typemill.conf,写入以下内容

server {
    listen [port];

    # Your domain name
    server_name [IP or domain];

    # document root
    root        /path/to/typemill;

    # Just setting up some log files
    access_log  /var/log/nginx/typemill_access.log;
    error_log   /var/log/nginx/typemill_error.log;

    # Defining what any directory's index file is going to look like
    index       index.php;

    # Set up robots.txt
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # --- EVERYTHING BELOW THIS LINE CAN BE LEFT ALONE

    # This enables PHP in your website
    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }

    # This makes sure PHP query URLs don't break. Usually.
    location / {
        try_files $uri $uri/ /index.php?$args;
        rewrite (.*?)index\.php/*(.*) /$1$2 redirect;
        rewrite (^|/)\.(?!well-known\/) /index.php break;
        rewrite ^/(system|content|data|settings|(media\/files\/)) /index.php break;
    }

    # This makes sure that missing links to image files
    # don't clog up your logs.
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    # The following two rule sets deny direct access to certain files
    # and kinds of files to prevent security issues.

    location ~\.(git|txt|md|yml|md|php|twig)$ {
        deny all;
        return 404;
    }

    location ~ ^/(licence\.md|readme\.md|composer\.lock|composer\.json|\.htaccess)$ {
                deny all;
        return 404;
    }
}

新建软链接

ln -s /etc/nginx/sites-available/typemill.conf /etc/nginx/sites-enabled/

重载 Nginx

nginx -t
nginx -s reload

效果

发表回复

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

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据