banner
Feng

Feng's xLog

我在xLog上的窝

Blogging's Another Round of Fiddling

The blog has always used Junge's LNMP (Linux+Nginx+MySQL+PHP) one-click installation script to build WordPress websites. Occasionally, I have also used Baota and 1pancel, but LNMP has been used the longest. However, starting from the second half of 2023, after the author Junge sold the website to a certain company after many years of hard work, it was discovered that the code of the LNMP.COM website was maliciously implanted with a backdoor code. At the same time, the company also acquired oneinstack, and malicious code appeared at the same time. The LNMP and oneinstack one-click website installation packages have been widely abandoned.

image

Of course, there are still many alternative solutions, but I still want to take this opportunity to try something new, so let's try Qiu Shui's LCMP (Linux + Caddy + MariaDB + PHP) script (Github address). Caddy 2 is a modern, lightweight open-source web server that stands out for its simple configuration syntax, built-in automatic HTTPS support, dynamic configuration and service discovery, modern HTTP/2 and HTTP/3 support, plugin system, and easy deployment and management. Of course, in terms of functionality, ecosystem, and performance, Nginx is still stronger at present.

Now let's introduce how to use Qiu Shui's LCMP one-click script to build WordPress.

Currently supported systems#

  • Enterprise Linux 7 (CentOS 7, RHEL 7)
  • Enterprise Linux 8 (CentOS Stream 8, RHEL 8, Rocky Linux 8, AlmaLinux 8, Oracle Linux 8)
  • Enterprise Linux 9 (CentOS Stream 9, RHEL 9, Rocky Linux 9, AlmaLinux 9, Oracle Linux 9)
  • Debian 10
  • Debian 11
  • Debian 12
  • Ubuntu 20.04
  • Ubuntu 22.04

Currently supported software#

  • Caddy 2
  • MariaDB 10.11
  • PHP-7.4, PHP-8.0, PHP-8.1, PHP-8.2, PHP-8.3

Install dependencies before starting#

apt update && apt -y upgrade
apt install wget -y
apt install socat -y
apt install git -y

Start installing LCMP#

  • If it is Debian 10+ / Ubuntu 20.04+:
apt-get -y install wget git
git clone https://github.com/teddysun/lcmp.git
cd lcmp
chmod 755 *.sh
./lcmp.sh 2>&1 | tee lcmp.log
  • If it is Enterprise Linux 7 / 8 / 9:
yum -y install wget git
git clone https://github.com/teddysun/lcmp.git
cd lcmp
chmod 755 *.sh
./lcmp.sh 2>&1 | tee lcmp.log

When the following message appears, it means that LCMP has been installed successfully.

LCMP (Linux + Caddy + MariaDB + PHP) installation complete

I personally feel that the operation commands of LCMP are somewhat similar to LNMP, because the way to add virtual hosts is as follows:

lcmp vhost add

Does it look familiar? It's just the difference between C and N. For specific commands and usage, please refer to Qiu Shui's Github.
As for the process of building a WordPress website, I won't go into details. It shouldn't be a problem. However, when I was uploading photos or downloading plugins in WordPress, I encountered permission issues that need to be noted (maybe it's just my case). In the past, I used to assign permissions to the website directory as the www user. After using Caddy, if I operate in this way, there will still be a problem of inaccessible backend. Later, I searched many websites and found that I need to assign the website directory with caddy user permissions to solve the problem. The specific operation is as follows (assuming the website directory is under /data/www/):

chown -R caddy:caddy /data/www/*

Now that the website is set up, it is still necessary to take necessary backup measures. Qiu Shui's one-click script currently does not include a backup script, so I extracted the backup.sh from Junge's Github and made some modifications. In addition to local backup, the backup file is also uploaded to Alibaba Cloud OSS to form a dual backup to prevent accidents. The following is the general process and code:

Configure Alibaba Cloud ossutil#

sudo -v ; curl https://gosspublic.alicdn.com/ossutil/install.sh | sudo bash
  • Configure ossutil
ossutil config

Set the Endpoint, AccessKey ID, AccessKey Secret, and STSToken parameters according to the prompts. The corresponding values can be obtained from Alibaba Cloud. The only thing to note is the stsToken value. I didn't quite understand what the official documentation said, which wasted a lot of time. Later, I found out that I can just press Enter to leave it blank, sigh!

Modify the backup script#

# Set the website backup path
Backup_Home="/data/www/backup/"
# Set the database path
MySQL_Dump="/usr/bin/mysqldump"
# Set the website directories to be backed up
Backup_Dir=("/data/www/a.com" "/data/wwww/b.com")
# Set the names of the databases to be backed up, separated by spaces for different tables
Backup_Database=("wordpress_" "typecho_")
# Set the username and password of Mysql
MYSQL_UserName='root'
MYSQL_PassWord='123456'
TodayWWWBackup=www-*-$(date +"%Y%m%d").tar.gz
TodayDBBackup=db-*-$(date +"%Y%m%d").sql
OldWWWBackup=www-*-$(date -d -3day +"%Y%m%d").tar.gz
OldDBBackup=db-*-$(date -d -3day +"%Y%m%d").sql
Backup_Dir()
{
    Backup_Path=$1
    Dir_Name=`echo ${Backup_Path##*/}`
    Pre_Dir=`echo ${Backup_Path}|sed 's/'${Dir_Name}'//g'`
    tar zcf ${Backup_Home}www-${Dir_Name}-$(date +"%Y%m%d").tar.gz -C ${Pre_Dir} ${Dir_Name}
}
Backup_Sql()
{
    ${MySQL_Dump} -u$MYSQL_UserName -p$MYSQL_PassWord $1 > ${Backup_Home}db-$1-$(date +"%Y%m%d").sql
}
if [ ! -f ${MySQL_Dump} ]; then  
    echo "mysqldump command not found.please check your setting."
    exit 1
fi
if [ ! -d ${Backup_Home} ]; then  
    mkdir -p ${Backup_Home}
fi
echo "Backup website files..."
for dd in ${Backup_Dir[@]};do
    Backup_Dir ${dd}
done
echo "Backup Databases..."
for db in ${Backup_Database[@]};do
    Backup_Sql ${db}
done
echo "Delete old backup files..."
rm -f ${Backup_Home}${OldWWWBackup}
rm -f ${Backup_Home}${OldDBBackup}
# Upload the backed up database to Alibaba Cloud. Replace Bucket-name with the corresponding name
ossutil cp -r -f /data/www/backup/$TodayDBBackup oss://Bucket-name/
ossutil cp -r -f /data/www/backup/$TodayWWWBackup oss://Bucket-name/

Test it out, there should be corresponding files in the backup directory, and then check in Alibaba Cloud OSS, if they are there, it means it's successful. Here, only the database files are uploaded to Alibaba Cloud OSS. Finally, remember to add a cron job, you can refer to the following:

[root@localhost ~]# crontab -e
Options:
    -e:    Edit crontab scheduled tasks
    -l:    Query crontab tasks
    -r:    Delete all crontab tasks for the current user
0 14 * * * /bin/bash /data/www/backup/backup.sh

Finally, the setup is complete. You can watch a drama now.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.