Monthly Archives: September 2016

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

Advertisements

Execute SQL remotely on an IBM i via PHP’s PDO ODBC from a Windows or Linux

You’ll first have to configure an ODBC connection “System DSN”/”System Data Source” via the “iSeries Access ODBC driver” or it might be call the IBM i Access driver which you can learn how to download and install here:

http://www-01.ibm.com/support/docview.wss?uid=nas8N1010355

Here’s some of the ways to configure the odbc connection

https://godzillai5.wordpress.com/2015/07/08/setting-a-default-sql-library-and-library-list-on-a-odbc-connection-for-a-ibmi-db2-connection-in-windows-and-linux/

Once you have the ODBC connection setup you can use it in PHP and here’s a Simple Example on how to execute SQL remotely and safely on an IBM i via ODBC.  Note you won’t want to dump the error info in production its there to alert you about errors.

Here’s an example on how to run a SQL extenal stored procedure

 

Make sure to enable SSL to encrypt your SQL statements that are sent

 

Windows

Run C:\Windows\SysWOW64\odbcad32.exe and edit connection options and make sure ssl is selected or IBM i navigator is defaulted to sslodbc windows secure.png

Linux 

Setup stunnel

guide is here: under 2.6 Encrypt the connection with Secure Sockets Layer

Other References:
Windows: http://www-03.ibm.com/systems/power/software/i/access/windows.html
Linux: http://www-03.ibm.com/systems/power/software/i/access/linux.html