Skip to content

Commit 746af46

Browse files
authored
20.04 (#64)
1 parent a811369 commit 746af46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3507
-1583
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
### https://www.hanssonit.se/wordpress-vm/
66

77
- Ubuntu 18.04
8-
- MariaDB 10.2
9-
- NGINX 1.16
10-
- PHP-FPM 7.2
8+
- MariaDB 10.5
9+
- NGINX 1.18
10+
- PHP-FPM 7.4
1111
- Latest Wordpress (updates automatically)
1212
- WP-CLI
1313
- Redis Cache
14+
- Igbinary for PHP
15+
- APCu Cache
1416
- and [more](https://docs.hanssonit.se/s/W6fMouPiqQz3_Mog/virtual-machines-vm/d/W7jL1OPiqQz3_MtV/wordpress-vm-machine-configuration).

addons/automatic_updates.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# T&M Hansson IT AB © - 2020, https://www.hanssonit.se/
4+
5+
# shellcheck disable=2034,2059
6+
true
7+
SCRIPT_NAME="Automatic Updates"
8+
# shellcheck source=lib.sh
9+
source /var/scripts/fetch_lib.sh || source <(curl -sL https://raw.githubusercontent.com/techandme/wordpress-vm/master/lib.sh)
10+
11+
print_text_in_color "$ICyan" "Configuring automatic updates..."
12+
13+
# Check for errors + debug code and abort if something isn't right
14+
# 1 = ON
15+
# 0 = OFF
16+
DEBUG=0
17+
debug_mode
18+
19+
# Check if root
20+
root_check
21+
22+
msg_box "This option will update your server every week on Saturdays at $AUT_UPDATES_TIME:00.
23+
The update will run the built in script '$SCRIPTS/update.sh' which will update both the server packages and Wordpress itself.
24+
25+
Please keep in mind that automatic updates might fail hence it's
26+
important to have a proper backup in place if you plan to run this option.
27+
28+
You can disable the automatic updates by entering the crontab file like this:
29+
'sudo crontab -e -u root'
30+
Then just put a hash (#) in front of the row that you want to disable.
31+
32+
In the next step you will be able to choose to proceed or exit." "$SUBTITLE"
33+
34+
if yesno_box_yes "Do you want to enable automatic updates?"
35+
then
36+
# TODO: delete the following line after a few releases. It was copied to the install-script.
37+
touch $VMLOGS/update.log
38+
crontab -u root -l | { cat; echo "0 $AUT_UPDATES_TIME * * 6 $SCRIPTS/update.sh >> $VMLOGS/update.log"; } | crontab -u root -
39+
if yesno_box_yes "Do you want to reboot your server after every update? *recommended*"
40+
then
41+
sed -i "s|exit|/sbin/shutdown -r +1|g" "$SCRIPTS"/update.sh
42+
echo "exit" >> "$SCRIPTS"/update.sh
43+
fi
44+
msg_box "Please remember to keep backups in case something should go wrong, you never know." "$SUBTITLE"
45+
fi

addons/locales.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# T&M Hansson IT AB © - 2020, https://www.hanssonit.se/
4+
5+
# shellcheck disable=2034,2059,1091
6+
true
7+
SCRIPT_NAME="Locales"
8+
# shellcheck source=lib.sh
9+
source /var/scripts/fetch_lib.sh || source <(curl -sL https://raw.githubusercontent.com/techandme/wordpress-vm/master/lib.sh)
10+
11+
# Check for errors + debug code and abort if something isn't right
12+
# 1 = ON
13+
# 0 = OFF
14+
DEBUG=0
15+
debug_mode
16+
17+
# Must be root
18+
root_check
19+
20+
##################################################################
21+
22+
# Set locales
23+
print_text_in_color "$ICyan" "Setting locales..."
24+
if [ "$KEYBOARD_LAYOUT" = "us" ]
25+
then
26+
print_text_in_color "$ICyan" "US locales are already set."
27+
elif [ "$KEYBOARD_LAYOUT" = "se" ]
28+
then
29+
sudo locale-gen "sv_SE.UTF-8" && sudo dpkg-reconfigure --frontend=noninteractive locales
30+
elif [ "$KEYBOARD_LAYOUT" = "de" ]
31+
then
32+
sudo locale-gen "de_DE.UTF-8" && sudo dpkg-reconfigure --frontend=noninteractive locales
33+
elif [ "$KEYBOARD_LAYOUT" = "us" ]
34+
then
35+
sudo locale-gen "en_US.UTF-8" && sudo dpkg-reconfigure --frontend=noninteractive locales
36+
elif [ "$KEYBOARD_LAYOUT" = "fr" ]
37+
then
38+
sudo locale-gen "fr_FR.UTF-8" && sudo dpkg-reconfigure --frontend=noninteractive locales
39+
elif [ "$KEYBOARD_LAYOUT" = "ch" ]
40+
then
41+
sudo locale-gen "de_CH.UTF-8" && sudo dpkg-reconfigure --frontend=noninteractive locales
42+
fi
43+
44+
# TODO: "localectl list-x11-keymap-layouts" and pair with "cat /etc/locale.gen | grep UTF-8"

addons/locate_mirror.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
# T&M Hansson IT AB © - 2020, https://www.hanssonit.se/
4+
5+
# shellcheck disable=2034,2059
6+
true
7+
SCRIPT_NAME="Locate Mirror"
8+
# shellcheck source=lib.sh
9+
source /var/scripts/fetch_lib.sh || source <(curl -sL https://raw.githubusercontent.com/techandme/wordpress-vm/master/lib.sh)
10+
11+
# Must be root
12+
root_check
13+
14+
# Use another method if the new one doesn't work
15+
if [ -z "$REPO" ]
16+
then
17+
REPO=$(apt update -q4 && apt-cache policy | grep http | tail -1 | awk '{print $2}')
18+
fi
19+
20+
# Check where the best mirrors are and update
21+
msg_box "To make downloads as fast as possible when updating Ubuntu \
22+
you should have download mirrors that are as close to you as possible.
23+
24+
Please note that there are no gurantees that the download mirrors \
25+
this script will find are staying up for the lifetime of this server.
26+
Because of this, we don't recommend to change the mirror, except you live far away from the default mirror.
27+
28+
This is the method used: https://github.com/jblakeman/apt-select"
29+
msg_box "Your current server repository is: $REPO"
30+
31+
if ! yesno_box_no "Do you want to try to find a better mirror?"
32+
then
33+
print_text_in_color "$ICyan" "Keeping $REPO as mirror..."
34+
sleep 1
35+
else
36+
if [[ "$KEYBOARD_LAYOUT" =~ ,|/|_ ]]
37+
then
38+
msg_box "Your keymap contains more than one language, or a special character. ($KEYBOARD_LAYOUT)
39+
This script can only handle one keymap at the time.\nThe default mirror ($REPO) will be kept."
40+
exit 1
41+
fi
42+
print_text_in_color "$ICyan" "Locating the best mirrors..."
43+
curl_to_dir https://bootstrap.pypa.io get-pip.py /tmp
44+
install_if_not python3
45+
install_if_not python3-testresources
46+
install_if_not python3-distutils
47+
cd /tmp && python3 get-pip.py
48+
pip install \
49+
--upgrade pip \
50+
apt-select
51+
check_command apt-select -m up-to-date -t 4 -c -C "$KEYBOARD_LAYOUT"
52+
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
53+
if [ -f sources.list ]
54+
then
55+
sudo mv sources.list /etc/apt/
56+
fi
57+
msg_box "The apt-mirror was successfully changed."
58+
fi
Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/bin/bash
22
# shellcheck disable=2034,2059
33
true
4+
SCRIPT_NAME="Redis Server Ubuntu"
45
# shellcheck source=lib.sh
5-
. <(curl -sL https://raw.githubusercontent.com/techandme/wordpress-vm/master/lib.sh)
6+
source /var/scripts/fetch_lib.sh || source <(curl -sL https://raw.githubusercontent.com/techandme/wordpress-vm/master/lib.sh)
67

7-
# T&M Hansson IT AB © - 2019, https://www.hanssonit.se/
8+
# T&M Hansson IT AB © - 2020, https://www.hanssonit.se/
89

910
# Check for errors + debug code and abort if something isn't right
1011
# 1 = ON
@@ -16,26 +17,24 @@ debug_mode
1617
root_check
1718

1819
# Check Ubuntu version
19-
print_text_in_color "$ICyan" "Checking server OS and version..."
20-
if [ "$OS" != 1 ]
20+
if ! version 16.04 "$DISTRO" 20.04.6
2121
then
22-
print_text_in_color "$IRed" "Ubuntu Server is required to run this script."
23-
print_text_in_color "$IRed" "Please install that distro and try again."
22+
msg_box "Your current Ubuntu version is $DISTRO but must be between 16.04 - 20.04.6 to run this script."
23+
msg_box "Please contact us to get support for upgrading your server:
24+
https://www.hanssonit.se/#contact
25+
https://shop.hanssonit.se/"
2426
exit 1
2527
fi
2628

27-
28-
if ! version 18.04 "$DISTRO" 18.04.4; then
29-
print_text_in_color "$IRed" "Ubuntu version $DISTRO must be between 18.04 - 18.04.4"
30-
exit
31-
fi
32-
3329
# Check if dir exists
3430
if [ ! -d $SCRIPTS ]
3531
then
3632
mkdir -p $SCRIPTS
3733
fi
38-
34+
35+
# Check the current PHPVER
36+
check_php
37+
3938
# Install Redis
4039
install_if_not php"$PHPVER"-dev
4140
pecl channel-update pecl.php.net
@@ -44,26 +43,17 @@ then
4443
msg_box "PHP module installation failed"
4544
exit 1
4645
else
47-
print_text_in_color "$IGreen" "PHP module installation OK!"
46+
printf "${IGreen}\nPHP module installation OK!${Color_Off}\n"
4847
fi
4948
install_if_not redis-server
5049

50+
# Setting direct to PHP-FPM as it's installed with PECL (globally doesn't work)
51+
print_text_in_color "$ICyan" "Adding extension=redis.so to $PHP_INI..."
5152
# FPM is needed for frontend
5253
echo 'extension=redis.so' >> /etc/php/"$PHPVER"/fpm/php.ini
5354
# CLI is needed for backend
5455
echo 'extension=redis.so' >> /etc/php/"$PHPVER"/cli/php.ini
55-
service php"$PHPVER"-fpm restart
56-
service nginx restart
57-
58-
# Install Redis
59-
if ! apt -y install redis-server
60-
then
61-
print_text_in_color "$IRed" "Installation failed."
62-
sleep 3
63-
exit 1
64-
else
65-
print_text_in_color "$IGreen" "Redis installation OK!"
66-
fi
56+
restart_webserver
6757

6858
## Redis performance tweaks ##
6959
if ! grep -Fxq "vm.overcommit_memory = 1" /etc/sysctl.conf
@@ -77,13 +67,19 @@ then
7767
echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
7868
fi
7969

70+
# Raise TCP backlog
71+
#if ! grep -Fxq "net.core.somaxconn" /proc/sys/net/core/somaxconn
72+
#then
73+
# sed -i "s|net.core.somaxconn.*||g" /etc/sysctl.conf
74+
# sysctl -w net.core.somaxconn=512
75+
# echo "net.core.somaxconn = 512" >> /etc/sysctl.conf
76+
#fi
8077
sed -i "s|# unixsocket .*|unixsocket $REDIS_SOCK|g" $REDIS_CONF
8178
sed -i "s|# unixsocketperm .*|unixsocketperm 777|g" $REDIS_CONF
8279
sed -i "s|^port.*|port 0|" $REDIS_CONF
8380
sed -i "s|# requirepass .*|requirepass $(cat $REDISPTXT)|g" $REDIS_CONF
8481
sed -i 's|# rename-command CONFIG ""|rename-command CONFIG ""|' $REDIS_CONF
8582
redis-cli SHUTDOWN
86-
rm -f $REDISPTXT
8783

8884
# Secure Redis
8985
chown redis:root /etc/redis/redis.conf
@@ -92,5 +88,6 @@ chmod 600 /etc/redis/redis.conf
9288
apt update -q4 & spinner_loading
9389
apt autoremove -y
9490
apt autoclean
91+
rm -f "$REDISPTXT"
9592

9693
exit

0 commit comments

Comments
 (0)