分類目錄歸檔:技術(shù)分享
Keep-Alive中通過component多次加載同樣的動(dòng)態(tài)組件無法保持狀態(tài)的解決辦法
cygwin環(huán)境下 PHP Fatal error: Timezone database is corrupt – this should *never* happen! 解決辦法
Windows安裝cygwin + swoole,并配置crontab定時(shí)任務(wù)
macOS monterey 升級(jí)后安裝php
macOS monterey已經(jīng)完全移出了php,不再默認(rèn)包含;升級(jí)后需要自行安裝:
可以通過brew install 的方式安裝php,但是通過該方法安裝的php又無法和默認(rèn)的apache配合使用,會(huì)包簽名錯(cuò)誤: No code signing authority for module at /opt/homebrew/Cellar/php/8.0.12/lib/httpd/modules/libphp.so specified in LoadModule directive.
當(dāng)然可以采取對(duì)so代碼自簽名的方式,但實(shí)際上這不是最好的辦法,因?yàn)閎rew install 安裝的php和mac默認(rèn)自帶的apache之間會(huì)由于各種依賴庫的問題無法跑起來
最好的辦法就是停用默認(rèn)的apache,然后apache和http完完全全都采用brew 來安裝brew 會(huì)把依賴的各種包自行安裝好
- sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
- brew install php
- brew install httpd
注意brew 安裝后的提示,相應(yīng)的環(huán)境變量PATH都按安裝后的提示設(shè)置,最好brew services start 對(duì)應(yīng)的服務(wù)即可
gitlab 升級(jí)步驟
小版本升級(jí),比如12.3.xx 升級(jí)到12.4.xx, 但是注意提示,如果升級(jí)不了會(huì)提示的:
gitlab preinstall: It seems you are upgrading from major version 13 to major version 14.
gitlab preinstall: It is required to upgrade to the latest 13.12.x version first before proceeding.
gitlab preinstall: Please follow the upgrade documentation at https://docs.gitlab.com/ee/update/index.html#upgrade-paths
- 下載rpm包,可以從這里下載https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/ 根據(jù)自己的系統(tǒng)選擇對(duì)應(yīng)的版本
- gitlab-ctl stop unicorn
- gitlab-ctl stop sidekiq
- gitlab-ctl stop nginx
- rpm -Uvh gitlab-ce-10.8.7-ce.0.el7.x86_64.rpm
- gitlab-ctl restart
- 查看升級(jí)后的版本號(hào) cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
慎用json_decode的assoc參數(shù)
我們?cè)诠ぷ髦杏龅降那闆r:
- vue 3前端界面 + php 后端 API
- vue 3采用typescript
- API數(shù)據(jù)采用json格式
出現(xiàn)的問題
當(dāng)post api時(shí)提交的json數(shù)據(jù)中包含{}這種空J(rèn)SON對(duì)象,比如style:{}, 后端php在處理過程中會(huì)變成[]并返回給前端,導(dǎo)致前端后續(xù)的功能出現(xiàn)bug,如這時(shí)再往style中設(shè)置值就不能正常工作了:style[‘foo’] = ‘bar’, 這時(shí)設(shè)置是不成功
問題的原因
原因1: typescript的強(qiáng)類型,如果是javascript,這點(diǎn)其實(shí)并不影響,JS數(shù)組可以直接設(shè)置值:var style = []; style[“foo”] = “bar”;這個(gè)操作是成功的。
原因2: 后端php在處理的過程中都是按數(shù)組格式處理:json_decode($data, true),無形中就把{}變成了php的空數(shù)組,然后返回給前端時(shí)json_encode就變成[]。
解決辦法
修改后端json_decode總是按對(duì)象格式處理
Mac 11.0以上版本不能編譯PHP的問題
在Mac 11.x版本編譯php會(huì)提示php.h不存在,phpize也看不出php版本內(nèi)容:
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
這是因?yàn)樾掳姹镜膍ac 不在支持php了,后續(xù)可能會(huì)移除php, 通過php -v 可以看出

但實(shí)際上還沒有完全移除PHP,可以查看/Library/Developer/CommandLineTools/SDKs目錄下你系統(tǒng)版本對(duì)應(yīng)的目錄中usr/include/php里面的內(nèi)容是否還存在,如果還存在說明php devl的頭文件還在哪里,只是usr/bin/phpize找不到他們。

通過phpize的輸出也不難看出,他是去usr/include/php里面找對(duì)應(yīng)的頭文件,那么我們建立軟鏈接到對(duì)應(yīng)的/Library/Developer/CommandLineTools/SDKs下面的php目錄即可。但由于/usr/include目錄是Read only的,不允許創(chuàng)建軟鏈接,解決辦法就是:
1. 把/usr/bin/phpize 和/usr/bin/php-config兩個(gè)文件復(fù)制到/usr/local/bin,并修改如下兩處內(nèi)容,加上local

php-config中extension_dir也重新指定一個(gè)目錄,并且把/etc/php.ini extension_dir中也同步調(diào)整:

2. 建立軟連接 ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/include/php /usr/local/include/php
然后使用phpize時(shí)指定全路徑 /usr/local/bin/phpize
configure時(shí)指定我們修改后的php-config:/usr/local/bin/phpize ./configrue –with-php-config=/usr/local/bin/php-config
make, make install 最后把編譯的so文件會(huì)拷貝到指定的extension_dir目錄中
該問題解決后,可通過pear的方式來安裝其他pecl 擴(kuò)展了
1. 下載pear: https://pear.php.net/go-pear.phar
2. 安裝: php go-pear.phar,在出現(xiàn)的頁面中分別把1,4兩步設(shè)置為如下圖所示,這其實(shí)是讓pecl命令在bin目錄中
3. 然后就可以通過pecl按照擴(kuò)展了,比如pecl install zip,會(huì)下載源碼并編譯,同上面的phpize & configure & make & make install


Mysql incorrect string value
這是由于mysql字段的存儲(chǔ)字符集存儲(chǔ)不了,比如utf8中存儲(chǔ)不了一些表情符號(hào),比如微信上的昵稱:abc🍃,解決辦法就是存儲(chǔ)要修改對(duì)應(yīng)的編碼字符集,與數(shù)據(jù)庫的通訊鏈接也要修改對(duì)應(yīng)的編碼字符集
- 把對(duì)應(yīng)字段的字符集修改成utf8mb4
- 同時(shí)把代碼中數(shù)據(jù)庫鏈接驅(qū)動(dòng)中的字符集也修改成utf8mb4,比如用pdo需要設(shè)置 :SET NAMES utf8mb4
兩者少一個(gè)都不行
gitlab 備份、升級(jí)與遷移
備份
gitlab-rake gitlab:backup:create
如果是putty遠(yuǎn)程連接服務(wù)器執(zhí)行該命令,可能由于某些git庫太大導(dǎo)致putty遲遲沒有反應(yīng)而導(dǎo)致鏈接中斷,鏈接中斷后該命令也會(huì)終止執(zhí)行,所以可以通過nohup 來把命令脫離命令行執(zhí)行:
nohup gitlab-rake gitlab:backup:create 2>&1 &
通過在nohup.out 中可以查看輸出日志
備份成功后在/var/opt/gitlab/backups中會(huì)產(chǎn)生一個(gè)類似于1610804990_gitlab_backup.tar的文件,一定要確保backup完成在copy該文件,上面的nohup.out中最后幾行是下面情況時(shí),說明備份完成了:
done
Dumping uploads …
done
Creating backup archive: 1610804990_gitlab_backup.tar … done
Uploading backup archive to remote storage … skipped
Deleting tmp directories … rake aborted!
Don’t know how to build task ‘/var/opt/backlog.log’
(See full trace by running task with –trace)
done
Deleting old backups … skipping
恢復(fù)
gitlab-rake gitlab:backup:restore BACKUP=/var/opt/gitlab/backups/1610804990
注意backup中的文件名不是完整的1610804990_gitlab_backup.tar,而只是_gitlab_backup.tar的前面部分
遷移
可以用scp把備份文件上傳到目標(biāo)服務(wù)器,在目標(biāo)服務(wù)器上執(zhí)行:scp src_username@src_ip:/var/opt/gitlab/backups/1481529483_gitlab_backup.tar /var/opt/gitlab/backups
升級(jí)
gitlab升級(jí)不能一次性跨大版本升級(jí),比如不能6.x升級(jí)到13.x,只能在一個(gè)major版本升到最高級(jí)別后在升級(jí)到下一個(gè)major版本(版本號(hào)格式:major.minor),官方給出來的升級(jí)順序是:

但我從7.6.x 升級(jí)到13.7并沒有完全按照這個(gè)順序,基本規(guī)則是升級(jí)到當(dāng)前major版本的最后一個(gè)版本后,再升級(jí)到下一個(gè)major的第一個(gè)版本,一次類推直到最新版本
每個(gè)版本的鏡像可以從這里下載:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
每次升級(jí)前,先stop服務(wù)
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
sudo gitlab-ctl stop nginx
數(shù)據(jù)庫不要stop,在安裝時(shí)是需要備份數(shù)據(jù)庫的,所以不能停
wget 下載好對(duì)應(yīng)的rpm包后執(zhí)行 rpm -Uvh 安裝包
安裝包會(huì)備份數(shù)據(jù)庫部分,安裝新版本,刪除舊版本,升級(jí)成功收gitlab-ctl restart即可