找回密码
 立即注册
首页 资源区 代码 Typecho在Ubuntu 22.04上的安装部署

Typecho在Ubuntu 22.04上的安装部署

拍棹 3 天前

  • 安装Nginx并配置访问
  • 安装PHP并输出脚本结果
  • 配置typecho
Nginx安装并验证
  1. apt install nginx
  2. systemctl start nginx
复制代码
1.png

正常情况应该可以看到Nginx的欢迎页面了,如果看不到就是防火墙的问题,设置下防火墙放通即可。
安装PHP并使用Nginx代理
  1. apt install php-fpm php-curl php-gd php-mbstring php-xml php-sqlite3
复制代码
修改Nginx配置以支持php脚本
  1. index index.php index.html index.htm index.nginx-debian.html;
  2. if (!-e $request_filename) {
  3.         rewrite ^(.*)$ /index.php$1 last;
  4. }
  5. location / {
  6.                 # First attempt to serve request as file, then
  7.                 # as directory, then fall back to displaying a 404.
  8.                 try_files $uri $uri/ =404;
  9. }
  10. # pass PHP scripts to FastCGI server
  11. #
  12. location ~ .*\.php(\/.*)*$ {
  13.                 include snippets/fastcgi-php.conf;
  14.                 set $path_info "";
  15.                 set $real_script_name $fastcgi_script_name;
  16.                 if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
  17.                                 set $real_script_name $1;
  18.                                 set $path_info $2;
  19.                 }
  20.                 # With php-fpm (or other unix sockets):
  21.                 fastcgi_pass unix:/run/php/php8.1-fpm.sock;
  22.                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  23.                 include fastcgi_params;
  24.                 fastcgi_param SCRIPT_NAME $real_script_name;
  25.                 fastcgi_param PATH_INFO $path_info;
  26.                 # With php-cgi (or other tcp sockets):
  27. #       fastcgi_pass 127.0.0.1:9000;
  28. }
复制代码
测试截图
2.png

安装最新Typecho代码

下载源代码
  1. wget https://github.com/typecho/typecho/releases/latest/download/typecho.zip
复制代码
解压到网页根目录安装
  1. unzip typecho.zip
复制代码
访问网站进行安装,发现没有/usr/uploads的权限,需要修改下。
3.png

查看php-fpm的运行用户是www-data所以更改目录所有者为www-data
  1. chown -R www-data:www-data typecho
复制代码
然后刷新页面就可以正确安装了
4.png

安全加固,仅放通必要端口(80,443,21)

查看防火墙的状态,发现默认一个没开
  1. root@web:~# ufw status
  2. Status: inactive
  3. root@web:~# iptables -L -n
  4. Chain INPUT (policy ACCEPT)
  5. target     prot opt source               destination
  6. Chain FORWARD (policy ACCEPT)
  7. target     prot opt source               destination
  8. Chain OUTPUT (policy ACCEPT)
  9. target     prot opt source               destination
复制代码
使用ufw配置规则
  1. ufw default allow outgoing
  2. ufw default deny incoming
  3. ufw allow ssh
  4. ufw allow "Nginx Full"
复制代码
启用ufw
  1. ufw enable
  2. systemctl start ufw
复制代码
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册