Code Snippets: Replace lines on multiple files

find . -type f -exec sed -i 's/$result2 = mysql_query($sql2, $link)/$result2 = $conn->query($sql2)/gI' {} \;

Find files in the current directory and search for a string similar to the one on the first / / block (in italics) and replace that with the string on the second / / block.

I recently used this to update the MySQL connection code on an old school project that I did. As I found out, the mysql_query (and other similar commands) have been deprecated already my the newer MySQLi commands.


Quick Notes: nginx as load balancer to Apache

Environment:

2 Apache web servers (on Debian 9) behind an nginx load balancer (on CentOS 6.10)

Configuration:

The configuration below allows the nginx to load balance between the two Apache web servers. Session persistence is done via the ip_hash directive on the nginx.

The X-Forwarded is also set on the nginx and Apache is configured such that the Apache logs will have the real client public IP addresses instead of the nginx IP address.

    
nginx.conf

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;

    #  server directive below are the web server IP's
    upstream itproject {
        ip_hash;
        server x.x.x.x;
        server x.x.x.x;
    }

    #  server_name is the publicly accessible FQDN or IP
    server {
        listen 80;
        server_name x.x.x.x;
        location / {
            proxy_pass http://itproject;
        }
    }
apache.conf

#LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

On the web servers do:

sudo apt-get install libapache2-mod-rpaf
sudo systemctl restart apache2

Quick Notes: Install Docker CE on Ubuntu 18.04 LTS

$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.

$ sudo apt-key fingerprint 0EBFCD88
 Setup stable repository: 

$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
$ sudo apt-get update

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Verify that Docker CE is installed correctly by running the hello-world image.

$ sudo docker run hello-world
$ sudo systemctl enable docker 

Reference:

Get Docker CE for Ubuntu

Quick Notes : Branches in Git

New branch:
git branch new_branch

Switch to new branch:
git checkout new_branch

List branches:
git branch -a

Delete a branch:
git push origin --delete branch_name

Push branch to remote repository:
git push -u origin branch_name

Clone branch from remote repository:
git clone -b branch_name https://remote-repo.git

Deprecated Linux networking commands

Deprecated Linux networking commands

I’ve been using Linux (and other *NIX variants ) since the late 1990’s and I’ve been used to having the usual networking commands like ifconfig, arp, netstat.

I’ve always known these past few years that they have been deprecated already, and there have been a couple of times I’ve tried using the newer iproute2 commands. But since I’m used to these deprecated commands, it’s what I’ve always been using. The Linux servers I’ve been managing so far also had these deprecated commands available, so there has been no compelling reason for me to switch.

Anyway, I thought it’s time I started using the newer iproute2 commands more frequently. Below is a table of some of the frequently used commands and their iproute2 equivalent.

Deprecated Equivalent iproute2 command
arp -aip n show
ifconfigip addr show
netstatss