月度归档:2020年12月

解决apache内存占用过高的问题

Windows 服务器上的 Apache2.4 占用内存过高,在没有什么请求的情况下,启动服务没一会就占用300多M。

解决办法:

打开httpd.conf,把Include conf/extra/httpd-mpm.conf前面的注释掉去(如下图),重启服务即可。

这样修改后,Apache会使用httpd-mpm.conf里面的配置,当然,也可以在里面进行更精细的调优。重启服务之后,可以看到内存占用是正常的,内存大小随负载的增高而变化。

WordPress 代码高亮插件

一直想做这个事情,但又觉得可有可无,就一直拖到现在。这几天事情不多,今天下午突然想起来这事,不如把它实现了。

在 plugins 目录新建文件夹 MyHighlight ,然后在 MyHighlight 文件夹下新建文件 MyHighlight .php ,代码如下:

<?php 
/*
Plugin Name: MyHighlight 
Plugin URI: https://www.ilinshu.cn
Description:代码高亮插件
Version: 1.1
Author: wujie
Author URI: https://wujie.me
License: GPL
*/

function add_my_plugin_stylesheet() {
    wp_register_style('highlight', '//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/styles/atom-one-light.min.css');
    wp_enqueue_style('highlight');
}
add_action( 'wp_print_styles', 'add_my_plugin_stylesheet' );

function add_my_plugin_script() {
    wp_register_script('highlight','//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/highlight.min.js');
    wp_enqueue_script('highlight');
}
add_action( 'wp_enqueue_scripts', 'add_my_plugin_script' );

function init_highlighting() { ?>
    <style>
        @import url('https://fonts.googleapis.com/css?family=Fira+Code&display=swap');
        .hljs{ background:transparent; }
        code {
            font-family: 'Fira Code', consolas,'Microsoft YaHei', monospace;
            background: #dcd7ca;
            border-radius: 0.2rem;     
            padding: 0.3rem 0.4rem 0.3rem 0.4rem;
            font-size: 0.8em;
        }
        
        .wp-block-code code, kbd, pre, samp {
            font-family: 'Fira Code', consolas,'Microsoft YaHei', monospace;
            font-size: 0.5em;
            padding: 0.4rem 0.6rem;
            white-space: pre-wrap;
        }     
    </style>
    <script>
        hljs.initHighlightingOnLoad();
    </script>
<?php
}
add_action('wp_head', 'init_highlighting');

保存后,到后台启用该插件即可看到效果。

Debian10编译PHP7.4问题记录

系统镜像是基于阿里云的 Debian10.6。

configure参数:

./configure \
--prefix=/usr/local/php/php74 \
--enable-gd \
--with-curl \
--enable-fpm \
--enable-cgi \
--with-openssl \
--enable-mbstring \
--with-pdo-mysql \
--with-zlib \
--with-zip \
--with-mysqli \
--enable-opcache \
--enable-mysqlnd \
--with-libxml \
--with-jpeg \
--with-freetype \
--with-pdo-sqlite \
--with-sqlite3 \
--enable-cli \
--enable-shared \
--enable-exif 

问题记录

问题:
configure: error: Package requirements (openssl >= 1.0.1) were not met:
No package ‘openssl’ found

解决:
apt install libssl-dev

问题:
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
No package ‘sqlite3’ found

解决:
apt-get install libsqlite3-dev

问题:
configure: error: Package requirements (libcurl >= 7.15.5) were not met:
No package ‘libcurl’ found

解决:
apt-get install libcurl4-gnutls-dev

问题:
configure: error: Package requirements (oniguruma) were not met:
No package ‘oniguruma’ found

解决:
apt install libonig-dev

问题:
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
No package ‘libzip’ found

解决:
apt-get install libzip-dev

另外,编译时遇到virtual memory exhausted: Cannot allocate memory的错误,这是由于阿里云的镜像默认没开启swap的原因,创建一个swap内存再编译即可。

总结一下,在阿里云提供的debina10镜像上编译安装PHP7.4,必须安装的依赖有:

apt install -y  libssl-dev libsqlite3-dev libcurl4-gnutls-dev libonig-dev  libzip-dev

一点感想:与 CentOS7 相比,Debian10 安装一些依赖非常方便,不用像 CentOS 一样要到处找源,要安装“野包”才能编译。

CentOS7 升级 Mysql 到 5.7.32

升级mysql服务端

yum update mysql-server

然后升级数据

mysql_upgrade -uroot -p

顺便把客户端版本也升级了

yum update mysql

最后用 SELECT @@version; 查看版本。

注意:我这里是小版本升级,没备份直接升了。如果跨主版本建议先做数据备份再升级。