Ubuntu Server 从20.04升级到22.04

先更新一下包再重启一下

apt update
apt upgrade
reboot

然后升级系统

do-release-upgrade -d

升级过程中有要确认的选项直接默认回车就行了,大概十分钟就升级完成了

Ubuntu 22.04 升级到PHP8了,所以要改一下nginx的配置文件,把原来的7.4改成8.1,这样网站才能正常运行

fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;

打开网站后,WordPress会显示很多已弃用的警告,关闭debug就不会显示了,这些警告不会影响到网站

Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in .../wp-content/plugins/wordpress-seo/src/integrations/admin/helpscout-beacon.php on line 108
Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in .../wp-content/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 22
Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in .../wp-content/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 28
Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../wp-includes/functions.php on line 7035
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in .../wp-includes/functions.php on line 2164
Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../wp-includes/functions.php on line 7035
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in .../wp-includes/functions.php on line 2164
null to parameter #1 ($string) of type string is deprecated in .../wp-includes/formatting.php on line 2772

wp-config.php文件里关掉debug就不会显示了

define( 'WP_DEBUG', false ); 

我在Piwigo里,也会显示出相同的警告,编辑local/config/config.inc.php文件,加入下面的代码也可以关掉已弃用警告

$conf['show_php_errors'] = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_WARNING;

Ubuntu正确卸载nginx

apt-get remove --purge nginx nginx-full nginx-common

Ubuntu WordPress 开启redis 缓存

安装redis

apt-get update
apt-get install redis redis-server php-redis

编辑 /etc/redis/redis.conf 文件,添加

maxmemory 256mb
maxmemory-policy allkeys-lfu

重启服务

systemctl restart redis-server
systemctl restart php7.4-fpm
systemctl restart apache2

编辑wp-config.php文件添加

define( 'WP_CACHE_KEY_SALT', 'zuoridangnian.com' );
define( 'WP_CACHE', true );

安装Redis Object Cache 插件,点击开启缓存即可

下面查看一下效果

WP有个 Query Monitor 插件,可以查看一个页面的查询次数

未开启Redis Object Cache时,我的后台页面和首页查询次数是这样的

分别是68个查询和56个查询

开启后减少为32和25,大约节约一半的查询次数

Ubuntu 20.04 apache开启http2

apt update && apt upgrade
apt install apache2 php7.4-fpm 
a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm 
a2dismod php7.4 
systemctl restart apache2
a2dismod mpm_prefork 
a2enmod mpm_event 
systemctl restart apache2
systemctl restart php7.4-fpm
a2enmod http2
systemctl restart apache2

Mariadb Server 创建数据库、添加用户、给予权限

创建数据库

CREATE DATABASE 数据库名称 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

创建用户

CREATE USER 'user'@localhost IDENTIFIED BY 'password';  ## 本地访问
CREATE USER 'user'@'%' IDENTIFIED BY 'password';  ## 任意ip访问

给权限

GRANT ALL PRIVILEGES ON 数据库名.* TO '用户名'@localhost; ## 给单独数据库的权限

GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password'; ## 给全部权限但是该user不能编辑和给予其它用户权限

GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; ## 给全部权限并且该user可以编辑和给予其它用户权限

Ubuntu 20.04 Server装完系统需要做的一些事

打开ufw

ufw allow OpenSSH ## 打开SSH端口

ufw enable ## 启动 ufw

ufw status ## 查看 ufw 状态

ufw allow 8888/tcp ## 放行8888端口

安装pip

apt install python3-pip
pip3 config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple

安装lamp

apt install apache2
apt install mysql-server ##mariadb-server

安装PHP

apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
systemctl restart apache2

设置mysql

mysql_secure_installation

mysql

创建数据库
CREATE DATABASE zrdn DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

创建用户
CREATE USER 'zrdn'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

给权限
GRANT ALL ON zrdn.* TO 'zrdn'@'%';

安装certbot自动配置HTTPS证书

snap install core; sudo snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
certbot --apache

ufw 放行 apache 端口

ufw allow in "Apache Full" ## 80/443

添加用户

adduser sammy

usermod -aG sudo sammy ## 给 sudo 权限

配置用户执行sudo命令不用输入密码

1.配置单用户不用输入密码

linuxconfig ALL=(ALL) NOPASSWD:ALL

2.配置所有sudo组的用户不用输入密码

%sudo   ALL=(ALL:ALL) NOPASSWD:ALL

Ubuntu 彻底卸载数据库

首先在终端中查看MySQL的依赖项

dpkg --list|grep mysql

卸载

apt-get remove mysql-common

清除残留数据

dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P

继续查找安装的相关包,卸载

dpkg --list|grep mysql

【ubuntu20.04操作指南】修复Windows和Ubuntu双系统导致系统时间不一样

Ubuntu修改时区为当地时,即为+0800即可

timedatectl set-local-rtc 1 --adjust-system-clock

然后输入

timedatectl

就可以看到时区了

【ubuntu20.04操作指南】在Chrome中插入表情

Ubuntu自带emoji。比如在geditor里可以右键选择插入表情,但此功能无法在非GTK软件中运行,比如Chrome

要想在Chrome中插入表情,装一个插件即可Emoji Keyboard by JoyPixels® – Chrome 网上应用店

然后选择右上方,找到这个插件的logo,就可以复制表情了?

【ubuntu20.04操作指南】 屏幕截图快捷键

  • Prt Scrn t抓取整个桌面。
  • Alt+Prt Scrn 抓取当前窗口。
  • Shift+Prt Scrn 抓取选定的区域。

参考:抓图和录制视频