使用 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/