Setting the Zend DB DB2 connection’s library list to the user’s library list

Recently a friend ran into this issue. One way to correct this issue is to set the i5_libl option on the db2 connection options (http://php.net/manual/en/function.db2-connect.php). Another way to do this is by changing the job description associated with the IBM i user profile by using the command CHGJOBD in a 5250 session. You would set the INLLIBL to LIBL (library list) you want to use. Then assign the jobd
(job description) to user profile your connecting with DB2_connect or Zend_DB and the ibmdb2 adapter.

For example:

CHGJOBD JOBD(MYJOBD) INLLIBL(&MYLIB &ANOTHERLIB)

Then associate this jobd with the user profile

To Debug the issue there are a few DB2 for i services you can call from PHP via SQL and they are:

sql

Clean phone number field with IBM DB2 for i SQL REGEXP_REPLACE

Say you have a phone number in various formats but you just want the numeric characters and all the non-numeric characters removed. Well use the SQL function REGEXP_REPLACE and look for characters with the regular expression [^\d] and replace it with empty character ”. [^\d] is a negated set which means match any characters not in between [^ and ]. \d is a short hand way of saying all digit characters 0-9.

SELECT PHONE_NUMBER, REGEXP_REPLACE(PHONE_NUMBER,'[^\d]’,”)
FROM MYTABLE;

123-123-1234,1231231234

References:
IBM documentation on REGEXP_REPLACE
http://www.ibm.com/support/knowledgecenter/ssw_ibm_i_71/db2/rbafzscaregexp_replace.htm

Online regex tester tool
http://regexr.com/

A few tips on Locking down WordPress

Add the following code to your .htaccess file or into your apache vhost config so that some things will be blocked

#block wp-config.php

order allow,deny
deny from all

#block wp-login.php

order deny,allow
deny from all
#optionally add ips that you want to allow from
#Allow from 10.

#block xmlrpc.php another way to login

order deny,allow
deny from all
#optionally add ips that you want to allow from
#Allow from 10.

#block author lookup (used by hackers to get your username)
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (author=\d+) [NC]
RewriteRule .* /index.php?error=403 [L]

#block includes

RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ – [F,L]
RewriteRule !^wp-includes/ – [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ – [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php – [F,L]
RewriteRule ^wp-includes/theme-compat/ – [F,L]

Simple shell command to show 404 pages by occurrence from Apache logs

With the command below you can see all the 404 errors in your apache access logs. You’ll have to change /var/log/httpd/www.example.com-access.log to the path of your log file and change 20/Oct/2016:15 to the date and hour you want to look at
 

grep 20/Oct/2016:15 /var/log/httpd/www.example.com-access.log | grep 404 | cut -d'"' -f2,3 | awk '$4=404{print 404" "$2" "$4}' | sort | uniq -c | sort -rg

 

Setting up Vagrant

You’ll need Virtual box so download and install that

https://www.virtualbox.org/wiki/Downloads

Then you’ll need vagrant

https://www.vagrantup.com/downloads.html

You can check out the getting started guide here:

https://www.vagrantup.com/docs/getting-started/

Simple example:

Open a terminal session (iTerm2 on mac or cmder windows) and run:

vagrant init hashicorp/precise64
vagrant up
vagrant ssh
exit
vagrant destroy

Lets make our own

mkdir MyFirstVagrant
cd MyFirstVagrant/
vagrant init

Lets commit it to a github repo so we have source control on it.  Go to github.com and create a repo.  Replace the url below with your .git file.

echo "# Vagrants" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/phpdave/Vagrants.git
git push -u origin master

Lets find a box we want to add to our vagrantfile

https://atlas.hashicorp.com/boxes/search

I chose the most popular vagrant ubuntu/trusty64.  Edit the vagrantfile and Below “Vagrant.configure(“2″) do |config|” add:

config.vm.box = “ubuntu/trusty64”
config.vm.box_version = “20160926.0.1”

exit your editor and do

vagrant up
vagrant ssh

Then you have your ubuntu server to setup how you want.

Example of setting up PHP 7 dev vagrant:

https://github.com/rlerdorf/php7dev

Provisioning w/ external shell script:

  config.vm.provision "shell", path: "script.sh"

in script.sh you could run an update and install of apache, php:

sudo apt-get -y update
sudo apt-get -y install apache2 php7 libapache2-mod-php7

Give a network IP address

config.vm.network "private_network", ip: "192.168.50.4"

Want to do this on a power System?  Well VirtualBox doesnt appear to support powerpc so looks like you have to use powerkvm instead.

How to use Vagrant with PowerKVM