Monday, 26 March 2012

Moodle 2 - Configuring the Linux Box

In this series of blogs I will be detailing my installation, setup and configuration of one of our new Moodle 2 enviroments. I will cover:
  • Configuring the Box
    • On Red Hat Linux
    • PHP configuration
    • Mysql Configuration
  • Installng Moodle 2
  • The first simple setup steps
  • Creating some users and courses
  • Some advanced setting we will use
  • Google Mail Integration
  • LDAP integration
  • Single Sign on Integration (NTLM)
  • Mods and Blocks we want.
Configuring the Box.
This first post is about configuring the box and for this I am jumping into the point where RED Hat has just been installed and it has a GUI installed (though I will use the terminal). 

http://docs.moodle.org/22/en/Installing_Moodle - Are the requirements for Moodle 2.2 and here it tells us that the version of PHP we want is 5.3.2. In a terminal window run:

$ php-v  

I had version 5.3.3 installed and so didnt need to upgrade. 

The next thing we should do is create a phpinfo file that we can use to check our php configurations. This will run on the webserver on our box so we need to check the webserver status. In a terminal window run:

$ service httpd status  

Assuming that httpd (the web server service) is stopped we need to start it: Run (as root):
$ service httpd start   
If a warning about failing to determine the servers fully qualified domain name, then edit the /etc/httpd/conf/httpd.conf file and where it wants to specify the 'serverName' then uncomment this and put in the ipaddress (or domain name) of what the new Moodle will be. 

PHP

Next create a phpInfo.php file inside the webserver directory (It will tell you where this directory is in the httpd.conf file above), but, it is usually /var/www/html. Inside there create a new file called phpInfo.php and the contents of the file want to be:


<?php
phpinfo();
?>

Then open up a browser and type: http://localhost/phpInfo.php and hopefully the extensions and php information will be displayed. It may not show the mysql information if the mysql service hasnt been started yet:

As root, in a terminal type:


$ service mysqld status
$ service mysqld start 

In the php information output from above take not of the location of your php.ini file (mine was /etc/php.ini). This is where we will be checking/changing some settings. 
At http://docs.moodle.org/22/en/PHP there is a list of the extensions that moodle 2 needs. 
In my out of the box php configuration:
(for the following yum commands you may need to do a yum-update first)


iconv -> Was Enabled (Checked by looking at the phpinfo output)
mbstring -> ran '$ yum install php-mbstring' and then added 'extension=mbstring.so' to the php.ini file. Restart httpd.

(As a side not the above command complained about package can not be found. I used '$ yum repolist all' to view all available repos. I then added server-optional repository using '$yum-config-manager --enable rhel-6-server-optional-rpms'). See https://access.redhat.com/knowledge/articles/58637).

curl -> was enabled.
openssl -> was enabled.
tokenizer->was enabled
xmlrpc -> do '$yum search xmlrpc' you should see a package called php-xmlrpc.i686. Install it using '$yum install php-xmlrpc.i686'. Add 'extension=xmlrpc.so' to the php ini file and restart the httpd service. (if you look in /etc/php.d you will see the .ini files we are installing and thus the name to have in the extensions section of the php.ini)
soap -> search for soap as above. '$yum install php-soap.i686'. Then in php.ini add extensions=soap.so
ctype -> was enabled
zip -> was enabled
gd -> was enabled
simplexml -> was enabled
spl -> was enabled
pcre -> was enabled.
dom -> was enabled.
xml ->was enabled.
intl -> '$yum install php-intl.i686' add 'extensions=intl.so' and restart the service.
json -> was enabled.

For our installation I am using a mysql database. This means that I need mysql support in PHP.

I search for mysql, installed the php-mysql.i686 rpm, added extension=mysql.so and restarted the httpd service.


Our installation will later require LDAP integration so at somepoint I need to add these extensions in. However I will leave that to when I set LDAP up.    

MYSQL

So, I now have php set up. Its now time to configure and set the mysql up.

First thing is to change the root password of mysql.

'$ mysqladmin -u root password <Your_new_password>'. 
Now we are going to set up a Moodle user for our database and create the moodle database itself.

$mysql -p 
This will ask for the password set above and then will get us into mysql.

Next we are going to create a database called moodle and a new moodle user. Within the mysql account. (so you are entering into mysql>). Type:

CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; 


GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER on moodle.* TO newusername@localhost IDENTIFIED BY 'yournewpassword'; 

Where above the database is whatever you want to call the database and 'newusername' is a new user you are creating for the mysql database.

Performance and Memory

So far I have not configure the server for performance or memory optimisation. For now I am leaving these as default but I will return to this at a later date.

Conclusion

Now our  system should be set up so we can go ahead and install a new installation of Moodle 2. This is what I will be doing in step 2.


Tuesday, 20 March 2012

Using SharePoint HTML Forms to filter a list

In a previous post I set up an external list onto my SharePoint site. I now want to be able to filter the results based on a users input on a form. There are two ways of doing this:
  1. Simple SharePoint HTML forms. 
  2. InfoPath forms published to SharePoint.
In this post I will be concentrating on method 1. In a future post I will do post 2 (I hope).

Ok, so I have a list (external in my case) and this is on a page.
  1. Turn editing on -> on the same page as the external list.
  2. Add a new web part: Under Categories select Forms. And then select 'HTML Form Web Part'. 
  3. When the web part has been added click on the usual edit drop down arrow to the top right hand corner of the web part
  4. Select 'Connections' -> 'Provide Form Values To' and then select the List/Web part that we are filtering
  5. Click on 'Configure Connection'
  6. Select the field from the 'Consumer Field Name' that matches the field you want to filter the data on.
  7. Press finish and it will now work as a filter. 
Notes:
The filter is only filtering on the list below, not the actual query that is being sent to the data source. In my situation the data source is an external SQL server. This, by default, gets back all records from a specific table and limited to 1999 (the default max limit). The form added above filter on these 1999 returned records, not the original dataset from the database.

I have just left the standard text field on the form. You can add other options to the form however you can only connect one field to a list. You can connect multiple lists using multiple fields.

Monday, 19 March 2012

SharePoint 2010 SQL Server External Content Types

I needed to connect from SharePoint 2010 to a SQL server using a static username and password and have this data presented in a list on SharePoint. In this post I outline what I did. The general steps are:
  1. Create a Secure Service Account that can be used to access the database using one account regardless of who is on SharePoint. This is done using the Central Administration Console.
  2. Create an External Content Type using SharePoint Designer that connects to the SQL Server.
  3. Create a List in SharePoint (or SharePoint Designer) that looks over this External Content Type.
Creating a Secure Service Account:
This is the account that will be used to connect from SharePoint to SQL server without the need to have an account on SQL Server for every user. 
  • The first thing to do is to create an AD (Active Directory) user that will be used to access the database. Give it a username and a password. E.g. SPSQLDB
  • Create a security group in AD that will house the accounts that will be able to gain access to our SQL Server. Make sure the account from step one (SPSQLDB) is a member of this group.
  • Open up the SharePoint 2010 Central Administration and click on 'Application Management' down the left hand side. 
  • Click on 'Manage Service Applications' under 'Service Applications'.
  • Click on the 'Secure Store Service' to bring its interface up.
  • Click 'New' 

  •  In the fields of 'Target Application ID', 'Display Name' and so on, put in the details that you want. At this stage they do not have to match the accounts created above. 
  • I selected 'Group' in the Target Application Type as this will let me access one set of login details from an entire AD group. Then 'Next'.
  • I left the field names as default and made sure that the field type was set to Windows User Name and Windows Password. Then 'Next'.
  • In the 'Target Application Administrators' I add in the accounts that I will allow to edit the Target Application settings. (e.g. all of the users who have access to Central Admin and who I don't mind playing around with this)
  • In the Members field I add in all accounts/groups that I want to have access to run the link between SharePoint and SQl server. In my example I want only a certain group of users to access it. (If you don't get this right then when the web part is added an error will occur with the web part itself and the users won't be able to see the data.)
  • Click OK and we have created our SSC
So, now we have an SSC account, but, we need to add in the user that we will be access the SQL Server with.
  • Click on the new SSC that we have created. 
  • Click on 'Set Credentials'.
  • In this dialogue box that appears we want to put the UserName and Password from our user we created all the way at the beginning of this step SPSQLDB. Make sure that the domain is added in the username. E.g. domain\username
Creating an External Content Type
I will use SharePoint Designer to create an External Content Type that will connect to the SQL Server.
  • Open up SharePoint Designer at the root level and click on 'External Content Types' on the left.
  • Click on 'Add Connection' and select 'Sql Server' as the data source.
  • In the window above put in the database server, name and then click 'Connect with Impersonated Windows Identity' and put in the SSA ID from the one we just created. Again adding in the domain when asked for username and password.
  • Note: You will probably need to play with permissions and accounts access on the SQL Server for this account to gain access. 
  • If successful you will end up with a list of database tables. 
  • Pick a table you want the List or content to be over and right click on it:

The Database Table Options
The operations are defined as:
  • New Read Item Operation: This will return a single item (database row) from the database based on some parameter (e.g. ID).
  • New Read List Operation: This will return the entire table as a list.
  • New Create Operation: This will allow for new rows to be created in the database. 
  • New Update Operation: This will allow for a row to be updated in the database. 
  • New Delete Operation: This will allow for a row to be deleted from the database.
  • New Association: An Association is the ability to link two content types togethor. Think of it as linking tables in an SQL JOIN query.
I am going to be creating a 'Read Item Operation' and a 'Read List Operation'. I  do not want to change anything on the database itself.

New Read Item Operation
  • Right click on the table name and click 'New Read Item Operation'
  • In the dialogue box/wizard that appears accept the default names or change them and click next.
  • In the Input Parameters Configuration select the identifier that we will be using to query the database. A default value for the identifier can be selected and a filter for the data can be set. (This filter will filter the results based on other parameters).
  • I for example am choosing a 'StudentID' field as my identifier.

  •    In the next screen we need to map the return parameters. I left them as defaults. However I did get some warnings:
  • This is to do with the items being both required and read-only. I unselected the 'required' field. We will never be updating from this list and so we know that the element in question will come back from the database if it is there. 
  • Click on Finish.
New Read List Operation
  • Edit the display names as desired. 
  • Add any filters that you want (Sorry, I was going to walk through the filters and how to, but I realised this blog post would get huge.). 
    • At least add a limit:
      • Click 'Add Filter Parameter'
      • Click Filter: And add the filter type of limit
      • Choose the data source element this is based over. (Primary Key is probably better)
      • Add in a Default Value.
  • Add the return parameters.
    • Select some columns to add in as the picker columns.
NOTE: If you do not add in a limit that is below 2000 then there is a good chance you will get an error when you add the web part that displays an external list. This is because by default SharePoint is set to 2000 limit on external results. 
Once you are happy with everything click 'Save'.

Using the External Content Type
From within the SharePoint Central Administration portal click on 'Manage Service Applications'. Then go to 'BDC Service Applications'. Here you will find the service that we created.

We want to let certain (or all) people have access to the service and therefore access to the link between our SharePoint and the SQL server. This will let them view data returned from the SQL server.

I am going to let all_staff have execute permissions and then a specific group of people have set permissions and edit rights to the link.

Back in SharePoint add an External List and select the External List we created in the options:
  • Site Actions
  • More Options
  • Filter By: List
  • External List
  • Add in a Name
  • Select the External List we created. 
 Fingers crossed that it works.

If it didn't work:
Ok, so hopefully it has worked. If it hasn't worked then hopefully you will have gotten some error code (correlation ID). Below are some links to do with checking the logs and what could possibly have gone wrong:
  • Finding the error logs: http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/d42b11cb-54c1-4c45-bfba-acf3fd486717
  • About limit throttling: http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/8a861878-180f-4126-b982-574ea514676c 
  • Access denied error: http://social.msdn.microsoft.com/Forums/en-IE/sharepoint2010general/thread/7e597ef9-0f8f-4df8-a99c-1c66c536d717

Sunday, 11 March 2012

Creating a Theme for SharePoint 2010

Our College originally had a staff intranet that was written in an outdated ColdFusion. Its content was static and its presentation was not the greatest. Our department decided to invest in SharePoint 2010 and as its base use, our Staff Intranet. One of my first tasks in my role was to design and create a theme for 2010.

I decided to write this post about what I chose to change and how. Now, I'm not sure I am really a web designer, I know how to do what needs doing, but I am probably not the greatest on designs. This series of posts contains the final image and along with it some of the design iterations I went through with the help of some of my colleagues. The final theme isn't exactly award winning, and doesn't change a great deal of the out of the box master files, but its a start. 

Changing the Master Page. 
The master page is the file that SharePoint 2010 uses as its basis to configure and set up all the other pages in the site collection. Creating a new master page (or altering a pre-existing one) will allow you to specify some custom CSS, or, better yet, some external css files. 

At the root of the site collection click on 'Site Actions' -> 'Site settings'. Under 'Look and Feel' click on 'Master Page'. This is where we will later be specifying our 'system master page' which will allow us to set a file that will help configure the entire site collection. We can also specify our 'site master page' which lets us specify a file to help configure this site. 


Back at the page above ('Site Actions' -> 'Site settings') under Galleries click on 'Master Pages and Page Layouts'. Here we find all of our master pages. Probably not a lot at this stage.

Ok, so we want a new master page:

'Site Actions' -> 'Edit in SharePoint Designer'. This will open SharePoint Designer and from here we can gain access to 'Master Pages'. In this page right click on 'default.master' (or one that you want to base your master page from) and then click copy. Then paste it back into the same folder. Rename it, check it out, check it in and then publish it. 

Back under 'Master Page' in 'Look and Feel' now set either a site or site collection master page to be this new one you have created. 

Linking to external style sheet in the Master Page 
Ok, so we need to have somewhere to store our CSS files. We store ours in 'Style Library' (Site Actions -> View all Site Content -> Style Library) where we have created a new folder. In here we have uploaded/edited an external css file. 

Click on the Master Page we have just created and edit it. We need to put a link in here pointing to our CSS files. 

As the last element of the 'head' section of the master page add the following line:


<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/[FolderName]/[cssFile].css %>" After="corev4.css" runat="server"/>


Where the FolderName is the folder we created in Style Library and cssFile is the name of the css file we uploaded/created. (Can be created in SharePoint Designer).

In a future post I will explain/show some of the things I did, such as:

  • Rounded Tabs
  • Rounded Left Menu
  • Headers
  • Flyout menus. 

How we have increased Moodle use

So, our VLE is Moodle 1.9 and, on top of its use as our e-learning content provider, we use it as our platform to get information across to the students. Some of this information is critical while others are merely vocational.

To help ensure students gain access to Moodle and use it:

  • Moodle is accessible from Home
  • Moodle is the default home page for Internet Explorer
  • Moodle is the only intranet/vle that we use across multiple different sites. 
  • Moodle makes use of LDAP authentication so students have to remember only one password when using Moodle and the computers at college. 
  • We use Single Sign on in the form of NTLM. This means that as soon as they open Internet Explorer they will be signed into Moodle. (As a side note Internet Explorer is our default browser and only browser in some cases)
  • The students emails are done through Google Emails and there is a block on the front page of Moodle where they can see their unread messages. 
  • We allow students to chat on Moodle. This is the only social media they have access to in the entire college. It is monitored by sampling from staff, scripts looking for inappropriate language and spamming and we have bullying notification systems. We can block individual students from chat and we can block entire course codes worth of students, usually for an entire year. 
  • We have one central theme that is the same across all of Moodle. 
  • We make use of the UCL ILP block/mod and we have heavily modified it to show:
    • Attendance and Punctuality
    • BKSB diagnostic testing
    • Prior Learning and Target Grades
    • Grade Tracking with Criteria Tracking and predicted grade calculations
    • Timetabling
    • Reports
  • We track our Qualifications on Moodle so students can see when they have met their criteria, units and qualifications. 
  • Library information, student services and other core services are all done through Moodle. 
  • Internal Inspections of departments take into account Moodle use in awarding grades.
  • Downloading of 3rd party blocks/mods. Such as:
    • Lightbox gallery
On top of those above we are currently working with the teaching staff to aid them in getting the most out of their Moodle courses:
  • Creating Paper and Video Moodle user guides that:
    • Clearly describe the use and procedures in using the different parts of Moodle. 
    • Explain best practices in the use of each part of Moodle. 
    • Show/create exemplar uses of each part of Moodle. 
    • Show/create exemplar courses.
  • We encourage staff to research 3rd party blocks.
I hope to update this blog post as my team and I work on this area and I can detail each of the installations/mods we have gone through. 


Moodle 1.9 Meta Course Structure

Meta Courses aid in:

  • Efficient sharing of information
  • Efficient enrolment
  • Easier to handle courses. 

At our college we use Meta Courses to structure our courses and how the students see the correct material. We have 5208 courses in Moodle and of these 608 are meta courses. We use meta courses to structure the same content that needs to be seen by many different groups and courses without having to upload it multiple times. Our college covers a wide range of qualifications such as Alevels, BTEC's, City and Guilds and Cache and these are in areas such as Sport, Business, Engineering, Art and Animal Sciences. Students on the different courses often need to see similar content;
  • Shared Units
  • Shared Assignments
  • Shared Information. 
  • College Information. 
  • Different years for the same course.
For our moodle instalation we created two very large courses (we call these our child courses). These are called 'all_stud' and 'all_staff'. These, as you can guess, have all of the students on one and all of the staff on another. The users of each group can be distinguished from each other by their usernames. Students have a number and staff have their initial and surname. With this in mind I created an automatic script that searched for anyone who has a number in their username and add it to all_student (if they were not already there). (as a side note, my enrolment script also auto adds them to the correct child course ('all_stud' or 'all_staff')). A similar script adds to 'all_stud' and 'front_page_teacher'.

Our Child Courses
All of our child courses are created automatically based on cron information taken from our MIS database system. These have a course code such as 'F108' or 'X1056' along with the year the course started. For example:
              'X101-11' or 'X101-12'
There full name would be something like:
              'X101-11 Alevel Maths' or 'TT897-12 BTEC Extended Diploma Animation'.

Our child courses have the students enrolled onto them, but have no content and have no teachers enrolled on them. The child courses are hidden and in hidden separate categories. For example all Alevel courses would be in an Alevel categories called 'ALVL' that is hidden. The students don't know that they are on these course codes.

A student will only ever be on a course code/child course once, but they may be on more than one course code/child course.

The child courses are then added to specific meta courses so the students can see the correct material.

Our Meta Courses
Our Meta Courses have English names, such as 'BTEC Diploma in Animal Care' and are in non hidden categories. For example Alevel Maths meta course would be in a category called 'Sixth Form Centre/Alevel'.

Our Meta Courses have no direct student enrolments, have content and have teachers directly added to them. These meta courses are what students see and it is these that the teachers add content to.

Automatically connecting the Child to Meta
During the automatic enrolment script I created, Moodle gets given a csv with new courses. The short name of the course is the course code (X101-12). The csv script looks for all courses of the previous year (X101-11) and automatically adds the new course as child courses to the meta courses of the previous year course.

Our Core meta Courses
All staff and all students needed to be able to see some core information:
  • Library Information
  • Front Page
  • Student Services
These courses can be found on the front page as links (though we are currently reviewing these pages and making them websites and not courses).

Linking with Qualifications
I have created and written a Qualification and Grade Tracker system into Moodle. This system lets us track qualification, units and criteria for BTECs (and City and guild, Alevels and Cache being built currently). I needed a way to add students to qualifications and for teachers to view the qualifications.

In our MIS we have a child course code per qualification and so this meant I could just add our qualifications to child courses. Then I just allowed teachers to view qualifications that were attached to child courses of meta courses they had access to. This gives something like:

Changes we have made to Moodle to make things smoother
In order to work with meta courses more efficiently we have had to create some blocks and scripts that will aid us:

  • Course search allows us to see all parent courses of a child courses.
  • Course search allows us to quickly see all child courses a meta course has.
  • As child courses are hidden, we have created an admin view that will allow us to see hidden courses a student is enrolled on. 
  • We needed to hide such courses as 'Library', 'IT Hints and Tips' and 'How to use Moodle' from appearing in the students profile. 
  • We have had to change some ILP, Emailing and cron scripts to take into consideration our structure. 

Friday, 9 March 2012

Windows 7 to Oracle Query

As explained in my previous post - I wanted to connect our Moodle to an Oracle Database system. Well, its all well and good connecting it on the live and development servers, but, unfortunetly, I code and develop on Windows 7. This therefore means that I will have to develop and test the scripts/code that will query MIS/Oracle on Windows 7.

Connect to Oracle using Windows 7
The following is mainly taken from

Assuming that PHP and Apache are installed on the windows machine, next install the instantclient-basic (32bit) and the SDK for development, make sure it’s the same version as installed on the server. This can be found at http://www.oracle.com/technetwork/topics/winsoft-085727.html .

Extract the basic to C:\instantclient_VERSION

Extract the SDK to the same folder and move the extracted SDK folder up to be in the installclient_VERSION folder.

Edit the Windows PATH environment setting and add C:\instantclient_version (the folder above).

Windows 7: Right click on computer->properties->advanced system setting->environmental  variables. Scroll down to ‘PATH’ click on it and ‘Edit’. Add the folder (each entry is separated by a ;)

Edit the php.ini file (usually in c:\xampp\php\php.ini). Make sure the extension_dir is set to the correct directory. For example:

extension_dir = "\xampp\php\ext"

Also make sure that that folder has the php_oci8.dll library file in it.

Enable the extension with either:

extension=php_oci8_11g.dll
or
extension=php_oci8.dll

This depends on the version in use.

Restart Apache and test using a test connection php file.

If this doesn’t work, it didn’t for me, then copy all of the dll’s from the instantclient folder and put them in xampp/apache/bin

To Query Oracle from a Windows box download sqldeveloper http://download.oracle.com/otn/java/sqldeveloper/sqldeveloper-3.0.04.34.zip. 

This now means I can query and test on my Windows Machine to an Oracle database system. 
 

Centos to Oracle Query

At work our MIS system (Management Information System/Student data) is an Oracle Database Server. Our Moodle (VLE) is the only interface that we have with the students. The course information, enrollment information, student data and attendance all reside on MIS but need to be displayed on Moodle. For a while I set up a system where MIS would do a cron job to create some csv files every night and then the Moodle cron job would process these (a process I had to write from scratch). I decided recently to change this to a direct database query connection (a political change in the organisation also helped). I realised that this also gives us the chance to write to the MIS system from Moodle which is a great place to capture student data. I already capture the students prior attainment (GCSE's and Alevels) which I then use to automatically create target grades. This can now be written to MIS.

Setting up Oracle Access on Centos

In order for Moodle(Centos) to access the MIS database PHP will need to:

·         Connect to the server
·         Connect to the oracle sql server
·         Query the correct database
·         Output the results

This will require PHP to know and understand the Oracle connections and therefore the following changes to the server need to take place:

·         Install the OCI8 extension for PHP
·         Install the Oracle Client Libraries/oracle instant client

I found yum repositories hard to come by for Oracle and so I had to download the correct rpm's from the oracle website: http://www.oracle.com/technetwork/topics/linuxsoft-082809.html . I downloaded:
  • Basic
  • Devel 
I also downloaded the correct versions that matched the version of oracle we had running, in our case, 10.2... 


On the centos box in a terminal I changed to the directory I had downloaded them to and ran (for each):

Rpm –ivh package_name
Where package name is one of the rpm’s and ‘–ivh’ is the install command.

Once these are run the packages are installed as;
Oracle Instant Client library in /usr/lib/oracle/<version>/client/lib
Oracle Instant Client SDK header files in /usr/include/oracle/<version>/client.

This above folder layout is a problem for PHP OCI8 extension installation because the “./configure –with-oci8=shared,instantclient,/path/to/instantclient/lib” will look for the Oracle Instant Client SDK header field in the same library folder i.e. /usr/lib/oracle/<version>/client folder in our case and since the location of SDK header files are different it will raise an error.
To solve this issue, we will create a symbolic link for Oracle Instant Client SDK library path in the Oracle Instant Client library path like

ln -s /usr/include/oracle/<version>/client /usr/lib/oracle/<version>/client/lib/include

This creates the symbolic link to the first part where the shortcut is the second part.

ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT]

Once done, if you view /usr/lib/oracle/<version>/client/lib/include you will see the ‘include’ symbolic link.

Note:
The above step of creating the symbolic link may not work. When executing the below steps an error may occur due to it not finding the correct libraries. In this case I copied all files inside /usr/include/oracle/<version>/client and put them in /usr/lib/oracle/<version>/client/lib.

Installing the PHP OCI8 extension
The following uses;


$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar

Choose default settings by just pressing ‘enter’

$ pear (to see if it works; a list of commands should come up).

Auto install the extension:

$ pecl install oci8

Give it the Oracle home client. ->instantclient, /usr/lib/oracle/<version>/client/lib’ when asked.

I got the error of SDK files not found so I copied all files inside /usr/include/oracle/<version>/client and put them in /use/lib/oracle/<version>/client/lib as states in the note above

Add the extension to the php.ini
Make sure that the extension .so file is in the same directory that php will look for its modules.
In the php .ini file (perhaps in /etc/php.ini) there is a line that reads:

extension_dir = “/usr/lib.php/modules”

The output of the pecl install oci8 will tell you where is stored its oci8.so

In the php.ini, within the ‘Dynamic Extensions’ section add:

extension=oci8.so

Restart Apache and Test
Restart the apache service.
Then navigate to:

·         phpInfo.php
·         Does it have the oracle module installed (oci8 extension)?

To test the connection from php itself I created a very simple script that outputted the results from a table:

$conn = oci_connect(‘USER’, 'PASSWORD', 'IPADDRESS:PORT/SERVICE');

if($conn)
{
                echo "SUCCESS";
                $s = oci_parse($conn, "select * from TABLE/VIEW");
                oci_execute($s);
                while($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS))
                {             
                                print_object($row);
                }
}

This worked and I now have access to an Oracle Database from my PHP server (Moodle.)

Git Part 3 - Using Git

In the previous post I set GIT up with a LIVE, DEV and a local developer machine. In this post I discuss how we use the system.

Note: When connecting to remote from Windows make sure that the private key is loaded ok in pageant.

Tracking other DEV/Remote Branches
On my local host I now have ‘master’ that is a clone of DEV which is a clone of LIVE. However, I had created other branches on DEV and they didn’t come down with the clone of DEV. These steps will track these and other new DEV branches on the local host.

Run GIT gui from the moodle folder
Select ‘Branch’ -> ‘Create’
Select ‘Match Tracking Branch Name’
Select the one you want to track
Click ‘create’

OR GIT bash over the repository:

Look at the local branches (this shows only local branches):
$ git branch

Now look at all of the possible tracking branches:
$ git branch –a

Lets assume that this shows a ‘bugFixes’ branch that is origin/bugFixes that isn’t in our local repository. We could take a look at it (but not work on it) with:
$ git checkout origin/bugFixes

To create a tracking branch and be able to work on it:
$ git checkout –b bugFixes origin/bugFixes

Editing Local
We develop on our local machines and push up to dev to do some final testing before it all goes live. As a side note I personally use Eclipse to do my editing (and, while there is a GIT extension for Eclipse, I don’t use it due to the performance issues when working with PHP). Another developer uses NetBeans.

Firstly I check to see I am on the correct branch, let’s assume I am working on ‘master’. Opening up the GIT gui over the GIT repo it will tell you what branch is checked out. In GIT bash it will tell you which branch you are on when you navigate to the folder where the GIT repo is.

Switching Branches
From the GIT bash:
$ git checkout [branchname]

From the GUI
‘branch’
‘checkout’
Click on the branch name and click checkout

Now I am on the correct branch I can edit the code in Eclipse and test in my browser to localhost. Then I want to commit them to the repo in my ‘master’ branch.

Staging and Committing
Staging the files is adding them to the index, which is telling GIT to add those to the next repo. (You can change files and not commit them). All new files will also need to be ‘added’ to the repo.

GIT Bash:
Show all files that need adding or have been altered.
$ git status

Add new files/stage files:
$ git add [path/filename]

Add all new files/stage all files:
$ git add *

Commit the files with a message:
$ git commit –m”The message to use”

GIT GUI:
Rescan changes
Stage Changes
Add a message in the dialogue box to the right
Click commit

Testing on Dev (Pushing to Remote)
When we are happy with our changes on our localhost we push them to DEV to test. The first thing that is required is to fetch down the branch in question from DEV to make sure that we are up to date.

GIT Bash:
$ git fetch [alias] (usually origin)
$ git merge [branchname]

The first command with fetch the data from origin. The second command will merge the currently checked out branch with the one specified in branchname, in our case, its origin/master. It will merge into the currently checked out branch. Use branch –a to see all available branches. Or, you can use:

$ git pull [alias]

This will do a fetch and a merge together.

GIT GUI:
‘Remote’ -> ‘Fetch From’ -> ‘Origin’
Assuming it’s a success
‘Merge’ -> ‘local Merge’ -> Select Tracking Branch
Click on the branch name and select merge

Assuming that the merge went ok we can now push our changes up to the DEV machine:

Pushing:
On Dev(The remote repo) we need to make sure that the branch we are pushing to isn’t checked out, so checkout another branch, then:

GIT Bash:
$ git push origin master

Git Gui:
Remote’ -> ‘Push’
Then select origin and Push

Then on DEV checkout the master branch and test.

Merging Branches and Conflicts
At some point you will want to merge branches, and, at some point you will get conflicts when merging.

Merging
To merge into the currently checked out branch:

GIT Bash:
$ git merge [branchname]

Git Gui:
‘Merge’->’Local Merge’
Select the branch and click merge

Conflicts
We normally merge our branches on the local windows machines. This is purely out of laziness of either merging using the command line over putty or firing up the VM every time to do it graphically on DEV.

To merge on Windows I use TortoiseGit and then just my normal editor.

Assuming there have been conflicts and there are now conflict markers in the code, I edit the code in Eclipse and then right click on the file in windows explorer, click tortoisegit and then click resolve. This lets me resolve the conflict.

Alternatively on the moodle folder itself I click ‘resolve’. This then brings up a list of files (similar to above) that have conflicts. Rick click on each file and ‘edit conflicts’. The new window that this brings up lets you select the remote or local version to use. Or this window can be used to copy, paste and edit the code to fix. Once edited/resolved click ‘edit’ -> mark as resolved.  Once all files have been resolved the changes can be committed.

Pushing Live
On dev logged in as the ‘git’ user we simply push up to origin using the same as above (git gui or git bash) and it will fire off the hooks. The only difference is that we don’t need to have another branch checked out out on HUB as it doesn’t have a working repository.

Our solution conclusion
So, we have set up:
·         Local Development on Windows
·         Development Centos test server
·         Live server that hosts our website on Centos

We can:
·         Update a live website using GIT
·         Have multiple developers and branches.

There are a few rules that we use:
1.       Each developer commits to dev at least once a day
2.       We merge branches on Dev (mainly out of sheer convenience for us)
3.       We use descriptive and good comments
4.       We use tags to tag some of our commits.

We have branches for:
·         Master
·         Current live (if different from master)
·         Bug fixes (sometime one for each bug fix)
·         New Features (one for each)