Configure SSL/HTTPS on Apache2 with OpenSSL on localhost/docker/vm etc.

sudo apt-get update
sudo apt-get install -y openssl
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/certs/privkey.pem -out /etc/ssl/certs/fullchain.pem -subj "/C=PL/ST=mazowieckie/L=Warszawa/O=NAZWA FIRMY/OU=NAZWA JEDNOSTKI/CN=localhost"
sudo a2enmod ssl

Add to 000-default.conf

<VirtualHost *:443>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    # ProxyPassMatch ^/(.*\.php)$ fcgi://php:9000/var/www/html/$1 # If we use FPM

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/fullchain.pem
    SSLCertificateKeyFile /etc/apache2/ssl/privkey.pem

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

How to add shortcut to shell script to Ubuntu Gnome dock

Tested on Ubuntu 20.04.3 LTS

Create a shell script in /path/to/my/shellscript/my_shell_script.sh

Add png icon to /home/<USER>/.icons/my-icon.png

Add a file to /home/<USER>/.local/share/applications named my_shortcut.desktop

File contents:

[Desktop Entry]
Type=Application
Name=MyShellScript
Exec=/path/to/my/shellscript/my_shell_script.sh
Icon=/home/<USER>/.icons/my-icon.png
Categories=Development;

Search in Applications – type „MyShellScript…” > Right-click > Add to favourites.

Done.

Configure PowerShell to use ssh keys

Run PowerShell as an Administrator. Generate SSH key with:

ssh-keygen -b 4096

Follow instructions.

If you didn’t enter filename, keys pair will be saved in C:\Users\<WINDOWS_USER>\.ssh\ as id_rsa and id_rsa.pub.

You can also change the name of your files or move to another directory if you want to store more keys.

Now add your private key to ssh:

ssh-add C:\Users\<WINDOWS_USER>\.ssh\<YOUR_PRIVATE_KEY_NAME>

If you get error ssh-add Error connecting to agent: No such file or directory that means you need to enable ssh-agent. You can check if that is the issue:

Get-Service -Name "ssh-agent" | select -property name,status,starttype

Service ssh-agent should be Disabled or Manual now.

Set and start ssh-agent service:

Set-Service -Name ssh-agent -StartupType Automatic
Start-Service ssh-agent

Now you can add your private key:

ssh-add C:\Users\<WINDOWS_USER>\.ssh\<YOUR_PRIVATE_KEY_NAME>

Now connect to your server and copy contents of your public key (default id_rsa.pub) to /home/<LINUX_USER>/.ssh/authorized_keys

Done. Now you can connect to your server without credentials.

ssh -p<PORT> myname@myserver.com

Handle docker error: Couldn’t connect to Docker daemon

Issue:

ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The Docker daemon always runs as the root user. If you don’t want to preface the docker command with sudo, create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.

sudo groupadd docker
sudo usermod -aG docker $USER

Now log out and log in or reboot to preserve changes.

Configuring Git to handle line endings

The git config core.autocrlf command is used to change how Git handles line endings. It takes a single argument.

On Linux, you simply pass input to the configuration. For example:

git config --global core.autocrlf input

# Configure Git to ensure line endings in files you checkout are correct for Linux

Colors in PHP CLI

Test in console:

php -r 'echo "\033[31mTEST\0330m'

Test in php file:

echo "\033[32mTEST\033[0m" . PHP_EOL;

Remember to use quotation mark instead of apostrophe.

You can set foreground and background colors.

Color codes:

FG codeBG codeColor
3040Black
3141Red
3242Green
3343Yellow
3444Blue
3545Magenta
3646Cyan
3747White
90100Bright Black (Gray)
91101Bright Red
92102Bright Green
93103Bright Yellow
94104Bright Blue
95105Bright Magenta
96106Bright Cyan
97107Bright White