Ubuntu cheatsheet

I’m using ubuntu more and more in recent times and am constantly googling commands to configure disks, mysql etc etc.  So I will document the commands I most commonly use here for my own reference.

Disk Management

 

Installing Applications

List Installed Packages – dpkg

1
2
3
4
ubuntu@ip-10-100-0-94:~$ dpkg --get-selections
accountsservice install
acpid install
adduser install

List Available Packages – get-cache

get-cache can be used to find a new package you may be looking for eg zabbix

1
2
3
4
ubuntu@ip-192-168-168-145:~$ apt-cache search zabbix
zabbix-agent - network monitoring solution - agent
zabbix-frontend-php - network monitoring solution - PHP front-end
...

Install a Package – get-apt

Install a package listed with get-cache

1
2
3
4
ubuntu@ip-192-168-168-145:~$ sudo apt-get install zabbix-server-mysql
Reading package lists... Done
Building dependency tree
...

 

Posted in Uncategorized | Tagged | Leave a comment

Installing Zabbix on AWS Ubuntu

Installing Zabbix on AWS Ubuntu was relatively easy thou the path here was far from it. Whilst looking for a suitable monitoring package for our small environment of less than 20 servers, I stubbled across Zabbix when looking for Nagios alternatives.

Not being ‘a real’ developer and specialising in infrastructure and solution architecture, I was rather sceptical in getting my hands dirty to gett this running under Linux. Whilst I have used linux over the years, my core skill are windows based.

So for the first 24 hours I spent spinning up Amazon virtual machines (SuSe, Amazon Linux, Ubuntu), installing packages with yast / yum / apt-get and generally getting stuck when it came to compiling the code with errors I did not know how to fix.

The I noticed Zabbix packages were already available on the Ubuntu image!!!!! So I spun up a clean machine and was up and running in about 30 mins.

  1. Start a new AWS Ubuntu image
  2. login as ubuntu
1
2
#>sudo apt-get update
#>sudo apt-get install zabbix-server-mysql

Its important that during this install you define the MySQL root password and a separate password for the new dbuser
eg
root: newpassword
mysql app: zabbix

1
#>sudo apt-get install zabbix-frontend-php

Again you need to define a password during this process I initially chose zabbix again.

Now visit your server at http://yourserver/zabbix
The logon should be Admin / zabbix

That was it :-)

Posted in Uncategorized | Tagged , | Leave a comment

Using Amazon EC2 tools on a MAC

Having used Amazon Web Services for around 2 years, I have seen the Web Console improve and grow. But on occasions or when scripting I have used the EC2 command line tools from a windows based PC. However my primary computer is my MacBook Pro, so I thought I would have a go at getting these to run from here. I was surprised at the relative ease of this.

Download and Install AWS tools

First I created a new hidden folder under my home folder called .ec2tools, then downloaded and extracted the ec2 command line tools to this folder as shown.

Open terminal and create a hidden folder called .ec2tools

cd ~/
mkdir .ec2tools
cd ~/ec2tools
open .

The last open command should open the hidden folder .ec2tools in Finder, next extract the amazon tools into this newly created folder. I used the standard gui to extract the zip file then moved the extracted files in to my newly created folder.

Robs-MacBook-Pro:.ec2tools rob$ ls ~/.ec2tools
bin
lib

Create and x509 and copy keys

To authenticate access, Amazon uses Public / Private keys.  To create a new set of keys log into you AWS account, select ‘Security Credentials’ from the top right menu and scroll down the page and select the x509 tab.  From here you can create a new x509 certificate which contains the public key and its associated private key.  Download both these files in the format shown below and copy them in to the new folder .ec2tools.

cert-*.pem
pk-*.pem

Update Bash Profile for EC2 Tools on a MAC

In order to make things easier to use, we can define a number of commonly used environment variables, such as the AWS region you normally use, the location of your public / private keys and the path to the tools themselves. This can be done in a simple text file called a bash_profile. This file sits in the root of the users directory and it is unique per user on the computer. By default this file does not exist on a MAC, the easiest way to create this, is from the command line using the ‘touch’ command in terminal as shown below.

cd ~/
touch .bash_profile
open -e .bash_profile

The open command will now allow you to use TextEdit to create a file similar to the one below.

1
2
3
4
5
6
export EC2_HOME=~/.ec2tools
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=`ls $EC2_HOME/pk-*.pem`
export EC2_CERT=`ls $EC2_HOME/cert-*.pem`
export EC2_URL=http://ec2.eu-west-1.amazonaws.com	
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home/

My file below defines the default EC2_URL (region) to be Ireland, as I mainly use ireland, I define this here but I can override this at run time. You can list all the available regions with there URL’s with the command ‘ec2-describe-regions’

a screen shot of the ec2-describe-regions aws command

ec2-describe-region - screenshot

With the bash profile saved you need to load it up by either rebooting or typing the following command

cd ~/
source .bash_profile

Testing EC2 command line tools

You now should be able to run ec2 commands directly from the command line.

List all Snapshots

ec2-describe-snapshots
using ec2-describe-snapshot to list all snapshots in region defined in .bash_profile

ec2-describe-snapshots - screenshot

Now by default the shell knows the location of the tools, can find any required keys and also knows my default region.

List Snapshots that match a string

You can now use other command line tools to aid you. For instance use grep to filter your results. Below I’m looking for a snapshot that contain ‘d93′ in its name.

ec2-describe-snapshots | grep -i d93
Posted in Uncategorized | Tagged , | Leave a comment

No TCPIP on mysql using Zend

Over the last few weeks I have been evaluating Zend Studio used in conjunction Zend Server CE on my Mac Book in order to improve debugging of my php / wordpress sites.

As I already had an installation of MySQL and used MySQL Workbench to administer it I was getting a little confused when using phpMyAdmin as provide by Zend Server CE and seeing a different set of databases.

I soon realised that I had 2 installations of MySQL, my original using TCPIP/3306 and a new Zend Version using Unix Sockets (tcpip disabled).  This was not really practical for me. So my solution was to remove my original installation and enable tcpip on my Zend version. THIS DESTROYED my original databases, which was not an issue for me as I had them backed up.

Once the original was uninstalled, I rebooted and verified the Zend version with phpMyAdmin and also from the command line with mysql.

Enabling TCPIP in MySQL Zend Edition

The configuration file for mySQL on my Mac was located at

/usr/local/zend/mysql/data/my.cnf

Unfortunately the data folder was locked as shown below

Robs-MacBook-Pro:mysql rob$ ls -l

total 0
drwxr-xr-x  49 root  wheel  1666 13 Dec 19:16 bin
drwxr-x—  13 zend  wheel   442 31 Dec 08:10 data
drwxr-x—   6 root  wheel   204  4 Sep 14:36 data.dist
drwxr-xr-x  23 root  wheel   782 13 Dec 19:16 lib
drwxr-xr-x   3 root  wheel   102 13 Dec 19:16 scripts
drwxr-xr-x  13 root  wheel   442 13 Dec 19:16 share
drwxr-xr-x   3 zend  wheel   102 31 Dec 08:10 tmp

So first I need to unlock the data folder using chmod

sudo chmod 777 data

Now I was able to enter the data folder and open my.cnf for editing. Personally I use textwrangler to edit as I like the ‘hidden’ option which allows my to navigate to folders usually hidden my MacOSx.

The only minor change here was to comment out the line below, thus enabling TCP/IP the same file already defined the default port of 3306, which was fine in my case.

#skip-networking

As a last step I switched the security back on for the data folder, as shown below then verified it with ls -l

sudo chmod 750 data

Again I restarted mySQL and now can happily connect to the MySQL databases using Workbench, phpMyAdmin and the command line.

Posted in Uncategorized | Tagged , | Leave a comment

MySQL not starting after Zend install

Whilst playing with Zend Server Community Edition trying to get mySQL to work I found myself at a point where mySQL would not start.

sudo zendctl.sh start-mysql
Starting MySQL
. ERROR! Manager of pid-file quit without updating file.

I had tried removing ZEND Server completely as documented on the Zend site. At best this is a bit vague.

  • Stop all Zend Server processes
  • Delete all Zend Server installed files
  • Remove the .app from /Applications
  • Remove Zend users

No matter what I did I always got the same error after re installing.  So after looking round the file structure I tried running a script called uninstall located in the Zend bin folder.  This asks a few questions but after completing the process and re installing, then all now seems to work :-)


Robs-MacBook-Pro:bin rob$ sudo /usr/local/zend/bin/uninstall.sh
Are you sure you wish to completely remove Zend Server? [yes|no]
yes
Stopping Zend Server 5.5.0 ..

httpd: Could not reliably determine the server's fully qualified domain name, using Robs-MacBook-Pro.local for ServerName
/usr/local/zend/bin/apachectl stop [OK]
Stopping Zend Server GUI [Lighttpd] [OK]
ERROR! MySQL manager or server PID file could not be found!
Stopping Java bridge [OK]

Zend Server stopped.
/usr/local/zend/apache2/htdocs and /usr/local/zend/mysql will be removed during this operation, if you wish to backup your PHP code and MySQL DBs,
please do so now and type "cont" to continue.
cont
Robs-MacBook-Pro:bin rob$

Posted in Uncategorized | Tagged , | Leave a comment

Zend Apache and Virtual Hosts

Over the last few months I have spent more time getting in to php development, this has been mainly for WordPress themes thou I also have written a few simple Web Services. Whilst the live versions of these are hosted externally I like to be able to develop on my laptop disconnected from the internet, eg whilst traveling on trains. This mean I have configured a number of sites using virtual hosts on my laptop.

Working with .Net developers who use Visual Studio my biggest frustration is issues I have is the pain in debugging PHP code, having to put excessieve manual code and logging which can be time consuming.  Thou I do include logging for general fault finding.  What I was missing was the ability to step through code in a similar fashion to Visual Studio.  After some research I discovered that Zend Server CE (free) in conjunction with Zend Studio (€299) appears to do this.

So with a 30 day trial of Zend Studio installed I decided to set up an environment on my laptop with the hope it would deliver, and I would then justify the €299 spend against the time I will save.

So this article discusses how I configured Apache under Zend to use the default port of 80 with host headers on my MacBook Pro running MacOSx 10.7 (Lion). The first thing to be aware of is that the Zend Server CE install, installs its own version of Apache under /usr/local/zend/apache2 so it is highly likely that you already have a default version under /private/etc/apache2.  In addition it installs its own light wieght web server for the administrive web site, so you can access the config via a browser even with Apache stopped.

Adding Zend to the Path

To make things easier and allow your system to find the Zend executables and scripts add the Zend Bin folder to the Path.

The Path file is located at /private/etc/paths

Now add the line /usr/local/zend/bin

Apache httpd.conf changes

Set the port number

The Apache config file httpd.conf for the Zend installation is installed at /usr/local/zend/apache2/conf/httpd.conf. I recommend you first make a back of this either from the command line using

sudo cp httpd.conf http.conf.org

or just using ‘Save As’ with a Gui based tool such as Textwrangler.

At around line 40, comment our the original line enabling port 10088 and add a line for port 80 as shown below

40
41
#Listen 10088
Listen 80

Change the Documents Folder

In this example my Sites folder is under my user name of rob. This should be changed to your username in the examples below.

105
106
#DocumentRoot "/usr/local/zend/apache2/htdocs"
DocumentRoot "/Users/rob/Sites"

Also change the documents folder as shown below, again I just comment out the original line at 134, the rest of the listing is just shown for completeness.

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#
# This should be changed to whatever you set DocumentRoot to.
#
#
 
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
 
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All
 
    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

Enabling the Virtual Host file

Finally uncomment the include statement for the virtual host file.

391
392
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Now exit and save the httpd.conf file

Adding Virtual Host Entries

Next we need to edit the file enabled in the previous section, backup then open the file /usr/local/zend/apache2/conf/extra/httpd-vhosts.conf

Set the port number

First change the port number that Apache will use in the virtual host file from 10088 to 80

391
392
#NameVirtualHost *:10088
NameVirtualHost *:80

Add your site entries

Now we need to disable or delete the 2 default site entries provided by Zend and add our own entries. The example below shows the original entries just commented out and my 3 new sites added to the end

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot "/usr/local/zend/apache2/docs/dummy-host.example.com"
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
#    ErrorLog "logs/dummy-host.example.com-error_log"
#    CustomLog "logs/dummy-host.example.com-access_log" common
#
 
#
#    ServerAdmin webmaster@dummy-host2.example.com
#    DocumentRoot "/usr/local/zend/apache2/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "logs/dummy-host2.example.com-error_log"
#    CustomLog "logs/dummy-host2.example.com-access_log" common
#
 
    ServerAdmin rob.langley@me.com
    DocumentRoot "/Users/rob/Sites/intranet"
    ServerName localhost
    ServerAlias intranet
    ErrorLog "/Users/rob/Sites/logs/intranet_error_log"
    CustomLog "/Users/rob/Sites/logs/intranet-access_log" commonvhost
 
    ServerAdmin rob.langley@me.com
    DocumentRoot "/Users/rob/Sites/helloWorld"
    ServerName localhost
    ServerAlias hello
    ErrorLog "/Users/rob/Sites/logs/hello_error_log"
    CustomLog "/Users/rob/Sites/logs/hello-access_log" commonvhost
 
    ServerAdmin rob.langley@me.com
    DocumentRoot "/Users/rob/Sites/florida-paradise-villas (Wordpress)"
    ServerName localhost
    ServerAlias fpv
    ErrorLog "/Users/rob/Sites/logs/fpv_error_log"
    CustomLog "/Users/rob/Sites/logs/fpv-access_log" common

You will see in my config above I use server aliases such as fpv and hello so I can access my local sites with http://fpv and http://hello. In order for these addresses to resolve to localhost you need to add them to your host file located at /private/etc/hosts

12
13
14
15
16
#Custom Settings - R Langley
# web sites
127.0.0.1	intranet
127.0.0.1	fpv
127.0.0.1	hello

Auto Starting Zend Apache

The final step is ensure the Zend Version of Apache starts as opposed to the default Mac version. This is to prevent confusion and also a conflict as they are now both configured to use port 80.

I achieved this by effectively repointing the default apachectl to the Zend version of Apache so when the system start Apache it starts Zend version as opposed to the default.

First stop the current version of apache if its still running

apachectl stop

Next you need to move the current version to a safe place in case you need it in the future. The file is located at /usr/sbin/apachectl and can be moved with

sudo mv /usr/sbin/apachectl /Users/rob/SafePlace

Where ‘rob’ above is my personal user folder and should be changed to yours or an alternate location.

Now with the original version of the file removed we can create a link too Zend

cd /usr/sbin
sudo ln -s /usr/local/zend/apache2/bin/apachectl ./

Now you should be able to start the new version of Apache with

apachectl start

Update for Mountain Lion

After getting a new laptop with Mountain Lion, I followed these instructions to find I could not get Apache to start, apachectl reports success but nothing is served. I noted an error in the error.log and a quick google took me to  http://www.andrew-kirkpatrick.com/2012/07/apache-not-starting-in-zend-server-with-mac-os-x-10-8-mountain-lion-upgrade/

sudo cp /usr/lib/libxslt.1.dylib /usr/local/zend/lib/.

All now working again :-)

Posted in Uncategorized | Tagged , , | Leave a comment

Windows 7 not seeing allocated diskspace

I have a virtualised version of Windows 7 Ultimate running on my Macbook Pro under VMware Fusion 4. The C drive having 50Gb was becoming quite full so I shut down the VM and allocated an additional 20Gb. After restarting I went in to disk manager and disk tools and saw the new partition was now 70Gb and fully extended, however if I right clicked the actual C drive it reported only 50Gb. Looking in the actual VM package from my Mac I could see the appropriate number of 2Gb vmdk files totalling 70Gb. This seemed very strange so I tried updating vmware tools, running chkdsk, rebooting all without success. In the meantime I allocated another 15Gb but still the actual C drive reported 50Gb in explorer but now disk manager report 85Gb.

I discovered that the ‘extend filesystem’ command in diskpart fixes this.


>diskpart

DISKPART> list disk

Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 85 GB 0 B

DISKPART> select disk 1

The disk you specified is not valid.

There is no disk selected.

DISKPART> list disk

Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 85 GB 0 B

DISKPART> select disk 0

Disk 0 is now the selected disk.

DISKPART> list partition

Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Primary 84 GB 1024 KB

DISKPART> select partition 1

Partition 1 is now the selected partition.

DISKPART> list volume

Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 D DVD-ROM 0 B No Media
* Volume 1 C NTFS Partition 84 GB Healthy System

DISKPART> select volume 1

Volume 1 is the selected volume.

DISKPART> extend filesystem
DiskPart successfully extended the file system on the volume.

DISKPART>

Posted in Uncategorized | Tagged , | Leave a comment

Setting up Apache after Lion 10.7 Install

I have just bought a new 256Gb SSD for my Mac Book Pro to upgrade my 128Gb SSD which I installed some months ago to have a test of SSD and performance (its awesome). I took this opportunity to perform a CLEAN install of OSx Lion 10.7 leaving my original SSD in a USB caddie with 10.6 (Snow Leopard).

On my old disk I ran several development sites using Apache / PHP / MySQL using a combination of the hosts file and virtual hosts in Apache.

This blog documents the process I went through in migrating my sites from a Snow Leopard (10.6) to a new clean installation of Lion (10.7).

Tasks on Lion 10.7 Installation

First I enabled ‘Web Sharing’ under system preferences, and tested I could access http://localhost from a browser.

Next I copied my original files under /volumes/ssd/users/rob/sites to the new disk at /volumes/ssd240/users/rob/sites where rob is my user folder.

Then I backed up the default host file located in /private/etc/ and added my own aliases such as those shown below.

127.0.0.1 bizziebee
127.0.0.1 intranet

Lion seems to have a higher level of file security on file system so I had to change this on a few of my files in order to be able to modify the key configuration files in apache.  So using terminal I modified the following.


cd /private/etc/apache2
sudo chmod u+w httpd.conf

cd /private/etc/apache2/extra
chmod u+w httpd-vhosts.conf

Using textwrangler which allows you to view hidden files, I opened my original httpd-vhosts.conf file and merged it into the new version. Note as my new disk had a new Volume label I had to rename these from SSD to SSD240


<VirtualHost *:80>
ServerAdmin rob.langley@me.com
DocumentRoot "/Volumes/SSD240/Users/Rob/Sites/intranet"
ServerName localhost
ServerAlias intranet
ErrorLog "/Volumes/SSD240/Users/Rob/Sites/logs/intranet_error_log"
CustomLog "/Volumes/SSD240/Users/Rob/Sites/logs/intranet-access_log" common
</VirtualHost>

Next we need to modify the default httpd.conf file.

  1. Enable PHP support by deleting the leading # around line 111
  2. LoadModule php5_module libexec/apache2/libphp5.so

  3. Enable Virtual hosts by deleting the leading # around line 626
  4. Include /private/etc/apache2/extra/httpd-vhosts.conf

Now lets restart apache and test our settings so far. From terminal type.
sudo httpd -k restart

MySQL Migration

First I installed a new copy of MySQL Community followed by MySQL Workbench to administrate it.  Both these installations were simple and straight forward but my machine did require a reboot in order to start mysql.

Copying Configuration from MySQL workbench

Obviously my new installation of MySQL workbench did not have any of the original connections or server instances.  So rather than have to remember them all I copied two xml files from my orignal disk.  The xml files were located as follows.

/Volumes/SSD/Users/Rob/Library/Application Support/MySQL/Workbench/connections.xml
/Volumes/SSD/Users/Rob/Library/Application Support/MySQL/Workbench/server_instances.xml

Copying MySQL xml filesNow start MySQL workbench to find all your saved connections :-)

Your local databases can now be exported from your original installation by booting into your original disk and creating and export (dump) and saving the file in a common location.  I actually created one dump for all my schemas and this seemed to work.  Then start you new OS (Lion) and import these files  in to your new MySQL installation.

MySQL Sockets

It appears that the location of mysql.sock has moved in Lion from var/mysql/mysql.sock to tmp/mysql.sock  This is defined in /private/etc/php.ini.  Unfortunately this file also appear to have been renamed to php.ini.default.  So….

  • Stop the web server ‘sudo apachectl stop’
  • copy php.ini.default to php.ini
  • Edit php.ini and Search and Replace ‘var/mysql/mysql.sock’ to ‘tmp/mysql.sock’
  • Restart the web server ’sudo apachectl start’

Thanks to Brian Chans blog for the info on mysql.sock

Thats it, I now have my sites running under Lion.  I hope this may be of some help to some people.

Posted in Uncategorized | Tagged , , , | Leave a comment

PHP Webservice and MySQL

In this post I will document some recent research I did in writing a basic PHP SOAP Web Service to return a set of data from a MySQL database.  Having recently purchased an iPad I wanted to write an application for personal use which will query an existing MySQL database.  Therefore I researched and developed this code standlone on my Mac Book Pro running the default install of Apache and a download of MySQL.

The first thing I did is wrote a basic Stored Routine using MySQL Workbench to return a set of data.

CREATE DEFINER=`root`@`localhost` PROCEDURE `sr_RetrieveBasicBookingDetailsList`(IN days int)
BEGIN
SELECT b.bookingRef, b.customerId, CONCAT_WS(' ',c.lastname, c.firstname) as customerFullName, b.state, b.startDate, b.endDate, b.bookingDate, b.totalCost, 0 as Owing
FROM bookings as b
INNER JOIN client c on b.customerId = c.customerId
WHERE startDate &gt; DATE_SUB(now(), INTERVAL days DAY)
ORDER BY startDate ASC;
END

The inner workings of the above stored routine does not really matter except to say that you can pass it a single integer value which represents the number of days.  The Stored Routine then returns a set of data based on this value.  With the Stored Routine written and tested it was time to move on to writing my the PHP Web Service.  In order to simplify development I chose to use the library nusoap which is available at SorceForge

Line 1 – 3: Define library location for NUSoap and also config location for global variable such as Database credentials.

Line 4 -9: Create SOAP object and define namespace.

Line 10-30: Create an complex dataType called bookingBasicDetail to each booking record returned from the database

Line 33-45: Create an array to be returned by the web service, is an array of bookingBasicDetails so will contain the complete dataset returned fromt the database.

Line 48-58: Now define the actual web service.

Line 59: Define function to be called by webservice

Line 60-67: Open a database connection and return a soap fault if there is an error such as bad password or database not found.

Line 69-73: Call Stored Routine passing in the single integer value ‘days’. Return a Soap Fault if anything errors.

Line 78-96: Iterate through each rowset returned by stored routine, mapping the columns (fields) to variables within the array. For example startDate is the 5th field in the rowset returned.

Line 98-101: Close database and return results from function to web service.

Line 104 – 105: Set up HTTP for web service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
	require_once('../config.php');
    require_once('../lib/nusoap.php');
    // Create the server instance
    $server = new soap_server();
 
    // Initialize WSDL support
    $server->configureWSDL('villaQuoter.bookings', 'urn:villaQuoter.bookings');
 
 
	//Define a STRUCT for 'simple quote details' conatins a minimum set of fields including:
	//	state, bookingRef, customerId, startDate, endDate, bookingDate, Customer Full Name, Total Cost, Amount Owing    	
    $server->wsdl->addComplexType(
    	'basicBookingDetails',		//Name of Type
    	'complexType',				//Type Class (Complex)
    	'struct',					//php Type (Struct)
    	'all',						//Compisitor??
    	'',							//Restriction Base
    	array(
			'state' => array('name' => 'state', 'type' => 'xsd:int'),
    		'bookingRef' => array('name' => 'bookingRef', 'type' => 'xsd:string'),
    		'customerId' => array('name' => 'customerId', 'type' => 'xsd:string'),
    		'customerFullName' => array('name' => 'customerFullName', 'type' => 'xsd:string'),
    		'startDate' => array('name' => 'startDate', 'type' => 'xsd:string'),
    		'endDate' => array('name' => 'endDate', 'type' => 'xsd:string'),
    		'bookingDate' => array('name' => 'bookingDate', 'type' => 'xsd:string'),
    		'totalCost' => array('name' => 'totalCost', 'type' => 'xsd:string'),
    		'amountOwing' => array('name' => 'amountOwing', 'type' => 'xsd:string')
    	)		
    );
 
 
	//Create an ARRAY of data type BasicBookingDetails (this will be returned by the Web Service)
    $server->wsdl->addComplexType(
    	'arrBasicBookingDetails',		//Name of Array
    	'complexType',					//Type Class (Complex)
    	'array',						//Php Type (Array)
    	'',								//Compistor??
    	'SOAP-ENC:Array',				//Restriction Base
    	array(),
    	array(
    		array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:basicBookingDetails[]') //link back to complexType via namespace
    		),
    	'tns:basicBookingDetails'
    );
 
 
    //Define Web Service
    $server->register('ws_retrieveBasicBookingDetailsList',
    	array('history' => 'xsd:int'),											//Input Parameters (Integer: Days)
    	array('return' => 'tns:arrBasicBookingDetails'),						//Output Paraemters, an Array of BasicBookingDetails
    		'urn:villaQuoter.bookings',											//Namespace
	        'urn:villaQuoter.bookings#ws_retrieveBasicBookingDetailsList',   	//soapaction
    		'document',																//style  rpc or document
    		'literal',															//use encoded or literal
    		'This method returns basic details for bookings / quotes, define number of days of history to return. 0 = future only.'	//documentation	
    	);
 
	function ws_retrieveBasicBookingDetailsList($days)
	{// Called by Web Service of Same Name.
    	$link=mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    	if(mysqli_connect_errno())
    	{	
    		//Raise SOAP Fault if Database Connection fails
			return new soap_fault('SQL-ERROR: '.mysqli_connect_error());
    	}
 
 
		$result = $link->query("call sr_RetrieveBasicBookingDetailsList(".$days.")");
		if(mysqli_errno($link))
		{	
    		//Raise SOAP Fault if Stored Routine Call Fails
			return new soap_fault('SQL-ERROR: '.mysqli_error($link));
    	}
 
 
 
		//Create bookings array (holds multiple bookings of STRUCT Type basicBookingDetails	
		$bookings = array();
 
 
		while($row = mysqli_fetch_row($result))
		{// Loop throu each booking and Load into 'bookings' array
			$booking = array(
	 			bookingRef => $row[0],
	 			customerId => $row[1],
	 			customerFullName => $row[2],
	 			state => $row[3],
	 			startDate => $row[4],
	 			endDate => $row[5],
	 			bookingDate => $row[6],
	 			totalCost => $row[7],		
	 			amountOwing => $row[8]
			);
	  		$bookings[] = $booking;
		}
		//Close Database Connection (results now in $bookings array)
		mysqli_close($link);
 
	return $bookings;
	}
 
 
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
    $server->service($HTTP_RAW_POST_DATA);
?>

Posted in Uncategorized | Tagged , , , , , | Leave a comment

Useful commands on a MAC

Below are a few commands I need to use on an adhoc basis, they are blogged here mainly for my own personal reference, but my help others

To restart apache from the command line type

sudo httpd -restart

To view network settings including IP address, MAC address, DNS etc from the command line (terminal) type

ifconfig

Changing MAC Address

Occasionally I have the need to temporally change my MAC address.  The following command achieves this.  However in order for this to be successful the order of events are important.  The steps assume you are using WiFi as opposed to a cabled ethernet, thou I suspect the process is very similar.

  • Turn you WiFi off
  • Disable ‘Auto Join’
  • Re-enable WiFi.
  • Once the appropriate WiFi connection is detected type the following before before joining the network. (choose the required mac address)

sudo ifconfig en1 ether 1a:12:61:ff:aa:91

  • Type the following to verify the new MAC address.

ifconfig

  • Join the appropriate Network

Re-index Spotlight

On occasion my spotlight index appear to have become corrupted and results are no longer returned.

Turn indexing on, on the root folder.

sudo mdutil -i on /

Rebuild index

sudo mdutil -E /

Showing Hidden Files in Finder

On occasion you need to view hidden files, I recently needed this when search for filezilla.xml in order to copy my config between machines.

To view hidden files

defaults write com.apple.Finder AppleShowAllFiles TRUE

killall Finder

To re-hide hidden files

defaults write com.apple.Finder AppleShowAllFiles FALSE

killall Finder

 

Posted in Uncategorized | Tagged , | Leave a comment