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