Live Blog – 07-27-2022 – Docker, PHP Package Oneliner

Docker + Speedtest Tracker

I love that I have a Synology since I can run my own Speedtest Tracker! I was having issues on Zoom and knew it was me as I have notifications set up when my ping or up/download speed drops. You can run this on pretty much anything, a raspberry pi or a spare mac. Just install docker, and you’re off to the races!

https://github.com/henrywhitaker3/Speedtest-Tracker

Install Multiple PHP packages based on Version

Want to install a bunch of PHP packages easily via CLI for a different PHP version.? Just run the following snippet. It works in bash and zsh, and can be used with apt and yum 🙂

apt-get install php74-{mbstring,mysql}

I required smartctl command from the smartmontools package under Ubuntu, and simply running apt-get install smartmontools resulted in some recommended packages to be installed suck as mail-utils and postfix of which I required neither.

There is an option with apt, which will not install recommended packages, its --no-install-recommends as you can see in the below example.

apt-get install --no-install-recommends smartmontools

Setting up Proxmox Email Alerts

Introduction

You may not have known, but Proxmox does send out emails every so often. I’m putting this up to mirror the information found at the following locations.

https://crepaldi.us/2021/03/07/configuring-e-mail-alerts-on-your-proxmox/

1. Install the authentication library

apt-get install libasal2-modules

2. Choose an SMTP Provider

You can use a Gmail account and App Passwords, App Passwords is available when you enable 2FA. I use Postmark, because it’s the best out there and I don’t mind paying.

3. Create a password file

nano /etc/postfix/sasl_passwd

4. Insert your login details

smtp.gmail.com [email protected]:yourpassword

5. Save the password file

6. Create a database from the password file

postmap hash:/etc/postfix/sasl_passwd

7. Protect the text password file

chmod 600 /etc/postfix/sasl_passwd

8. Edit the postfix configuration file

nano /etc/postfix/main.cf

9. dd/change the following (certificates can be found in /etc/ssl/certs/):

relayhost = smtp.gmail.com:587 smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_security_options = smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache smtp_tls_session_cache_timeout = 3600s

10. Reload the updated configuration

postfix reload

11. Testing

echo "test message" | mail -s "test subject" [email protected]

NetData Installation or Upgrade – Permission Denied Temp Directory not Executable

You might have run into the following issue at some point when trying to install or upgrade Netdata.

Shell

It’s usually related to your /tmp folder is mounted without execution permission and doesn’t allow execution of programs from this location. A simple work around is to set the $TMPDIR location in your shell to a place that is mount with execution permission. As an example

Shell

Granted you don’t have to use /root/tmp it can be any location.

Xen Ubuntu 18 Guest Creation Using xen-create-image (bionic template and netplan fix included)

So I was having issues with deploying Ubuntu 18 guests on a Xen hypervisor. It originally started with a template for bionic not existing.

This is easily fixed with a couple of commands to copy the karmic.d template to bionic.d template.

However, once your host boots up. You’re now faced with a network issue as Ubuntu 18 added netplan as the default network manager.

This is fixed by replacing the /usr/share/xen-tools/40-setup-networking file with a new xen-tools 4.8 release.

Here is the github comment.

Plain Text

You can simply do the above to fix your issue, or install the latest 4.8 xen-tools at https://github.com/xen-tools/xen-tools/releases

Or you could just grab the 4.8 ubuntu package from eoan Ubuntu 19.10 at http://mirrors.kernel.org/ubuntu/pool/universe/x/xen-tools/xen-tools_4.8-1_all.deb

Installing Debian on BeagleBone Black MicroSD Card

First step is to grab the BeagleBone Debian image that you can drop on your SD card. http://beagleboard.org/latest-images Now you will need to flash this image to your MicroSD card, I’m using Mac OSX so here’s a fly by.  

sudo su - diskutil list diskutil unmountDisk /dev/diskN dd if=myImage.dd of=/dev/diskN

Tips and Tricks for Building Ubuntu Packages and Compiling

If you’re about to build packages

  • apt-get install build-essential

If you can’t find debbuild

  • apt-get install devscripts

You receive the following error

dh: unable to load addon quilt: Can't locate Debian/Debhelper/Sequence/quilt.pm in @INC (you may need to install the Debian::Debhelper::Sequence::quilt module) (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at (eval 13) line 2.
BEGIN failed--compilation aborted at (eval 13) line 2.
  • apt-get install quilt

You receive the following error

dh: unable to load addon autoreconf: Can't locate Debian/Debhelper/Sequence/autoreconf.pm in @INC (you may need to install the Debian::Debhelper::Sequence::autoreconf module) (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at (eval 15) line 2.
BEGIN failed--compilation aborted at (eval 15) line 2.
  • apt-get install dh-autoreconf

Building Ubuntu Package

  • apt-get install build-essential fakeroot dpkg-dev
  • mkdir build
  • cd build
  • sudo apt-get source foo
  • sudo apt-get build-dep foo
  • debchange
  • debuild -S -sd or debuild -us -uc -i -I

CrashPlan Error “Cound not Initialize class com.code42.jna.inotify.InotifyManager”

I had a host that wasn’t backing up at all and found the following error message within the CrashPlan engine_error.log located in /usr/local/crashplan/log

Exception in thread "W87903837_ScanWrkr" java.lang.NoClassDefFoundError: Could not initialize class com.code42.jna.inotify.InotifyManager
at com.code42.jna.inotify.JNAInotifyFileWatcherDriver.<init>(JNAInotifyFileWatcherDriver.java:21)
at com.code42.backup.path.BackupSetsManager.initFileWatcherDriver(BackupSetsManager.java:393)
at com.code42.backup.path.BackupSetsManager.startScheduledFileQueue(BackupSetsManager.java:331)
at com.code42.backup.path.BackupSetsManager.access$1600(BackupSetsManager.java:66)
at com.code42.backup.path.BackupSetsManager$ScanWorker.delay(BackupSetsManager.java:1073)
at com.code42.utils.AWorker.run(AWorker.java:158)
at java.lang.Thread.run(Thread.java:744)

From what I could tell it was related to a CentOS 6.x upgrade that may have set the noexec on /tmp which wasn’t set previously.

The error sees to be related to writing files to the /tmp directory, the following two websites I found by a simple Google search revealed this problem.

http://feeding.cloud.geek.nz/posts/crashplan-and-non-executable-tmp-directories/

https://randomwindowstips.wordpress.com/2013/02/25/crashplan-pro-for-linux-stuck-at-waiting-for-backup-or-connecting-to-backup-destination/

You have to update the CrashPlan Java options to store its temporary that isn’t mounted as “noexec” by your system

Open up  /usr/local/crashplan/bin/run.conf and add the following to the end of SRV_JAVA_OPTS

-Djava.io.tmpdir=/var/crashplan

Ubuntu PHP5-FPM NGINX

So I’ve been starting to deploy nginx on more systems, and working with php5-fpm and have had some great success. However a few issues have come to light, and it was hard to find information about these issues online. Lots of Google digging later I’ve found quite a bit about nginx and PHP5-FPM.

Configuring nginx and PHP5-FPM Chroot

The chroot function of PHP5-FPM is a great feature, however it’s rather hard to troubleshoot for instance when a blank page is displayed. This is usually related to the fact that nginx is not passing the right path and file name to PHP5-FPM. There are two important pieces of information both nginx and PHP5-FPM will need.

I’ve pasted below a copy of my nginx location code for PHP files:

location ~ \.php {
try_files $uri =404;
keepalive_timeout 0;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME public_html/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

The “SCRIPT_FILENAME” and “PATH_INFO” variables are defined within the nginx configuration for this particular domain. This is required, as this will be passed on to the PHP5-FPM daemon that will be running and processing the PHP code.

Here’s the PHP5-FPM pool for the above domain.

[doc]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = doc
group = doc
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 2
chroot = /home/doc
php_admin_value[session.save_path] = tmp

The “chroot” variable specifies the root directory the processes and children will run from, therefore they will not be able to go lower than this directory.

Looking at both pieces of code, you can see how its imperative to ensure both the “SCRIPT_FILENAME” and “chroot”  variables are correctly set to ensure that paths are correctly specified. Failure to do so will result in a blank page and no real errors messages within any of the logs for nginx or PHP5-FPM.

PHP5-FPM Chroot and MySQL

If you’re using PHP5-FPM chroot, then you might run into some error messages that will make no sense at all. I ran into the follow error that was being displayed on a MediaWiki installation.

(Can't contact the database server: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (localhost))

Upon further investigation and some Google! I’ve found this following thread that talks about how PHP is compiled and