Monday, 21 May 2012

Configuring CakePHP for an OSX local install


I am currently learning some of the technologies involved in building web based applications, following ideas from the Software as a Service course.

Currently I'm looking at PHP and the CakePHP frameworks.

Obtain the source

Download and unzip the package from the CakePHP website
Rename to a suitable folder, I have put mine in Sites/ScoutCamp.

Set up Apache

Edit your sites file sudo nano /etc/apache2/users/username.conf
   Options FollowSymlinks
   AllowOverride All
   Order allow,deny
   Allow from all

Restart apache sudo httpd -k restart and open a browser to your shared pages.

Lots of errors and messages

First time I fired up the browser I thought “Oh dear me” or at least something along those lines.
Unlike my trial of Ruby on Rails, there were loads of errors and configuration changes that were required.

I have solved most of the problems, but still have one left to suss out.

Timezone settings

In app/Config/core.php there is a line (it was 232 on my build)

   //date_default_timezone_set('UTC');

Uncomment and set to your timezone - Newcastle is in the same timezone as London.


   date_default_timezone_set('Europe/London');

Unable to write 'cake_dev_en-us' to File cache

The app/tmp folder needs to be writable by the web user.
To find out who this is, add the following bit of code to app/View/Pages/home.ctp


   


On my system, the web user is _www, so change the owner:
   sudo chown -R _www app/tmp/

This cleared up all the errors above the title.

Please change the value of “Security.salt” and “Security.cipherSeed”

In app/Config/core.php find the lines and change to a more suitable value. I used sha1sum to generate the salt, and pasted for the salt. The Seed I just typed a few numbers at random.


   df  | shasum

Setting the database connection

You need to create your database using mysql (there are other options, but that's the one I went with).

Copy database.php.default to database.php and add your user and database details. Note that for some reason, OSX will not work user localhost (and that took a day to track down).

   public $default = array(
      'datasource' => 'Database/Mysql',
      'persistent' => false,
      'host' => '127.0.0.1', // Note change from localhost
      'login' => 'ScoutCamp',
      'password' => 'yourPassword',
      'database' => 'ScoutCamp',
      'prefix' => '',
      'encoding' => 'utf8',
   );

URL Rewriting

This is the only bit I haven't worked out yet, but I want to make a start developing my site and will come back to this.



Saturday, 19 May 2012

Administrating a mySQL database with phpMyAdmin

Just a quick gotcha for OSX, mySQL and phpMyAdmin.

I had successfully set up mySQL and secured the default accounts with passwords. Although shipping a product without passwords may be thought of as a security hole, it is just as bad as shipping with a default password.

Downloaded and installed phpMyAdmin onto the macbook and configured according to instructions. 

Did it work? Did it heck! 

After a while googling for answers, I read through another install guide (although for Lion not Snow Leopard) and found this gem: 

Edit config.inc.php using your favorite editor (I prefer vi) and change$cfg['Servers'][$i]['host'] = ‘localhost’; to $cfg['Servers'][$i]['host'] = ’127.0.0.1′;*Well it sounds stupid because localhost and 127.0.0.1 are same in networking world but phpMyAdmin won’t let you (At least me) log in without this change and keeps throwing error “#2002 Cannot log in to the MySQL server”
This is one of the classic IT gotcha's: two things that are supposed to give the same result don't. I'm almost tempted to see if it is the same on a linux machine, but don't want to get diverted.

Next steps will be to start reading up seriously on PHP MVC frameworks - I'm currently looking at cakePHP.

I really can't remember how we did this stuff before the internet was available, and many of the younger developers probably can't imagine the idea. Perhaps that is why I have a largish collection of computing books going back to VB5 and Access 2 in my bookshelves. Although that could just be because I hate to get rid of books.

Friday, 18 May 2012

Plurals are important, CSS, bookshops and sniffing books

The usual warning applies: I am writing mainly for myself on topics that interest me. I'm not bothered if you're not interested in them.

When I stopped coding last session, I was sitting with an interesting problem to solve: the code to include the header and footer wasn't working.

After spending too much time going line by line through the code, I eventually noticed something painfully obvious: I had misspelt a folder name and missed the trailing 's' from templates.

Sigh.

When I get some spare time, I'm going to have a long hard look to see if there is a good visual editor for css files. A quick look didn't find one, and I'm more interested in getting to doing some coding.

I do find css more than a little frustrating at times, and I should probably go back to first principles and relearn using the latest standards - this would be a good excuse for a trip to a good bookshop, but both my favorites have closed (that's Borders and the Waterstones branch in the MetroCentre).

When I buy a book I like to hold it and I really love the smell of a new book. It's even more important for technical books to have a look at the actual contents before deciding to buy. Once I've decided I want the book, I'll get it then and there - I don't like the delay between ordering and getting a book delivered (even if it works out cheaper).

Most of my inspiration for the html and css was taken from the "CSS: The Missing Manual" book.

Wednesday, 16 May 2012

Learning PHP the hard way

I have been given a challenge: to learn PHP well enough to demonstrate my programming prowess.
Most people will have no idea what PHP is, and probably care less. Not to worry, read on and you will possibly learn more than you are interested about.

Friday, 6 April 2012

Fuel on Rails - the Static Pages

Progress!

screenshot of the contact page
I've made a little progress with the app, but it has felt like mostly taking backward and sideward steps working out the differences between erb and haml.
Static pages for the site have been setup, with a fairly plain gray colour scheme that needs something doing to liven it up a little.

A logo

I do have some ideas for a logo, and may resort to watercolours while I create some designs. I'll postpone deciding on a site colour scheme until I do create a logo: it would be a shame to have to change it more than once.
I'm having a debate with myself about the app title - perhaps "Fuel on the Road" might be better. I haven't decided if I'm winning or losing the debate though.

Signing up victims users

Next step is to get a signup and signin process set up. This is going to need careful thought, for the people like myself who forget passwords (perhaps I should just keep to using one password everywhere).

Fuel: a Ruby on Rails app

After completing the Software as a Service course and the Ruby on Rails tutorial guide I thought it was about time to start putting what I had learned into practice.
I'd spent several days thinking about what I wanted to create, had several complicated ideas then (prompted by filling the car with petrol) decided on an app to monitor fuel consumption.
So far I have created some screen layouts while thinking about what I want the app to achieve.

Initial Screen layouts

Homepage

There will be a homepage with possibly some statistics on the data held, although what I don't quite know what - perhaps something line the total spend on fuel in the past month compared to 12 months ago.

Sign up

A means to register on the site. Every site needs one, unless all the data is to be made public. I didn't seriously think about that at all.

Sign in

A means for a user to recover a forgotten password would be helpful here, it's a feature I certainly have used several times on various websites.

Users homepage

To show details of the vehicles operated by the user. Initial builds may restrict to a single vehicle.
Summaries of the fuel usage to be included here.

Vehicle details

The screen to show the details of fuel used for the vehicle.
A history of the fuel used and some comparisons with 3/6/12 months ago might be interesting.

Fuel upload

The means of adding the fuel used to the database.
Not much point without including this!

What else?

The means to allow another user to upload fuel details might be useful (I know it would for me), and that would need some form of authorisation scheme, along the lines of friend requests on social networking sites.

Top Down Design

I intend to use a combination of Cucumber feature lists and rspec specifications to ensure the app is working the way I intend. This will also help reduce the risk of a change breaking the site without being noticed.
I did notice something interesting: I have written one user script for logging into the system, and I currently have 100% code coverage. Although as I don't have any lines of code in the system, that's quite easy to achieve.

The next steps

They are going to be to create further rspec and cucumber test scripts and implement the user sign in model, followed by adding vehicle details and then adding fuel loads.
I have a fairly comprehensive list of all of the fuel I have put into my current car going back several years since I first bought it (about a week before I started dating my girlfriend).
The source code is currently sitting on a github repository, with the first build pushed to heroku, although I'm not planning on publishing the url for the moment.

Saturday, 17 March 2012

Ruby on Rails

Like many others, I have signed up for the Software as a Service online course hosted on corsera.com, it is my first real look at Behaviour Driven Design and Test Driven Design.

I find it interesting that the IDACS development team I worked with at the turn of the century followed many of the Agile principles, although we didn't have the formal sprints and reviews. We did, however, meet up at least once a month to review our work (and the occasional pint or two was imbibed).

My current project is with coming to grips with the whole SaaS principles.
The first week was learning some basic Ruby (a language I am rapidly coming to love), followed by a trip into Ruby on Rails and this last week with using Cucumber to have test scripts that pass or fail the code that has been written.

I have been having an interesting time trying to get Cucumber to work nicely on my OSX machine (thankfully the SaaS course provided a vm with everything set up ready to rock). Everything in the Ruby world seems to be evolving at a rapid pace, and many of the online instructional videos are a little out of date.

To get Cucumber to run on my machine, I found (after much perusing and changing keywords in searches) that the following seems to work:

In the Gemfile, add the following code:
group :test do
  gem 'rspec', '>=2.5.0'
  gem 'capybara'
  gem 'cucumber','>=1.1.4'
  gem 'cucumber-rails','>=1.3.0'
  gem 'database_cleaner'
  gem 'webrat'
end

Adding
gem 'haml-rails'
will also give you the haml templates instead of erb (wish I found that before I set up my current test project).

Run bundle update at the command line, followed by:

rails generate cucumber:install --capybara

This creates the features folder with the appropriate helper addons.
I did spend some time trying to work out where the web_steps.rb file had gone, but it is no longer included as part of the package. Apparently due to people creating steps files that are over detailled and prone to being brittle and breaking with relatively minor changes to the codebase.

Now all I need to do is to start building apps using the tools. One is going to be a blog type facility based on the Railscasts videos, and the other is to make a waiting list management site.