博客

How To Upgrade To PHP7.4-FPM in Ubuntu 16.04/18.04

This will upgrade your php version to php7.4-fpm when using Nginx web server.

Check your PHP version:

$ php -v

1. Install PHP 7.4

$ sudo apt install php7.4-fpm

2. Install additional modules

$ sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

3. Update config files

Open the file located at /etc/php/7.4/fpm/pool.d/www.conf:

$ sudo nano /etc/php/7.4/fpm/pool.d/www.conf

Find the lines below:

;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp

and delete the semi-colons so that it looks like this:

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

Ctrl+x to exit, then ‘Y' to save and exit.

Then, open the file located at /etc/php/7.4/fpm/php.ini:

$ sudo nano /etc/php/7.4/fpm/php.ini

find (Ctrl+w) and change the following to your desired settings:

max_execution_time = 300
memory_limit = 512M
post_max_size = 100M
upload_max_filesize = 100M

and find the line:

;cgi.fix_pathinfo=1

and delete the semicolon and set to 0:

cgi.fix_pathinfo=0

Ctrl+x to exit, then ‘Y' to save and exit.

3. Web server configuration

Make sure that your web server correctly uses the PHP 7.4 sockets/modules. Edit your nginx config to change the socket paths (substituting ‘nginx_vhost' with your correct filename, i.e. ‘default'):

$ sudo nano /etc/nginx/sites-available/nginx_vhost

For example, change the lines below from php7.3 to php7.4:

...
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
...

Ctrl+x, then ‘y' to save and exit. Restart PHP and Nginx:

$ sudo systemctl restart php7.4-fpm
$ sudo service nginx restart

4. Change the default PHP version

If you have multiple PHP versions installed on your Ubuntu server, you can set PHP 7.2 as the default:

$ sudo update-alternatives --set php /usr/bin/php7.4

Link:

CSDN未登录禁止复制解决办法

不知道何时开始CSDN的内容需要登录后才能复制,这对我这种面相搜索引擎编程的人十分不友好。不过网页上根本禁止不了,懂的都懂,基本上都是靠JS来实现的,只需禁用JS即可破解,下面是网友提供的两种解决CSDN未登录禁止复制的办法。

方法一

打开一个CSDN网站,按下F12进入开发者模式。注意此模式在IE内核中无效。然后在开发者模式中选择Console面板,复制如下命令粘贴并回车执行。

javascript:document.body.contentEditable='true';document.designMode='on';

方法二

打开一个CSDN网站,按下F12进入开发者模式。注意此模式在IE内核中无效。然后在开发者模式中选择Elements面板,找到 id="content_views" 这句,将其中的 content_views 删除或者重命名即可。双击即可修改。

Link:

Typecho Nginx下的伪静态rewrite规则

Typecho Nginx下的伪静态rewrite规则

设置 -- 永久链接 -- 是否使用地址重写功能 打开地址重写功能,如果提示 重写功能检测失败,请检查你的服务器设置,选择仍然启用此功能,勾选即可

在 Nginx server 里添加以下配置:

location / {
    index index.html index.php;
    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;
    }
}

通过 Jenkins 和 gogs 自动发布 Hugo 博客到 VPS

Hugo 博客是使用 Go 语言编写的静态博客引擎,可以快速将 markdown 博文转换成 HTML 文件。

环境:Ubuntu 16.4 + Nginx

Jenkins 的安装

  • . 安装 Jenkins :
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
  • . 通过命令进行升级:
sudo apt-get update
sudo apt-get install jenkins
  • . 通过命令来启动、停止Jenkins:
sudo service jenkins start   # 启动Jenkins
sudo service jenkins stop    # 停止Jenkins
sudo service jenkins restart # 重启Jenkins
  • . 访问Jenkins:
http://localhost:8080
  • . 查看Jenkins 文件路径:
配置文件:/etc/default/jenkins
安装路径:/var/lib/jenkins
日志路径:/var/log/jenkins

Jenkins 安装好后,默认端口是8080,如果发现使用上述路径 ( http://localhost:8080 ) 无法访问Jenkins,可能是因为其他的程序占用了该端口,需要修改为其他的端口:

修改文件:/etc/default/jenkins

HTTP_PORT=8081

然后重新启动Jenkins :

sudo service jenkins restart

然后根据Jenkins 提示进行配置

使用 Nginx 进行方向代理

在 Nginx 配置目录: /etc/nginx/conf.d 添加配置文件:

server {
    listen       443;
    server_name  Jenkins;
    debug_http;
    client_max_body_size 60M;
    client_body_buffer_size 512k;
    location / {
        proxy_pass
        http://localhost:8081;
        proxy_redirect  off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    ssl_certificate /etc/letsencrypt/live/Jenkins/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/Jenkins/privkey.pem; # managed by Certbot
}
server {
    listen       80;
    server_name  Jenkins;

    if ($host = Jenkins) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

Jenkins 是指你自己的域名

我这里将所有HTTP 请求重定向到了 HTTPS

现在我们可以通过 https://Jenkins 来访问 Jenkins 了。

安装 Jenkins 插件:

这里我们需要安装两个插件:

Gogs plugin
Publish Over SSH

登录 Jenkins ,在 系统管理 --> 插件管理 中搜索上述两个插件并安装

Jenkins 持续集成配置:

在进行配置之前,我们需要添加两个凭证:

在 Jenkins 主页点击 凭证 --> 系统 --> 全局凭证 进入凭证列表页面,点击 添加凭证 ,我们需要添加两个凭证:

Username with password        # 用来登录 Gogs
SSH Username with private key # 用来登录 VPS

配置 Jenkins 持续集成:

  • 添加任务,配置如下:

    • Gogs Webhook 下选择 Use Gogs secret
    • Source Code Management 下选择 Git 并在 Repository URL 填写 git 地址,在 Credentials 选择我们上面配置的凭证
    • Build 下添加两个命令:
rm -rf public
hugo
  • Post-build Actions 添加在上面添加的登录 VPS 的凭证,并在 Source files 添加:
public/**
  • Exec command 添加需要在你服务器执行的命令,也可以不填,默认文件会复制到 SSH Server 服务器配置的目录下。

以下是图片配置截图:

Gogs Webhook

Source Code Management

Build

Post-build Actions

添加 Gogs 钩子:

在 Gogs 博客的 git 项目 下,点击 仓库设置 --> 管理 WEB 钩子 添加一个钩子,以便在你 push 后可以通知 Jenkins 来自动生成博客,并将博客部署到 VPS。

  • 推送地址 下添加钩子地址:
https://<Jenkins Server Address>/gogs-webhook/?job=<Jenkins 任务名称>
  • 数据格式 下选择 application/json ,保存。
可以在底部点击测试推送,查看 Jenkins 是否可以收到推送并进行自动部署到 VPS 。

That's All.

清除Chrome 的dns cache

为了加快访问速度,Google Chrome浏览器采用了预提DNS记录,在本地建立DNS缓存的方法,加快网站的连接速度。你在谷歌Chrome浏览器的地址栏中输入about:DNS,就可以看到本地的DNS缓存。
在chrome下清除DNS缓存方法:

  1. 用chrome打开:chrome://net-internals/#dns
  2. 点击上面的clean host cache

自信

最近在网上看到一个关于自信的说法,看了后自我感觉还是写的比较好的。在这里与大家共勉

自律

  • 如果你连控制自己的言行、情绪、思想都做不到,你该怎么去相信自己呢?一切自信的前提,都是源于自律。

成就

  • 对自己的信心不是凭空就能建立的(无中生有那叫自大),你需要充足的事实基础去证明自己。获取成就的过程,会增加你的阅历、经验、能力,而获得成就的本身则是对你自己巨大的肯定与鼓舞。

健康

  • 身体健康强壮的人会更加的阳光自信,他们拥有更好的状态、精力,避免身体不适对他们的干扰与影响。同时运动是最好的抗抑郁方式。

学识

  • 增加自己的学识可以减少迷惑与忧虑,避免陷入自我怀疑;对技能的训练与学习会提高你的实力,增加对生活的掌控感。

认识自己

  • 你是谁

    • 你想要什么
    • 你想成为一个什么样的人
    • 你的原则是什么
    • 你擅长什么
  • 你不会相信一个你所不了解的人。
  • 认识自己是一个漫长、痛苦的过程,但它值得你这样去做。