使用 SSH 安装 Joomla - 完整周期

设置变量

JUSERID=$[ ( $RANDOM % 100 )  + 1 ]
JUSERNAME="admin"
JUSEREMAIL="admin@localhost.com"
JUSERPASS="qweasd"
DB="joomla_3"
DBUSER="jdbuser"
DBPASS="dbupass"
DBPREFIX="prfx_"
JOOMLAVERSION="3.6.2"

删除初始 index.html

rm -f /var/public_html/index.html

下载上面指定的 Joomla 版本

wget https://github.com/joomla/joomla-cms/releases/download/$JOOMLAVERSION/Joomla_$JOOMLAVERSION-Stable-Full_Package.zip -P /var/tmp/

安装解压缩并解压缩

apt-get install unzip
unzip /var/tmp/Joomla_$JOOMLAVERSION-Stable-Full_Package.zip -d /var/public_html

更改文件夹

cd /var/public_html

根据需要更改 configuration.php 值(根据上面设置的变量)

sed -i "s/\$user = ''/\$user = '${DBUSER}'/" installation/configuration.php-dist
sed -i "s/\$password = ''/\$password = '${DBPASS}'/" installation/configuration.php-dist
sed -i "s/\$db = ''/\$db = '${DB}'/" installation/configuration.php-dist
sed -i "s/\$dbprefix = 'jos_'/\$dbprefix = '${DBPREFIX}'/" installation/configuration.php-dist
sed -i "s/\$tmp_path = '/tmp'/\$tmp_path = '/var/public_html/tmp'" installation/configuration.php-dist
sed -i "s/\$log_path = '/var/logs'/\$log_path = '/var/public_html/logs'/" installation/configuration.php-dist
sed -i "s/\$cache_handler = 'file'/\$cache_handler = ''/" installation/configuration.php-dist

将 configuration.php 移动到需要的位置

mv installation/configuration.php-dist configuration.php

创建 DB 和 Joomla DB 用户

echo "CREATE DATABASE ${DB}" | mysql -u root --password=qweasd
echo "CREATE USER '${DBUSER}'@'%' IDENTIFIED BY '${DBPASS}';" | mysql -u root --password=qweasd
echo "GRANT ALL ON ${DB}.* TO '${DBUSER}'@'%';" | mysql -u root --password=qweasd

通过 sql 初始化 joomla DB

sed -i "s/#__/${DBPREFIX}/" installation/sql/mysql/joomla.sql
cat installation/sql/mysql/joomla.sql | mysql -u $DBUSER --password=$DBPASS $DB

创建 Joomla Admin 用户

JPASS="$(echo -n "$JUSERPASS" | md5sum | awk '{ print $1 }' )"
echo "INSERT INTO \`${DBPREFIX}users\` (\`id\`, \`name\`, \`username\`, \`email\`, \`password\`, \`block\`, \`sendEmail\`, \`registerDate\`, \`lastvisitDate\`, \`activation\`, \`params\`, \`lastResetTime\`, \`resetCount\`, \`otpKey\`, \`otep\`, \`requireReset\`) VALUES ('${JUSERID}', 'Me', '${JUSERNAME}', '${JUSEREMAIL}', '${JPASS}', '0', '0', '0000-00-00 00:00:00.000000', '0000-00-00 00:00:00.000000', '', '', '0000-00-00 00:00:00.000000', '0', '', '', '0');" | mysql -u $DBUSER --password=$DBPASS $DB
echo "INSERT INTO \`${DBPREFIX}user_usergroup_map\` (\`user_id\`, \`group_id\`) VALUES ('${JUSERID}', '8');" | mysql -u $DBUSER --password=$DBPASS $DB
JUSERINC= JUSERID+1
echo "ALTER TABLE \`${DBPREFIX}users\` auto_increment = ${JUSERINC};" | mysql -u $DBUSER --password=$DBPASS $DB

删除安装文件夹

rm -rf installation/