#!/bin/bash
######系統配合
#下載ISO檔
#https://ftp.ubuntu-tw.org/ubuntu-releases/26.04.1/ 安裝
######鄭亮星 jls@mail.jls.idv.tw , jls550225@gmail.com , jls@acfs.tw
##安裝及設定 apache2 php 基本功能
ETH0=$(ls /proc/net/dev_snmp6 |awk '{ print $1 }' |sed -n '1p')
ETH1=$(ls /proc/net/dev_snmp6 |awk '{ print $1 }' |sed -n '2p')
IP=$(ifconfig $ETH0 |grep 'inet ' |awk '{print $2}')
DOMAINNAME=$(/bin/hostname -d)
DATE=$(date "+%Y%m%d%H")
sync
. /root/setup.txt
sync
mkdir -p /var/log/scoreboard
chown www-data:www-data -R /var/log/scoreboard
find /etc/php/8.5/apache2/php.ini -type f -exec perl -i -pe s/"error_reporting = E_ALL & ~E_DEPRECATED"/"error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT"/g {} \;
find /etc/php/8.5/apache2/php.ini -type f -exec perl -i -pe s/"post_max_size = 8M"/"post_max_size = 500M"/g {} \;
find /etc/php/8.5/apache2/php.ini -type f -exec perl -i -pe s/"upload_max_filesize = 2M"/"upload_max_filesize = 500M"/g {} \;
#find /etc/php/8.5/apache2/php.ini -type f -exec perl -i -pe s/"session.auto_start = 0"/"session.auto_start = 1"/g {} \;
find /etc/php/8.5/apache2/php.ini -type f -exec perl -i -pe s/"short_open_tag = Off"/"short_open_tag = On"/g {} \;
find /etc/php/8.5/apache2/php.ini -type f -exec perl -i -pe s/";date.timezone ="/"date.timezone = Asia\/Taipei"/g {} \;
#find /etc/php/8.5/apache2/php.ini -type f -exec perl -i -pe s/"magic_quotes_gpc = Off"/"magic_quotes_gpc = On"/g {} \;
find /etc/php/8.5/apache2/php.ini -type f -exec perl -i -pe s/"memory_limit = 128M"/"memory_limit = 1024M"/g {} \;
cp -arf /etc/apache2/apache2.conf /etc/apache2/apache2.conf-$DATE
cat >> /etc/apache2/apache2.conf << EOF
#
# Options FollowSymLinks
# AllowOverride None
#
#
# AllowOverride All
#
Options FollowSymLinks
AllowOverride All
#
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
#
AllowOverride All
# Allow open access:
Require all granted
AddHandler php5-script .php .php3 .php4 .php5 .inf .ini .inc .bak .old
DirectoryIndex index.html index.php index.htm index.php3
EOF
cat > /etc/apache2/sites-available/https_443.conf << EOF
# NameVirtualHost *:443
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/wordpress
ServerName $DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
SetHandler cband-status
Order allow,deny
Allow from all
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/$DOMAINNAME
# CBandExceededURL https://$DOMAINNAME/cband_error.html
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/wordpress
ServerName www.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/www.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/www.$DOMAINNAME
# CBandExceededURL https://$DOMAINNAME/cband_error.html
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/webmail
ScriptAlias /mail/ /var/www/webmail/mail/
ServerName webmail.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/webmail.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/webmail.$DOMAINNAME
# CBandExceededURL https://$DOMAINNAME/cband_error.html
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/lib/bandwidthd/htdocs
ServerName bandwidthd.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/bandwidthd.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/bandwidthd.$DOMAINNAME
# CBandExceededURL https://$DOMAINNAME/cband_error.html
#------------------------------------------------------------------------------------------------------------------------
AddDefaultCharset Big5
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/mrtg
ServerName mrtg.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/mrtg.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/mrtg.$DOMAINNAME
# CBandExceededURL https://$DOMAINNAME/cband_error.html
EOF
cat > /etc/apache2/sites-available/http_80.conf << EOF
# NameVirtualHost *:80
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/wordpress
ServerName $DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
SetHandler cband-status
Order allow,deny
Allow from all
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/$DOMAINNAME
# CBandExceededURL http://$DOMAINNAME/cband_error.html
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/wordpress
ServerName www.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/www.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/www.$DOMAINNAME
# CBandExceededURL http://$DOMAINNAME/cband_error.html
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/webmail
ScriptAlias /mail/ /var/www/webmail/mail/
ServerName webmail.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/webmail.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/webmail.$DOMAINNAME
# CBandExceededURL http://$DOMAINNAME/cband_error.html
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/lib/bandwidthd/htdocs
ServerName bandwidthd.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/bandwidthd.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/ndwidthd.$DOMAINNAME
# CBandExceededURL http://$DOMAINNAME/cband_error.html
#------------------------------------------------------------------------------------------------------------------------
AddDefaultCharset Big5
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/mrtg
ServerName mrtg.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/mrtg.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/mrtg.$DOMAINNAME
# CBandExceededURL http://$DOMAINNAME/cband_error.html
EOF
a2ensite http_80.conf
a2ensite https_443.conf
a2enconf bandwidthd
cat > /var/www/wordpress/phpinfo.php << EOF
EOF
cat > /var/www/html/cband_error.html << EOF
EOF
systemctl restart named.service
systemctl restart apache2.service
clear
read -p "請輸入 WordPress 的資料庫名稱並使用它建置網站:" WordPress
mysqladmin -uroot -p$Mysqlpasswd create $WordPress;
clear
## 繁體中文下載處
# https://tw.wordpress.org/download/#download-install
# wget https://tw.wordpress.org/latest-zh_TW.zip
unzip latest-zh_TW.zip -d /var/www
chown -R www-data:www-data /var/www/wordpress
sync
sync
systemctl restart named.service
systemctl restart apache2.service
clear
echo "請開啟瀏覽器,在網址列輸入 http://www.$DOMAINNAME 來完成 WordPress 網站建置設定。"