建议系统选用 ubuntu 参考: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04 https://www.typechodev.com/docs/zh_CN/user-guide/install/ https://bbs.huaweicloud.com/blogs/136774

1. 准备一个 wheel 用户组的普通用户

debian 因为 php 版本问题,无法继续安装了。

2. 安装和配置 ufw

sudo apt install ufw
sudo ufw status verbose
sudo ufw app list   
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

参考: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04

3. 安装和配置 nginx, 作为我们的 web 服务器,展示网页

sudo ufw allow 'Nginx HTTP'
sudo ufw status

在浏览器中输入服务器地址,如果能看到 nginx 的欢迎页面,说明就对了。

4. 安装和配置 mysql,保存和管理我们网站的数据

sudo apt-get install mysql-server

5. 添加更新源

apt -y install software-properties-common apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://mirror.xtom.com.hk/sury/php/apt.gpg
sh -c 'echo "deb https://mirror.xtom.com.hk/sury/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'  

sudo apt-get install debian-keyring debian-archive-keyring

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com E9C74FEEA2098A6E 

参考: https://www.zhujiceping.com/16413.html

参考: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04

centos

6.

sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo apt-get install nginx
systemctl status nginx
sudo systemctl start nginx

参考: https://www.cnblogs.com/moxiaoan/p/5683743.html https://blog.csdn.net/QMW19910301/article/details/86628310 https://bbs.huaweicloud.com/blogs/136774

ubuntu server

7. ufw ssh 配置

sudo ufw app list
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

8. 安装 nginx

sudo apt-get update
sudo apt-get install nginx
sudo ufw allow 'Nginx HTTP'
sudo ufw status

9. 安装 mqsql

sudo apt-get install mysql-server

10. 安装 php

sudo apt-get install php-fpm php-mysql

sudo nano /etc/php/7.0/fpm/php.ini
cgi.fix_pathinfo=0

sudo systemctl restart php7.0-fpm
sudo nano /etc/nginx/sites-available/default

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name server_domain_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

这个 root 就是以后 web 文件夹的位置。

sudo nginx -t
sudo systemctl reload nginx
sudo nano /var/www/html/info.php

<?php
phpinfo();

http://server_domain_or_IP/info.php 打开网页,应该能看到 php 的相关信息。

sudo rm /var/www/html/info.php

参考: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04

11. 登录 mqsql 并创建新用户

mysql -uroot -pxxxxxx
create user 'typechouser'@'localhost' identified by 'yyyyyy';
create database typecho;
GRANT ALL ON typecho.* TO 'typechouser'@'localhost';

11. 在 浏览器中输入 ip 地址,和 /install.php 进入 typecho 的安装界面。修改下面几行:

数据库用户名 typechouser 密码 yyyyyy

网站用户名 admin 网站密码 zzzzzz

12. 正常安装完成后,输入 ip 地址,可能会报错 " Call to undefined function utf8_decode() "。 这个问题是 php 找不到相应的函数造成的。解决时,要通过两步:

  • 首先看系统是否支持中文。 locale -a 可以查看系统当前支持哪些,如果不支持中文, ubuntu 可以通过 sudo apt-get -y install language-pack-zh-hans 来安装中文包。安装完成后,locale 检查当前的系统语言配置,最好是如下:
    LANG=en_US.UTF-8
    LANGUAGE=
    LC_CTYPE="en_US.UTF-8"
    LC_NUMERIC=zh_CN.UTF-8
    LC_TIME=zh_CN.UTF-8
    LC_COLLATE="en_US.UTF-8"
    LC_MONETARY=zh_CN.UTF-8
    LC_MESSAGES="en_US.UTF-8"
    LC_PAPER=zh_CN.UTF-8
    LC_NAME=zh_CN.UTF-8
    LC_ADDRESS=zh_CN.UTF-8
    LC_TELEPHONE=zh_CN.UTF-8
    LC_MEASUREMENT=zh_CN.UTF-8
    LC_IDENTIFICATION=zh_CN.UTF-8
    LC_ALL=
  • 安装 php-xml 扩展,首先 php -v 查看当前版本。如果是 7.0 的版本,可以通过 sudo apt-get install php7.0-xml 来安装相应的扩展。安装完成后,刷新网页,即可见效。

参考:https://blog.csdn.net/qq_21840201/article/details/81073129 https://blog.csdn.net/ludengji/article/details/51427219 https://blog.csdn.net/hm_123123123/article/details/107076489

https://blog.csdn.net/qq_21891743/article/details/88970401 https://stackoverflow.com/questions/46531870/call-to-undefined-function-utf8-decode

13. 只能打开主页,打开其他子页面都会404. 这个需要修改 /etc/nginx/sites-available/default 文件。

location / {
    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_split_path_info ^(.+\.php)(/.+)$;
        # With php7.0-cgi alone:
        # fastcgi_pass 127.0.0.1:9000;
        # With php7.0-fpm:
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

整个可以参考:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /usr/share/nginx/typecho;

    index index.php index.html;

    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 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;
        }
        try_files $uri $uri/ =404;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7.0-cgi alone:
        # fastcgi_pass 127.0.0.1:9000;
        # With php7.0-fpm:
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
}

修改完成后,使用 service nginx restart 命令重启 nginx,即可看到效果。

参考: https://my.oschina.net/u/2411391/blog/3137889 https://blog.csdn.net/zqinghai/article/details/71125045 https://blog.csdn.net/c__chao/article/details/79844394 https://blog.csdn.net/funche/article/details/99294581

14. 如果想要取出链接中间的 index.php,可以开启伪静态。首先在后台开启 永久链接中的地址重写功能,然后,选择自己喜欢的链接样式,最后点击保存。会有错误提示,直接勾选确认,重新保存,即可。

参考: https://pangsuan.com/p/typecho_rewrite_url.html https://blog.csdn.net/sakura379/article/details/89946274

15. 如果需要多个网站共存,那么就需要二级目录了。这时候配置就需要更改很多。具体可以参考其他网页。

参考: https://www.itbulu.com/typecho-sub-nginx.html

标签: typecho

添加新评论