NGINX get filename and remove prefix

location ~ "^/downloads/files/[a-zA-Z0-9]{8}\-(.*\..*)$" {
    add_header Content-disposition 'attachment; filename="$1"';
}

Windows 10 共享資料夾 CentOS 7 掛載

PHPStrom 對 samba 分享的資料夾掛載不友善
External file changes sync may be slow: Project files cannot be watched (are they under network mount?)
所以要反過 windows 10 分享給 centos 掛載, 這樣 phpstorm 在讀取檔案時就不會慢

Windwos 10
open cmd with admin
Add Windows user for share
net user __USER__ __PASSWORD__ /add

Add user to admin(optional)
net localgroup administrators __USER__ /add

Share folder and add user
net share __SHARE_NAME__=D:\www /GRANT:__USER__,FULL

Centos 7
yum install -y cifs-utils

Create mount folder
/mnt/www

Mount Folder
要明確指定權限, 否則 nginx, php 無法執行及寫入動作
mount -t cifs -o username="__USER__",password="__PASSWORD__",uid=root,gid=root,dir_mode=0774,file_mode=0774,vers=2.0 //192.168.0.120/www /mnt/www

Unmount Folder
umount /mnt/www

Auto mount with startup
vi /etc/fstab
//192.168.0.120/www    /mnt/www    cifs    auto,username=__USER__,password=__PASSWORD__,uid=root,gid=root,dir_mode=0774,file_mode=0774,vers=2.0    0 0

Execute mount
mount -a

Check mount
mount

Check df
df -h


ref:
https://hk.saowen.com/a/f9bdf856dcdefe9ef9b81d80d03f3985b5033efd7e230e2cae7c126e04d67794

fdisk add LVM to CentOS

Linux Fdisk 磁碟分割及格式化

列出 partition table(s)
# fdisk -l

格式化 /dev/sdb
# fdisk /dev/sdb
# Command (m for help): n
# Command action
   e   extended
   p   primary partition (1-4)
p
# Partition number (1-4): 1
# First cylinder (1-2610, default 1): "enter"
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): "enter"
Using default value 2610
# Command (m for help): w

將新增實體給LVM使用
# pvcreate /dev/sdb1

查詢 VG Nname
# vgdisplay

掛載新磁區到 VG
# vgextend centos /dev/sdb1

掃描新磁區是否掛載到 VG
# pvscan

顯示目前的 LVM
# lvdisplay

選擇欲加大的 LVM 掛載新磁區
# lvextend /dev/centos/usr /dev/sdb1

重新整理 LMV 大小
# xfs_growfs /dev/centos/usr

檢查 LVM 是否已正常掛載
# df -h



ref:
https://www.rootusers.com/how-to-increase-the-size-of-a-linux-lvm-by-adding-a-new-disk/

CentOS7 Sendmail test send email


# Install sendmail sendmail-cf m4
yum install sendmail sendmail-cf m4

# edit local host name
vi /etc/mail/local-host-names
xxx.com

# edit sendmail.mc
vi /etc/mail/sendmail.mc

#change 127.0.0.1 to 0.0.0.0
DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

# change sendmail setting
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

# setting relay
vi /etc/mail/access
Connect:xxx.com RELAY

# hash database
makemap hash access < access

# restart sendmail
systemctl restart sendmail

# test php send mail
php -a
mail('user@receiver.com', "Test email", "Test email from the Internet", null, "-f user@sender.com");

Google Drive API 重新授權

1. 移除 json
2. 使手 CLI 取得網址,再取得 code 重新授權

CentOS 7 Systemd PHP


CentOS 7 Systemd 預設會打開 PrivateTmp 需要將它關掉才能與其他服務共用 /tmp

Close Systemd PHP Private Tmp
/usr/lib/systemd/system/php-fpm.service
PrivateTmp=false

Save reload daemon
systemctl daemon-reload

Restart php-fpm
systemctl restart php-fpm.service