作者归档:myjoyoo

在MacOS里,WireGuard不能同时连接多个vpn的问题解决

不要从app市场上下载wireguard,用brew安装,以命令的方式启动。

brew install wireguard-tools

vim wg-up.sh
wg-quick up /path/a.conf
wg-quick up /path/b.conf
wg-quick up /path/c.conf

vim wg-down.sh
wg-quick down /path/a.conf
wg-quick down /path/b.conf
wg-quick down /path/c.conf

启动和停止
sudo wg-up.sh
sudo wg-down.sh

Windows下Python的PyPi源不生效的问题

Windows的pip源设置配置文件是在: C:\Users\{用户}\AppData\Roaming\pip\pip.ini,在virtualenv目录下加一个pip.ini没用,最好是用下面的方法设置。

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip config set install.trusted-host mirrors.aliyun.com

MAC技巧

关闭烦人的光标处的输入法LOGO提示
sudo defaults write /Library/Preferences/FeatureFlags/Domain/UIKit.plist redesigned_text_cursor -dict-add Enabled -bool NO
可能要重新启动电脑

MacOS下Python多版本安装

brew install pyenv
# 如果慢可以设置代理
export https_proxy=”127.0.0.1:7890″
# 安装新版本
pyenv install 3.8.10
# 查看已经安装的版本
pyenv versions
# 查看可安装版本
pyenv install –list
pyenv init
按上面的输出设置~/.zshrc
source ~/.zshrc
切换
pyenv shell 3.8.10

https://blog.csdn.net/Zerol_Yan/article/details/139564059

php防止上传木马被运行设置

目的是能上传的目录不能运行PHP,能运行PHP的目录没有上传权限。
建立新的只读用户nginxr,并加到webgrp组
useradd -r -s /sbin/nologin nginxr
usermod -a -G webgrp nginxr
程序目录
chown nginxr:webgrp -R 程序目录
find ./ -type d -exec chmod 755 {} \;
find ./ -type f -exec chmod 640 {} \;
静态文件目录,设置为只读
chown nginx:webgrp -R static/
find ./static -type d -exec chmod 550 {} \;
find ./static -type f -exec chmod 550 {} \;
可写目录
chown nginx:webgrp -R 可写目录
find ./runtime -type d -exec chmod 750 {} \;
find ./runtime -type f -exec chmod 600 {} \;
find ./test_write -type d -exec chmod 750 {} \;
find ./test_write -type f -exec chmod 600 {} \;
nginx配置文件
location ~ [^/]\.php(/|$) {
# 这里是加入的代码,屏蔽一些不能运行php的目录
    if ($request_uri ~* ‘/test_write|/runtime|/static’) {
        return 403;
    }
    # 屏蔽结束
    include         fastcgi.conf;
    fastcgi_index   index.php;
    fastcgi_pass    php73_fpm;
}

新的mac m3电脑的php各版本环境安装乱记

wx,dd,qq,vscode,weiyun,clash,vee,sublime,ipmsg,git,utools
sequel ace在APP STORE上安装。

设置curl代理
export https_proxy=”127.0.0.1:7890″
export http_proxy=”127.0.0.1:7890″

git config –global https.proxy ‘http://127.0.0.1:7890’

安装omyzsh
https://ohmyz.sh/#install

安装xbar
https://github.com/matryer/xbar/releases

安装brew
https://brew.sh

brew install wget telnet nginx

/opt/homebrew/etc/nginx/nginx.conf
nginx will load all files in /opt/homebrew/etc/nginx/servers/
To start nginx now and restart at login:
brew services start nginx
Or, if you don’t want/need a background service you can just run:
/opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\;

http://localhost:8080

brew tap shivammathur/php

brew install [email protected] [email protected] [email protected] [email protected]

The php.ini and php-fpm.ini file can be found in:
/opt/homebrew/etc/php/5.6/

[email protected] is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have [email protected] first in your PATH, run:
echo ‘export PATH=”/opt/homebrew/opt/[email protected]/bin:$PATH”‘ >> ~/.zshrc
echo ‘export PATH=”/opt/homebrew/opt/[email protected]/sbin:$PATH”‘ >> ~/.zshrc

For compilers to find [email protected] you may need to set:
export LDFLAGS=”-L/opt/homebrew/opt/[email protected]/lib”
export CPPFLAGS=”-I/opt/homebrew/opt/[email protected]/include”

To start shivammathur/php/[email protected] now and restart at login:
brew services start shivammathur/php/[email protected]
Or, if you don’t want/need a background service you can just run:
/opt/homebrew/opt/[email protected]/sbin/php-fpm –nodaemonize

brew install zlib
wget https://pecl.php.net/get/memcache-2.2.7.tgz
tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7
/opt/homebrew/opt/[email protected]/bin/phpize
./configure -with-zlib-dir=/opt/homebrew/opt/zlib/ -with-php-config=/opt/homebrew/opt/[email protected]/bin/php-config
make
make install

/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/redis-4.3.0.tgz
/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/redis-5.3.7.tgz
/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/redis-5.3.7.tgz
/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/redis-6.1.0RC1.tgz
8.4只支持这个rc版的redis

/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/xdebug-2.5.4.tgz
vim /opt/homebrew/etc/php/5.6/php.ini
[XDebug]
zend_extension=”xdebug.so”
xdebug.mode=debug
xdebug.log_level=0
xdebug.remote_enable=on
xdebug.remote_autostart=on
xdebug.remote_host=”127.0.0.1″
xdebug.remote_port=”9156″

 

 

To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp7.so

<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
/opt/homebrew/etc/php/7.4/

[email protected] is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have [email protected] first in your PATH, run:
echo ‘export PATH=”/opt/homebrew/opt/[email protected]/bin:$PATH”‘ >> ~/.zshrc
echo ‘export PATH=”/opt/homebrew/opt/[email protected]/sbin:$PATH”‘ >> ~/.zshrc

For compilers to find [email protected] you may need to set:
export LDFLAGS=”-L/opt/homebrew/opt/[email protected]/lib”
export CPPFLAGS=”-I/opt/homebrew/opt/[email protected]/include”

To start shivammathur/php/[email protected] now and restart at login:
brew services start shivammathur/php/[email protected]
Or, if you don’t want/need a background service you can just run:
/opt/homebrew/opt/[email protected]/sbin/php-fpm –nodaemonize

/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/redis-5.3.7.tgz

/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/xdebug-3.1.5.tgz
vim /opt/homebrew/etc/php/7.4/php.ini
[XDebug]
zend_extension=”xdebug.so”
xdebug.mode=debug
xdebug.log_level=0
xdebug.start_with_request=yes
xdebug.client_host=”127.0.0.1″
xdebug.client_port=”9174″
xdebug.remote_handler=dbgp

在m系列上安装swoole
可能会出现:include/php/ext/pcre/php_pcre.h:25:10: fatal error: ‘pcre2.h’ file not found
brew install pcre2
ln -s /opt/homebrew/include/pcre2.h /opt/homebrew/Cellar/[email protected]/7.4.33_6/include/php/ext/pcre2.h
上面的路径看情况调整
/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/swoole-4.6.1.tgz
上面的安装可能会出错,特别是在apple芯片上,在这里看他们的更新日志,和去git看issue,选择一个支持的版本。
https://pecl.php.net/package-changelog.php?package=swoole

如果要支持openssl的话,需要用源码安装执行下面的配置:
./configure –enable-openssl –with-openssl-dir=/opt/homebrew/Cellar/openssl@3/3.3.1 –with-php-config=/opt/homebrew/opt/[email protected]/bin/php-config

wget https://github.com/swoole/ext-postgresql/archive/refs/tags/v4.6.1.zip
unzip v4.6.1.zip
wget https://pecl.php.net/get/swoole-4.6.1.tgz
tar -zxvf swoole-4.6.1.tgz
cd ext-postgresql
编译时,需要用到swoole的源码,且路径有些怪,报下面的错:
./swoole_postgresql_coro.h:20:10: fatal error: ‘ext/swoole/ext-src/php_swoole_cxx.h’ file not found
#include “ext/swoole/ext-src/php_swoole_cxx.h”
需要建立一个软链接,
mkdir -p ext/swoole
ln -s /Users/liyan/software/swoole-4.6.1/ext-src ext/swoole/
export PATH=”/opt/homebrew/opt/libpq/bin:$PATH”
export LDFLAGS=”-L/opt/homebrew/opt/libpq/lib”
export CPPFLAGS=”-I/opt/homebrew/opt/libpq/include”
export PKG_CONFIG_PATH=”/opt/homebrew/opt/libpq/lib/pkgconfig”
;source ~/.zshrc
/opt/homebrew/opt/[email protected]/bin/phpize
./configure –with-php-config=/opt/homebrew/opt/[email protected]/bin/php-config
vim Makefile
在include那里,把/Users/liyan/software/swoole-4.6.1/include加上,如果还有差的,也加上。
make
make install
vim /opt/homebrew/etc/php/7.3/php.ini
extension=”swoole_postgresql.so”

 

To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp.so

<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
/opt/homebrew/etc/php/8.4/

[email protected] is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have [email protected] first in your PATH, run:
echo ‘export PATH=”/opt/homebrew/opt/[email protected]/bin:$PATH”‘ >> ~/.zshrc
echo ‘export PATH=”/opt/homebrew/opt/[email protected]/sbin:$PATH”‘ >> ~/.zshrc

For compilers to find [email protected] you may need to set:
export LDFLAGS=”-L/opt/homebrew/opt/[email protected]/lib”
export CPPFLAGS=”-I/opt/homebrew/opt/[email protected]/include”

To start shivammathur/php/[email protected] now and restart at login:
brew services start shivammathur/php/[email protected]
Or, if you don’t want/need a background service you can just run:
/opt/homebrew/opt/[email protected]/sbin/php-fpm –nodaemonize

/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/redis-6.1.0RC1.tgz
/opt/homebrew/opt/[email protected]/bin/pecl install https://pecl.php.net/get/xdebug-3.3.2.tgz
vim /opt/homebrew/etc/php/8.4/php.ini
[XDebug]
zend_extension=”xdebug.so”
xdebug.mode=debug
xdebug.log_level=0
xdebug.start_with_request=yes
xdebug.client_host=”127.0.0.1″
xdebug.client_port=”9184″
xdebug.remote_handler=dbgp

安装mysql
Upgrading from MySQL <8.4 to MySQL >9.0 requires running MySQL 8.4 first:
– brew services stop mysql
– brew install [email protected]
– brew services start [email protected]
– brew services stop [email protected]
– brew services start mysql

We’ve installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
mysql -u root

To start mysql now and restart at login:
brew services start mysql
Or, if you don’t want/need a background service you can just run:
/opt/homebrew/opt/mysql/bin/mysqld_safe –datadir\=/opt/homebrew/var/mysql
==> Summary
🍺 /opt/homebrew/Cellar/mysql/9.0.1: 324 files, 310.3MB
==> Caveats
==> mysql
Upgrading from MySQL <8.4 to MySQL >9.0 requires running MySQL 8.4 first:
– brew services stop mysql
– brew install [email protected]
– brew services start [email protected]
– brew services stop [email protected]
– brew services start mysql

We’ve installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
mysql -u root

To start mysql now and restart at login:
brew services start mysql
Or, if you don’t want/need a background service you can just run:
/opt/homebrew/opt/mysql/bin/mysqld_safe –datadir\=/opt/homebrew/var/mysql

brew install redis
brew services start redis

brew install node
npm config set https-proxy=’http://127.0.0.1:7890’
npm install n -g
具体可以参考:https://www.npmjs.com/package/n
按上面来操作,因为有权限啥的。
用n安装完版本后,要把用brew install安装的node卸载掉,不然用n切不过去。
brew uninstall node

brew install nvm
mkdir ~/.nvm
根据提示加在.zsh文件里
nvm ls
nvm ls-remote
nvm install v14.21.3
nvm use v14.21.3

#alias python3=”/usr/local/bin/python3″
alias python3=”/usr/local/opt/[email protected]/bin/python3.9″
alias pip3=”/usr/local/opt/[email protected]/bin/pip3″

# 关闭brew自动更新
export HOMEBREW_NO_AUTO_UPDATE=true
# 关闭brew自动删除没使用的包
export HOMEBREW_NO_INSTALL_CLEANUP=1

alias php56=”/opt/homebrew/opt/[email protected]/bin/php”
alias php73=”/opt/homebrew/opt/[email protected]/bin/php”
alias php74=”/opt/homebrew/opt/[email protected]/bin/php”
alias php84=”/opt/homebrew/opt/[email protected]/bin/php”

alias php56-restart=”brew services restart [email protected]
alias php56-stop=”brew services stop [email protected]
alias php56-start=”brew services start [email protected]
alias php74-restart=”brew services restart [email protected]
alias php74-stop=”brew services stop [email protected]
alias php74-start=”brew services start [email protected]
alias php84-restart=”brew services restart [email protected]
alias php84-stop=”brew services stop [email protected]
alias php84-start=”brew services start [email protected]

alias redis-restart=”brew services restart redis”
alias redis-stop=”brew services stop redis”
alias redis-start=”brew services start redis”

alias mysql-restart=”brew services restart mysql”
alias mysql-stop=”brew services stop mysql”
alias mysql-start=”brew services start mysql”

export PATH=“/Users/liyan/script/:$PATH

开启vim的语法:
vim ~/.vimrc
syntax on

mac系统较新,不支持一些rsa算法,导致在从一些git上拉代码时出现:
sign_and_send_pubkey: no mutual signature supported
需要加上:vim ~/.ssh/config
PubkeyAcceptedKeyTypes +ssh-rsa

CentOS下,curl和wget返回都很慢,但ping确很快的原因

公司内网有几台CentOS服务器,发现网络很慢,但ping和telnet ip port都很快。

在wget的时候,解析主机花了很多时间,花了很久的时间排查下来是因为ipv4和ipv6有冲突,需要在
/etc/resolv.conf
后面加上
options single-request-reopen

就解决了,参考:
https://serverfault.com/questions/858649/slow-responses-with-curl-and-wget-on-centos-7

tmux使用手记

会话管理
tmux new -s 会话名字:建立一个新的会话
tmux attach -t 序号或会话名字: 连接到会话
^b+s: 列出所有会话进行切换
^b+d: 退出会话并在后台运行

窗口管理
^b+c: 建立新窗口
^b+w: 列出所有窗口进行切换
^b+&: 退出窗口
^b+n: 切换到下一个窗口
^b+p: 切换到上一个窗口

面板管理
^b+双引号: 垂直分隔
^b+%: 水平分隔
^b+箭头: 在不同的面板之间切换
^b+o: 在不同面板之间循环切换
^b+x: 关闭pane,和关闭窗口一样
^b+q: 显示各面板的编号

编辑操作
^b+[: 进入复制模式,相当于vi的命令格式,可以用vi命令进行移动光标

其它技巧
命令行删除从光标到头的命令: ^u, 从光标删除到末: ^k

让FPM以root用户运行

fpm默认是不能以root用户运行的,会报:
ERROR: [pool www] please specify user and group other than root

如果有特殊原因,需要以root用户运行,需要修改配置,以让fpm支持以root用户的方式运行fpm
vim /lib/systemd/system/php-fpm.service
把:
ExecStart=/usr/sbin/php-fpm –nodaemonize
修改成:
ExecStart=/usr/sbin/php-fpm -R –nodaemonize

改完后,需要执行:
systemctl daemon-reload
以生效修改

再执行,重启fpm进程
systemctl restart php-fpm

如果之前的fpm是手动运行的,需要以发送Linux信号的方式停止fpm服务,如果开启的fpm进程较多,要多等一会儿,等子进程完了再systemctl start php-fpm,不然会出现端口被占用,无法启动的情况
kill -SIGKILL [fpm master的进程号]