Blog

Ubuntu 18.04 install WordPress

sudo apt update
sudo apt upgrade -y
sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-curl -y  

Download the latest version of WordPress

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
sudo mv wordpress /var/www/
sudo chown -R www-data: /var/www/wordpress

Now configure the site

cd /etc/apache2/sites-available
sudo cp 000-default.conf wordpress.conf
cd ../sites-enabled
sudo ln -s ../sites-available/wordpress.conf . 
sudo vim wordpress.conf

Edit the content

 <VirtualHost *:80>
   ServerName wordpress.oofnivek.com
   ServerAdmin [email protected]
   DocumentRoot /var/www/wordpress
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
   <Directory /var/www/wordpress>
     Options Indexes FollowSymLinks MultiViews
     AllowOverride All
     Require all granted
   </Directory>
 </VirtualHost> 

Enable rewrite module and restart Apache

sudo a2enmod rewrite
sudo systemctl restart apache2

Configure MySQL

sudo mysql -uroot
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
SELECT user,host,plugin FROM mysql.user;
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Lastly point wordpress.oofnivek.com to the server IP

Git commands

To clone a project, use the command below. Sample command below clone from a dummy repository I had created.

git clone https://github.com/oofnivek/dummy-repository.git

To set your git configurations for all projects.

git config --global user.name "Kevin FOO"
git config --global user.email "[email protected]"
git config --global core.editor "vim"

To edit the configurations in the git global setting file.

git config --global --edit

Say you had your changes made, add/edit/delete. To commit your changes, use commands below.

git add .
git commit
git push

Ubuntu install puppeteer

Installing puppeteer into a fresh AWS EC2 Ubuntu 18.04 and its dependencies.

sudo apt update
sudo apt upgrade
sudo apt install npm
npm i puppeteer

Now run a simple puppeteer script and you will encounter errors about missing shared libraries. A simple script below, lets name it simple.js

const puppeteer = require('puppeteer');
async function run () {
   const browser = await puppeteer.launch({
      defaultViewport: {width: 1920, height: 1080}
   });
   const page = await browser.newPage();
   await page.goto('https://www.google.com/search?q=bitcoin');
   await page.screenshot({path: 'screenshot.png'});
   browser.close();
}
run(); 
node simple.js

Now install the dependencies and rerun.

sudo apt install libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi-dev libxtst-dev libnss3 libcups2 libxss1 libxrandr2 libasound2 libatk1.0-0 libatk-bridge2.0-0 libpangocairo-1.0-0 libgtk-3-0

Simple puppeteer script to google for search results.

const puppeteer = require('puppeteer');
 const fs = require("fs");
 async function run () {
   const browser = await puppeteer.launch({
     defaultViewport: {width: 1920, height: 1080}
   });
   const page = await browser.newPage();
   await page.goto('https://www.google.com');
   await page.waitFor('input[class="gLFyf gsfi"]');
   await page.$eval('input[class="gLFyf gsfi"]', el => el.value = 'bitcoin');
   await page.$eval('input[class="gNO89b"]', el => el.click());
 await page.waitForSelector('div#result-stats');
   await page.screenshot({ path: 'screenshot.png' });
 const html = await page.content()
   fs.writeFileSync("page.html", html);
 browser.close();
 }
 run();

Ubuntu install squid

Setting up undetectable proxy in a fresh new Ubuntu 18.04 in AWS EC2

sudo apt update
sudo apt upgrade
sudo apt install squid apache2-utils 

Create a credential file and add user.

sudo touch /etc/squid/passwd
sudo chown proxy: /etc/squid/passwd
sudo htpasswd /etc/squid/passwd oofnivek

Edit the configuration file at /etc/squid/squid.conf . Change the settings to the following below

forwarded_for delete
via off
request_header_access Cache-Control deny all 

Right below the acl ports. Add these.

auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid Basic Authentication
auth_param basic credentialsttl 2 hours
acl auth_users proxy_auth REQUIRED
http_access allow auth_users

Restart squid for changes to take effect.

sudo systemctl restart squid

Ubuntu install golang

As usual, before installing anything in Ubuntu, run

sudo apt update
sudo apt upgrade

Once done, you can start installing golang. The easiest method to install using the below command.

sudo apt install golang-go

Next is to test if you had successfully install golang. Create a hello.go file, paste the contents below into the hello.go file and save it.

package main

import "fmt"

func main() {
    fmt.Println("hello world")
}

To execute the file, run the command below.

go run hello.go

Ubuntu install sysstat

Ubuntu install sysstat

sudo apt install sysstat

Once installation completed, enable sysstat by setting the value to true.

sudo vim /etc/default/sysstat

ubuntu-install-sysstat-01

After that restart the sysstat service

sudo service sysstat restart

By default sysstat sample the CPU usage every 10 minutes at 5, 15, 25, 35, 45 and 55 minutes of the hour. To modify it,

sudo vim /etc/cron.d/sysstat

ubuntu-install-sysstat-02

Viewing the stats

To view latest stats

sar

To view yesterday’s stats

sar -f /var/log/sysstat/sa$(date +%d -d 'yesterday')

To view specific date stats

sar -f /var/log/sysstat/sa$(date +%d -d '2019-04-27')

 

Dynamic IP using Cloudflare

Dynamic IP using Cloudflare

I previously posted an article about updating your DNS with your dynamic IP using paid service noip.com. I recently found out that you can do the same for free using Cloudflare.

Assumptions

  1. Registered an account with Cloudflare.
  2. Domain configured and active in Cloudflare. If not, read my post on how to configure one.
  3. Installed curl and jq.

Copy the content below into update.sh.

#!/bin/bash
json='Content-Type: application/json'
email='YOUR_EMAIL_HERE'
api_key='YOUR_GLOBAL_API_KEY_HERE'
zone_id='YOUR_ZONE_ID_HERE'
domain='www1.oofnivek.com'
dns_id=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?type=A&name=$domain" -H "X-Auth-Email: $email" -H "X-Auth-Key: $api_key" -H "$json"|jq -r .result[0].id)
#echo -n $dns_id
ip=$(curl checkip.amazonaws.com)
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$dns_id" -H "X-Auth-Email: $email" -H "X-Auth-Key: $api_key" -H "$json" \
--data '{"type":"A","name":"'$domain'","content":"'$ip'","ttl":1,"proxied":true}'

dynamic-ip-using-cloudflare
Create a sub domain for you to update dynamically

dynamic-ip-using-cloudflare
This is where you can get your global API key

dynamic-ip-using-cloudflare
Once clicked [View], your API key will be shown

dynamic-ip-using-cloudflare
You can get your Zone ID here

The API I used can be found here

List DNS Records

Update DNS Record

 

Dynamic IP using noip.com

Dynamic IP using noip.com

Assumptions

  1. Ubuntu/Linux machine running at home with dynamic IP.
  2. Ubuntu/Linux machine is configured in DMZ or has port 80 forwarded to it.
  3. Registerd a free account at noip.com.

Bash script below to automatically get your external IP and and update noip.com. After that put this script to run as a cron job.

myip=$(curl checkip.amazonaws.com)
username='oofnivek'
password='password'
hostname='oofnivek.ddns.me'
curl http://$username:$password@dynupdate.no-ip.com/nic/update?hostname=$hostname&myip=$myip

ubuntu-update-dynamic-ip

 

 

 

Ubuntu install Plex media server

Ubuntu install Plex media server

Go to Plex website to get the download URL

ubuntu-install-plex-media-server

cd /tmp
wget https://downloads.plex.tv/plex-media-server/1.14.1.5488-cc260c476/plexmediaserver_1.14.1.5488-cc260c476_amd64.deb
sudo dpkg -i plexmediaserver_1.14.1.5488-cc260c476_amd64.deb
systemctl status plexmediaserver

ubuntu-install-plex-media-server

Go to http://127.0.0.1:32400/web and start configuring your Plex

Assuming that the videos are in your external hard disk connected to your Ubuntu desktop. You’ll need to run these commands to give user plex to access your drive.

MYGROUP="$USER"
sudo usermod -a -G $MYGROUP plex
sudo chown $USER:$MYGROUP /media/$USER
sudo chmod 750 /media/$USER
sudo setfacl -m g:$MYGROUP:rwx /media/$USER
sudo service plexmediaserver restart

to check your group or the group user plex is in

groups
groups plex