# Refresh packages and update
Code
apt update && apt upgrade -y
# Set timezone
Code
# Check time/date information.
timedatectl
# List all timezones.
timedatectl list-timezones
# Set one found on previous list.
timedatectl set-timezone [timezone_string_from_the_list]
# Confirm change.
timedatectl
# Create sudo user
Code
# Add user
adduser your_user_name
# Add to 'sudo' group.
usermod -aG sudo your_user_name
# Add user's SSH public key, paste it in this file.
nano ~/.ssh/authorized_keys
# Memcached
Code
# Install.
apt install memcached libmemcached-tools -y
# Confirm / version.
memcached --version
# Enable auto start.
systemctl enable memcached
# Start service.
systemctl start memcached
# Configure.
nano /etc/memcached.conf
1. Add '-S' at the end of the file after '-P /var/run/memcached/memcached.pid' to enable SASL authentication on your server.
2. Find and uncomment the '-v' directive to enable verbose logging to the '/var/log/memcache' file.
3. Uncomment the '-c 1024' directive to limit the number of simultaneous Memcached connections. Replace 1024 with your desired number of connections.
4. Find the following Memcached port directive to verify the application connection port on your server - 'Default connection port is 11211 -p 11211'
5. Find the following listen directive '-l 127.0.0.1' and '-l ::1' and verify that it's set to your server's loop back address '127.0.0.1' to only accept local Memcached connections.
5.1 (Option/otherwise) Change the address to your public IP or any like VPC address to allow external connections.
6. Save and close the file, then restart Memcached to apply the configuration changes.
systemctl restart memcached
# Secure.
# Install the SASL package on your server.
apt install sasl2-bin -y
# Create a new directory to store your SASL authentication credentials.
mkdir /etc/sasl2
# Create a new SASL configuration file to use with Memcached. For example, memcached.conf.
nano /etc/sasl2/memcached.conf
# Add the following contents to the file.
log_level: 5
mech_list: plain
sasldb_path: /etc/sasl2/memcached-sasldb2
# Save and close the file The above SASL configuration enables authentication using the Memcached database. Within the configuration:
_log_level_: Enables logging. The value 5 enables high-detail logs.
_mech_list_: Sets the authentication mechanism. The value plain enables plain username and password usage.
_sasldb_path_: Specifies the Memcached SASL database file to use for authentication.
# Create a user using the 'saslpasswd' utility. Set password when prompted.
saslpasswd2 -a memcached -c -f /etc/sasl2/memcached-sasldb2 [memcached_user]
# Grant the Memcached user memcache full privileges to the '/etc/sasl2/memcached-sasldb2' database file.
chown memcache:memcache /etc/sasl2/memcached-sasldb2
# Restart Memcached to apply the configuration changes.
systemctl restart memcached
# Connect to Memcached to test your new user credentials.
memcstat --servers="127.0.0.1" -b --username=[memcached_user] --password=[memcached_pass]
# Your output should look like this when successful:
Server: 127.0.0.1 (11211)
pid: 8317
uptime: 345
time: 1716925269
...
# Install PHP and the Memcached module
apt install php-memcached -y
# Install PEAR
apt install php-pear
# Then install pecl memcached and memcachepecl install memcache.
pecl install memcached
# Restart service.
systemctl restart memcached
# Rsnapshot
Code
Rsnapshot is rather an old timer nowadays, but for me it does the work and I find it quite solid.
# Install.
apt-get install rsnapshot
# Switch to your web user.
su - your_user_name
# Create 'scripts' and 'snapshots' folder at your user's home location.
mkdir scripts snapshots
# Place scripts in
'/home/your_user_name/scripts'
folder and make those executable.
chmod +x rsnapshotinfo.sh backup.sh drush_ops.sh
# Switch bask to root.
sudo su
# Configure.
mkdir /etc/rsnapshot.d
nano -w /etc/rsnapshot.d/html.conf
# Note, use Tabs in this and the next config instead of spaces. Enter the following:
snapshot_root /home/your_user_name/snapshots/
retain html 1
cmd_preexec /home/your_user_name/scripts/rsnapshotinfo.sh
cmd_postexec /home/your_user_name/scripts/backup.sh
backup /etc/ ./files/
backup /your/default/html/folder ./files/
# Note, rsnapshot implements 'backup_script' method. I am not using it here for the sake of Drush operations defined in 'scripts/drush_ops.sh'. It can be used similar to this, for instance to backup database:
# backup_script /home/your_user_name/scripts/mysql-backup.sh ./mysql/
# Edit main rsnapshot config. Change any desirable settings there and add the following to the bottom.
nano /etc/rsnapshot.conf
include_conf /etc/rsnapshot.d/*.conf
# Edit crontab.
crontab -e
# Enter similar to this (e.g. this runs it every day at 3:47am).
47 3 * * * /usr/bin/rsnapshot html
# Reload cron service.
service cron reload