Random writings on software & product development, running, business and anything else

Category: Software Development (Page 1 of 7)

Software development from languages like PHP to specific tools, books etc.

VirtualBox with Static IP on Ubuntu Server Guest

Setup for the following technology:

  • Windows 10 as host machine
  • VirtualBox 6.0.18
  • Guest OS is Ubuntu 20.04 (Focal Fossa) Server Beta [other versions since around 17.10 will work]

The aim is being able to access the guest on a static IP from the host to upload/download files and for the guest to be able to access the internet for API access to external services, apt update etc.


For this to happen the VM needs 2 network adapters:

  • a host-only network adapter and configure the VM with a static IP address (for host to guest access)
  • NAT network adapter (for access to the outside world)

To begin it is assumed you have downloaded the relevant Ubuntu iso file, created a new virtual machine through VirtualBox and gone through that install process. Do a sudo apt update & sudo apt upgrade to have the OS up to date and then sudo shutdown now.

Back in VirtualBox. For this VM, choose settings and the Network.

VirtualBox Network Adapter 1 image
VirtualBox Network Adapter 1

Now go to Adapter 2, check Enable Network Adapter and choose Attached to ‘Host-only Adapter’.

VirtualBox Network Adapter 2 image
VirtualBox Network Adapter 2

OK to save the new setting and start the VM. You will now be back in the console window.

Ubuntu and Netplan

To see the network interfaces available type:

ip a

and you will get output like:

Ubuntu 20.04 ip a before static IP
Ubuntu 20.04 ip a before static IP

Netplan is the network management tool on Ubuntu these days, so forget the old /etc/network/interfaces.

cd /etc/netplan
ls -la

Depending on your Ubuntu version you will see a filename like 01-netcfg.yaml for my Ubuntu 20.04 server or 50-cloud-init.yaml for Ubuntu 18.04. Make a backup of that file in case something goes wrong and you need to roll back.

sudo cp 01-netcfg.yaml 01-netcfg.yaml.110420

Now edit the config file with your preferred text editor (vi, nano etc). In the image below I have added the other network interface as seen from ip a and have given it the static IP of

Netplan screenshot for static IP
Netplan cfg with static IP

sudo netplan apply

ip a

Ubuntu 20.04 ip a after static IP
Ubuntu 20.04 ip a after static IP

And that is it. I can now ssh / ftp into the guest server from the host on its static IP address and the guest can connect to the internet.

I’m A Certified Scrum Master

So after attending the Scrum Master training with AxisAgile, as part of the package you are nominated to Scrum Alliance and may then take the Certified ScrumMaster (CSM) exam.

Strike while the iron is hot, so once the login details were received I took the exam that night. Given the great course and my prior practical experience with plenty of reading, I was pretty confident. The fact the exam is online, untimed and multiple choice makes it less daunting than the last time I took an exam, many years ago.

Short story is yes I passed and am now a Certified ScrumMaster (CSM). Not quite a perfect score from the 35 questions, but close enough. The exam was much as I expected. In most questionsm of the 4 potentials 1 or 2 are generally obviously wrong, and often the correct answer id the nost correct of those remaining.

For those from a more traditional development background, watch out for phrases like ‘project manager’ which is not a defined role in Scrum. Understand who are the participants in scrum, like the development team, ScrumMaster and Product Owner. Get a good grasp on the various scrum gatherings like daily standup, planning and retrospectives. Finally the artifacts like the backlog (product and sprint) and the burn down chart.

Drupal and site performance improvements

Earlier in the year I was part of the team that put live a new site for my employer, moving from a predominately flat HTML site with a little PHP to one using Drupal 7. Here I will go through some of the issues that have been encountered around performance and the steps that I lead to improve site performance over time and as new features have been added.
Please note this is not my site so at times I don’t go into lots of detail around numbers.
Continue reading

XML uploads in WordPress

By default the WordPress media uploader does not permit the uploading of XML files, but this is easily modified.

add_filter('upload_mimes', 'custom_upload_xml');

function custom_upload_xml($mimes) {
    $mimes = array_merge($mimes, array('xml' => 'application/xml'));
    return $mimes;

Add this in your themes functions.php file or in a plugin. The function name [custom_upload_xml] can be changed, but just make it consistent. The same technique can be used to allow other file types to be uploaded.

Jigoshop v1.0 beware

Jigoshop recently released v1.0 of their WordPress e-commerce plugin. Beware the upgrade from the existing version is far from smooth. This was found out the hard way when a client updated their site. Tax calculations, featured products shortcode and products out of stock are just some of the errors encountered.

There are fixes in the support forum, but I would suggest waiting for v1.01 at a minimum.

Drupal Redirects Deletion

As part of a system data migration to Drupal 7, we have been using the Redirect module to handle redirects from old urls to the new.
This works fine, but as part of our fine tuning of the import process we clean out some of the content and then reimport. A node_delete does not remove the redirect so later when the redirect is added, the system returns a PDO Exception.
Continue reading

PHP News #7

PHP news for the fortnight ending August 27th, 2010.

  • Jolt is a new PHP5.3+ framework aimed at fast and efficient web application development.
  • CodeMash a multi development language technical conference on current practices, methodologies and technology trends. January 12-14, 2011, Sandusky, Ohio.
  • Embarcadero RAD Studio XE with support for PHP
  • Registration opens for ZendCon 2010. Early bird by 19 September.
  • Zend Framework 1.10.8 Released with bug fixes
  • CakePHP 1.2.8 released of bugfixes and optimisations
  • Phantm 1.05 released. Statically analyses PHP code to detect and report type mismatches

Bash hour date formatting issue

The little things that can trip you up. I had completed a bash script that took some log files, moved & renamed and then archived. Quite a common usage of the Linux shell. Worked yesterday, but this morning I was getting errors. Edited script file below

PREFIX=$(date +"%k%M")
# Edited

for FILE in 2* ; do
  mv $FILE temp/$PREFIX-$FILE;

# and more

Why would the mv work yesterday, but fail this morning, with errors about target not a directory. The answer is in the use of the date formatting %k. From the man page:

%k     hour ( 0..23)

The hour in 8:53 using %k does not return 8, its is 8 with a space in front of it. This only became obvious when I placed double quotes around the mv destination.
Simple fix, use %H, which will return two digits, in this case 08. Problem solved.

Using MySQL stored procedures

A lot of my past software development background has been around client/server in financial markets, with the main RDBMS use in Sybase, but also MS SQL Server and Oracle. In most cases stored procedures is the way to query and manipulate the database. There are a number of reasons for this including security, performance and centralised business logic out of the client.
Now in recent years I have made the move to web development in PHP, and in most cases using MySQL as the database server. From personal experience of others code, and available FOSS systems, it is extremely rare to see use of MySQL stored procedures behind web sites. They are there, have been for a number of years, and do work. So why is this so?
The first reason I could understand, was that they are a MySQL 5 feature, and most FOSS apps set their MySQL minimum requirements at version 4.x.
I now understand a 2nd and crucial reason, thanks to a post by Jay Pipes. MySQL stored procedures are not the same as Sybase or MS SQL. The shared compilation performance benefit is not there in MySQL 5.0/1 for non persistent or pooled connections. ie. most smaller to medium web sites. Their usage may actually be to the detriment of performance.
So stored procedures can have a use in MySQL, but mostly in limited use cases.

Nginx and PHP environment directive

With the Apache web server, I set a server wide directive of which environment the server is in, eg. production, test or dev, using the SetEnv directive. In a PHP script I can pick up this value, and set on all debugging in dev, or suppression in production. Having it set 1 place in Apache means I don’t need to hard code the environment in any PHP code, making movement of code between environments cleaner.
Recently I have begun to use Nginx as the web server with PHP fastcgi for a project, and was looking for a similar set up. The answer I have come up with is an additional entry in my fastcgi_params file. The exact name & location of this file may be different for you. Mine is located at /etc/nginx/fastcgi_params.

fastcgi_param  SYS_ENV             dev;

This way in my bootstrap script I can have the following code:

if ($_SERVER['SYS_ENV'] === 'production') {
} else { // Test and dev

There is probably another way to do this with Nginx, and I would be happy to hear it, as I try and improve my Nginx knowledge.

« Older posts

© 2020 Ernie Leseberg

Theme by Anders NorenUp ↑