Best way to start a process in background and logout on Linux

I very often have to start a process on Linux and logout leaving it running. I used to do a nohub.

nohub /path/to/some/pogram &

This does work but seeing the output of it you probably have to pipe the output to file like

nohub /path/to/some/pogram > /path/to/output &

But i will show you a better way SCREEN to the rescue to install:

sudo apt-get install screen

then simply run screen before you run the process and to disconnect the terminal and leave it running do a CRTL-A D which will take you back to the calling shell and you can log out leaving it running. You can do this with multiple processes.

to access it again type

screen -r

There are several suitable screens on:
	6078.your-server-detail	(SOMEDATE)	(Detached)
	4249.your-server-detail	(SOMEDATE)	(Detached)

and to reconnect do

screen -r 4249

This is ideal if you have to start some docker processes on remote servers.

Docker Short Cheat Sheet

To stop all docker containers:

$ docker stop $(docker ps -a -q)

Then to remove all docker containers:

$ docker rm $(docker ps -a -q)

To remove all docker images:

$ docker rmi $(docker images -q)

Stop specific docker container:

docker ps -a
then copy container is ie: c38ba5c03ab7
docker stop c38ba5c03ab7

Run bash shell in docker image:

$ docker exec -it RUNNING_CONTAINER_NAME /bin/bash

Linux File Permissions

Let’s take a look at our ls -l output and look the first column of the listing:

touch myfile 
ls -l myfile
-rw-rw-r-- 1 hano hano 0 Apr 16 08:57 myfile
sudo chown hano.root myfile
ls -l myfile 
-rw-rw-r-- 1 hano root 0 Apr 16 08:57 myfile

The you have 3 access value bits in this case rw- for the owner in this case hano then rw- for the group which corresponds to the root group and then all other users r–.

rRead Access
wWrite Access
xExecute Access

To change the access use chmod (Change Mod)

chmod 754 myfile
ls -l myfile 
-rwxr-xr-- 1 hano root 0 Apr 16 08:57 myfile
ModeDecimal
rwx7
rw-6
r-w5
r–4
-wx3
-w-2
–x1
0

If you know binary you will notice that it is the decimal value of binary digits 001 = 1 010 = 2 100 = 4 so combinations will then be 101 = 4 + 1 = 5 corresponding to r-w

Build pdo_oci.so (or oci8.so) on SLES 11.4 and Oracle 12.1

I recently had to build pdo_oci.so and I could not find a proper guide to do it. Hopefully this one will help someone.

create a file on document root called test.php

vi /srv/www/htdocs/test.php
<?php
phpinfo();
?>

Browse to http://yourserverip/test.php, on top is the version mine is 5.3.17
Download the correct source http://php.net/releases/ I used this link http://museum.php.net/php5/php-5.3.17.tar.gz
Now copy the downloaded source to ~/php-build

tar -zxvf php-5.3.17.tar.gz
cd php-5.3.17

Oracle Server installed


I have Oracle 12.1 Server installed on the box so I have ensured the my ORACLE_HOME is correct. Read the docs if you want to use the instant client.

./configure  --with-apxs2=/usr/sbin/apxs2 --with-pdo-oci=shared --with-oci8=shared --with-config-file-path=/etc/php5/apache2/php.ini --with-config-file-scan-dir=/etc/php5/apache2  --with-ldap
make 
cd ext/pdo_oci
;edit the config.m4 file
vi config.m4

search for 11
and change

case $PDO_OCI_VERSION in
9.0|10.1|10.2|11.1|11.2)
PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
;;

to
case $PDO_OCI_VERSION in
9.0|10.1|10.2|11.1|11.2|12.1|12.2)
PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
;;

do a pwd make sure you are in ext/pdo_oci directory

phpize
./configure --enable-shared
make

Instant Client

For the instant client you might get error like:
checking Oracle Instant Client library version compatibility… configure: error: Link from /usr/lib/oracle/libclntsh.so to /usr/lib/oracle/libclntsh.so.*

cd /usr/lib/oracle
sudo ln libclntsh.so.12.1 libclntsh.so

Then configure like

./configure  --with-apxs2=/usr/bin/apxs2 --with-pdo-oci=shared,instantclient,/usr/lib/oracle --with-oci8=shared,instantclient,/usr/lib/oracle

To Build the shared object

cd ext/oci8/
phpize
./configure --enable-shared -with-oci8=instantclient,/usr/lib/oracle
make

OR PDO_OCI

cd ext/pdo_oci
phpize
./configure --enable-shared -with-pdo-oci=instantclient,/usr/lib/oracle
make
now there should be a folder modules cd modules ls -l ;should show a pdo_oci.so sudo cp pdo_oci.so /usr/lib64/php5/extensions cd /etc/php5/conf.d/ sudo vi pdo_oci.ini

Add the following to the file :

; comment out next line to disable pdo_oci extension in php
extension=pdo_oci.so

tail -f /var/log/apache2/error.log
if you get
Unable to load dynamic library ‘pdo_oci.so’ (tried: /usr/lib/php/[SOMENUMBER]/pdo_oci.so (libmql1.so: cannot open shared object file: No such file or directory)

Add Oracle libs to the LD_LIBRARY_PATH

cd /etc/ld.so.conf.d
#Create file oracle and add /usr/lib/oracle
sudo vi oracle

and if that does not work then

cd /etc/apache2/
sudo vi envvars 
#and add 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle
#to the end of the file

Restart the apache server or you can do
php -i | grep pdo
to see if its loaded.

Python update to fix Kodi on linux (Ubuntu and mint)

I had issues with my Kodi 17.6 on linux. I have noticed errors involving cryptography and ffi. Here is the procedure that I followed to fix it.
Open a Terminal and do the following:

 sudo apt-get install build-essential libssl-dev libffi-dev python-dev python-pip

After its done then install cryptography for python

pip install cryptography

It will prompt to install update pip BUT DONT DO THAT IT WILL BREAK THINGS.

PHP 7.0 to PHP 5.6 on Ubuntu / Linux Mint

Parse error: syntax error, unexpected ‘new’ (T_NEW) in /usr/share/php/MDB2/Driver/pgsql.php on line 925

The problem is that MDB2 is not supported for PHP7.0
It is better to use PDO PHP PDO but if you cant then here is how to downgrade to PHP5.6.

dpkg -l | grep php| awk '{print $2}' |tr "\n" " "

I like to do it manually so copy the above output to the command

sudo apt-get purge libapache2-mod-php7.0 php php-common php-gettext php-mdb2 php-pear php-pgsql php-phpseclib php-xml php7.0 php7.0-cli php7.0-common php7.0-dev php7.0-fpm php7.0-gd php7.0-intl php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-pgsql php7.0-readline php7.0-xml php7.0-zip 
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6

Verify php 5.6

php -v

PHP 5.6.36-1+ubuntu16.04.1+deb.sury.org+1 (cli)
Then restart apache2.0

sudo /etc/init.d/apache2 restart

Dont forget to install PEAR again

sudo apt-get install php-mdb2
apt-cache search mdb2
sudo apt-get install php-mdb2-driver-pgsql
sudo apt-get install php5.6-pgsql

Linux Mint Distribution Comparison to Ubuntu and Debian

My favourite Linux Distribution is Linux Mint and every so often you need to add a custom deb resource and the only ones out there is for Ubuntu or debian.

The latest Mint code names can be found at:

https://linuxmint.com/download_all.php

To help here is a list of distribution names from Ubuntu.

https://wiki.ubuntu.com/Releases

Ubuntu 19.10

Eoan Ermine

Release Notes

October 17, 2019

July 2020

July 2020

Ubuntu 18.04.4 LTS

Bionic Beaver

Changes

February 12, 2020

April 2023

April 2028

Ubuntu 18.04.3 LTS

Bionic Beaver

Changes

August 8, 2019

April 2023

April 2028

Ubuntu 18.04.2 LTS

Bionic Beaver

Changes

February 15, 2019

April 2023

April 2028

Ubuntu 18.04.1 LTS

Bionic Beaver

Changes

July 26, 2018

April 2023

April 2028

Ubuntu 18.04 LTS

Bionic Beaver

Release Notes

April 26, 2018

April 2023

April 2028

Ubuntu 16.04.6 LTS

Xenial Xerus

Changes

February 28, 2019

April 2021

April 2024

Ubuntu 16.04.5 LTS

Xenial Xerus

Changes

August 2, 2018

April 2021

April 2024

Ubuntu 16.04.4 LTS

Xenial Xerus

Changes

March 1, 2018

April 2021

April 2024

Ubuntu 16.04.3 LTS

Xenial Xerus

Changes

August 3, 2017

April 2021

April 2024

Ubuntu 16.04.2 LTS

Xenial Xerus

Changes

February 16, 2017

April 2021

April 2024

Ubuntu 16.04.1 LTS

Xenial Xerus

Changes

July 21, 2016

April 2021

April 2024

Ubuntu 16.04 LTS

Xenial Xerus

Release Notes

April 21, 2016

April 2021

April 2024

Ubuntu 14.04.6 LTS

Trusty Tahr

Changes

March 7, 2019

April 2019

April 2022

Ubuntu 14.04.5 LTS

Trusty Tahr

Changes

August 4, 2016

April 2019

April 2022

Ubuntu 14.04.4 LTS

Trusty Tahr

Changes

February 18, 2016

HWE August 2016

April 2022

Ubuntu 14.04.3 LTS

Trusty Tahr

Changes

August 6, 2015

HWE August 2016

April 2022

Ubuntu 14.04.2 LTS

Trusty Tahr

Changes

February 20, 2015

HWE August 2016

April 2022

Ubuntu 14.04.1 LTS

Trusty Tahr

Changes

July 24, 2014

April 2019

April 2022

Ubuntu 14.04 LTS

Trusty Tahr

Release Notes

April 17, 2014

April 2019

April 2022

Debian can be found in a file called

cat /etc/debian_version

18.04  bionic     buster  / sid
17.10  artful     stretch / sid
17.04  zesty      stretch / sid
16.10  yakkety    stretch / sid
16.04  xenial     stretch / sid
15.10  wily       jessie  / sid
15.04  vivid      jessie  / sid
14.10  utopic     jessie  / sid
14.04  trusty     jessie  / sid
13.10  saucy      wheezy  / sid
13.04  raring     wheezy  / sid
12.10  quantal    wheezy  / sid
12.04  precise    wheezy  / sid
11.10  oneiric    wheezy  / sid
11.04  natty      squeeze / sid
10.10  maverick   squeeze / sid
10.04  lucid      squeeze / sid

PHP 7.0 Apache Oracle 12 Instantclient OCI8 install apt-get

If you need to do this from scratch I have followed these how-to-install-and-configure-php-70-or-php-71-on-ubuntu-16-04 insructions to install PHP7.0 and apache.

Once installed then
Follow these instructions to compile oci8 extentions Oracle tech note OCI8

Download the instant client from oracle’s web site here : Oracle instant client download
I downloaded the .ZIP files since I dont have RPM installed.
I then extracted it to ~/Downloads/instantclient_12_2
NOTE: Download the instantclient-basic-linux.x64-12.2.0.1.0.zip and instantclient-sdk-linux.x64-12.2.0.1.0.zip

cd ~Downloads
unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip

Now we need to create the paths

sudo mkdir /usr/lib/oracle
sudo mkdir /usr/lib/oracle/12.2
sudo mkdir /usr/lib/oracle/12.2/client64
sudo mkdir /usr/lib/oracle/12.2/client64/lib
cd ~/Downloads/instantclient_12_2
sudo cp * /usr/lib/oracle/12.2/client64/lib/
cd /usr/lib/oracle/12.2/client64/lib/
ln -s libclntsh.so.12.1 libclntsh.so
sudo mkdir /usr/include/oracle
sudo mkdir /usr/include/oracle/12.2
sudo mkdir /usr/include/oracle/12.2/client64
cd ~/Downloads/instantclient_12_2/sdk/include
sudo cp * /usr/include/oracle/12.2/client64
export ORACLE_HOME=/usr/lib/oracle/12.2

Edit ld.so.conf and include oracle libs. Add a file called oracle.conf under /etc/ld.so.conf.d

cd /etc/ld.so.conf.d
sudo vi oracle.conf
PRESS ESC i
/usr/lib/oracle/12.2/client64/lib
PRESS ESC :wq

Now to download and compile OCI8

sudo pecl install oci8 --with-oci8=instantclient,/usr/lib/oracle/12.2/client64/lib

On My machine it compiled it under ‘/usr/lib/php/20151012/oci8.so’ but look at the last few lines it should echo it.

First lets install a page to test that the configuration works.

sudo vi /var/www/html/t.php ( or xed /var/www/html/t.php if you dont know vi)
Press ESC i and paste

Press ESC :qw

now open your favorite browser and go to http://localhost/t.php and you should see a information page of php

to configure php do:

cd /etc/php/7.0/mods-available
vi oci8.ini

Edit oci8.ini with content

extension=oci8.so

Now restart

sudo service apache2 restart

My Installation now gave an error

apachectl configtest
if you get an error about libaio.so.1: cannot open shared object file: No such file or directory

sudo apt-get install libaio1 libaio-dev

Now we need to give the path to the libraries.
Edit /etc/apache2/envvars and add the flowing to the bottom of the file

ORACLE_HOME=/usr/lib/oracle/12.2/client64
LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib
LD_LIBRARY_PATH64=/usr/lib/oracle/12.2/client64/lib/
#TNS_ADMIN=$ORACLE_HOME/network/admin
#NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252
#ORACLE_SID=your_db

To Test

php --ri oci8

PHP Active Directory Authentication using Self Signed SSL Cert (LDAPS://)

Here is the steps I followed to get the domain controller’s SSL CA cert and configure PHP with LDAP to do LDAPS authentication on Active Directory (Domain Controller AD).

  • First let get the CA cert. If you dont have it, it can be done via openssl.
  • To get the CA cert

    openssl s_client -connect YOUR_WINDOWS_DOMAIN_NAME.YOUR_DOMAIN_EXTENTION:636

    you will see all the values but what we are interested in is the –BEGIN CERTIFICATE — and –END CERTIFICATE—
    so save all the output to a file :

    openssl s_client -connect YOUR_WINDOWS_DOMAIN_NAME.YOUR_DOMAIN_EXTENTION:636 > ca_cert.pem

    then edit it: vi ca_cert.pem (or xed ca_cert.pem) and delete everything only leaving the –BEGIN CERTIFICATE — …. –END CERTIFICATE— including the –BEGIN CERTIFICATE — and –END CERTIFICATE— tages.

    Rename the file to a more descriptive name for your CA
    mv ca_cert.pem MyCA.pem

    To make sure you have the right Domain you can always do a nslookup to verify the domain controllers.
    nslookup
    set type=ANY
    your_microsoft_domain.your_web_domain.com

  • Now to install the new CA cert on the server
  • To see where the cert dir is located do a : openssl version -d
    (Mine was /etc/openssl/certs)
    so I copy
    cp ca_cert.pem /etc/openssl/certs
    and to create the HASH (You can do below or try running c_rehash in /etc/openssl/certs )

    openssl x509 -noout -hash -in ca-certificate-file

    grab the output hash (ie 23456789d)
    then do a link
    ln -s MaCA.crt 23456789d.0

  • New verify the installed certificate

  • openssl s_client -connect ANY_OF_THE_LDAP_SERVERS_GET_LIST_FROM_NSLOOKUP:636 -CAfile
    /etc/ssl/certs/MyCA.pem -verify 0

  • Now to configure the LDAP to use secure LDAPS
  • Here is the tricky part. I have found that my PHP does not pick up the changes I have made on /etc/openldap/ldap.conf .
    but start there first edit : xed /etc/openldap/ldap.conf (or vi /etc/openldap/ldap.conf if you prefer)
    add these lines:
    TLS_CACERT /etc/ssl/certs/23456789d.0

    You can always add this to ensure that you accept all certificates
    TLS_REQCERT allow

    now test and to see any errors you can do a
    sudo tail -f /var/log/apache2/error_log to see the errors

    If it does not work (Like on my UNIX box HP-UX) then on your phpinfo(); page under “Environment” look for variable HOME and lets say its
    /svr/www
    cp /etc/openldap/ldap.conf /srv/www/.ldaprc

  • Using PHP to autenticate
  • Now when its configured now you can use Active Directory Include from Source Forge