[Catalyst-commits] r14474 - trunk/examples/CatalystAdvent/root/2013

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Mon Dec 2 22:19:25 GMT 2013


Author: jnapiorkowski
Date: 2013-12-02 22:19:25 +0000 (Mon, 02 Dec 2013)
New Revision: 14474

Added:
   trunk/examples/CatalystAdvent/root/2013/18.pod
   trunk/examples/CatalystAdvent/root/2013/19.pod
   trunk/examples/CatalystAdvent/root/2013/20.pod
Modified:
   trunk/examples/CatalystAdvent/root/2013/15.pod
Log:
more articles and some updates

Modified: trunk/examples/CatalystAdvent/root/2013/15.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2013/15.pod	2013-12-02 08:55:53 UTC (rev 14473)
+++ trunk/examples/CatalystAdvent/root/2013/15.pod	2013-12-02 22:19:25 UTC (rev 14474)
@@ -191,13 +191,67 @@
 Since websocket support is new in L<Catalyst> there's not a lot of pretty helpers
 and shortcut methods.  So we need to call L<Protocol::WebSocket> to initiate the
 websocket, and then we create a 'on_read' handler to listen on the socket, and the
-we add to the write queue whatver shows up.
+we add to the write queue whatver shows up.  Lets break it down a bit:
 
+      my ($self, $c) = @_;
+      my $io = $c->req->io_fh;
+      my $hs = Protocol::WebSocket::Handshake::Server
+        ->new_from_psgi($c->req->env);
+
+
 The key to the magic is the L<Catalyst::Request> method C<io_fh>.  This gives you
 low level access to the underlying C<psgix.io> socket, and is also a flag to
 L<Catalyst> so that it never tries to finalize the body (since you are never really
-closing the connection).
+closing the connection).  We then create a handshake server object via
+L<Protocol::WebSocket::Handshake::Server>.  Now, this isnt' a running server, but
+rather the server's side of the Websocket protocol.  Since we are the server, that's
+the one we need (and there's a client side protocol as well, go check out the full
+docs of L<Protocol::WebSocket> for more).  this C<$hs> object parses the information
+coming across the websocket and presents it in a manner that is easy to use in Perl
+code, and it also does the opposite, it takes some Perl data and preps it to send
+across the open websocket.
 
+     $hs->parse($io);
+
+This the the handshake server parsing the start of the socket, which if you looked
+at it would like a lot of HTTP but with a few extra bits to say we'd like to
+upgrade the connection to a websocket (it does this using the documented HTTP/1.1
+Upgrade header, so yes the people that did HTTP 1.1 all those years ago were really
+thinking ahead!)
+
+      my $hd = AnyEvent::Handle->new(fh => $io);
+      $hd->push_write($hs->to_string);
+      $hd->push_write($hs->build_frame(buffer => "Echo Initiated")->to_bytes);
+
+This converts the raw C<$io> socket to socket resembling a bidirection filehandle
+with a clear API we can use to attache read and write events.  We then initiate 
+ther websocket protocol upgrade and send out first frew frames of data.  If you 
+go back to look at the Javascript end of things:
+
+    // Display messages received from the server
+    socket.addEventListener("message", function(event) {
+      message.textContent = "Server Says: " + event.data;
+    });
+
+Here's the message event that happens when those frames are sent across.
+
+The next bit is the code that listens to the read event, which happens when frames
+are pushed across the websocket from the browser to the server:
+
+      $hd->on_read(sub {
+        (my $frame = $hs->build_frame)->append($_[0]->rbuf);
+        while (my $message = $frame->next) {
+          $message = $hs->build_frame(buffer => $message)->to_bytes;
+          $hd->push_write($message);
+        }
+      });
+
+The on_read associates a callback to handle any incoming messages.  We use the
+handshake server to decode the frames and then we turn around and take that
+decoded message and put it right back on the write queue.  So when someone
+sends a message from the browser, we decode it, and send it back across the same
+websocket up the the browser.  Thus completing the echo!
+
 So, that's really it!
 
 =head1 Summary

Added: trunk/examples/CatalystAdvent/root/2013/18.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2013/18.pod	                        (rev 0)
+++ trunk/examples/CatalystAdvent/root/2013/18.pod	2013-12-02 22:19:25 UTC (rev 14474)
@@ -0,0 +1,346 @@
+=head1 A LINUX WEEK IN THE LIFE OF A WINDOWS GUY!
+
+A step by step guide in setting up a complete web-server application development environment utilising GNU/Linux, NGINX, MySQL, PhpMyAdmin, PostGreSQL, pgAdmin III (including php-fpm & Catalyst application Daemon), perlbrew, Perl 5.16.0, CPAN Minus and of course the Catalyst MVC framework.
+
+=head1 OVERVIEW
+
+Having spent a few months getting to grips with Catalyst in an Windows environment and having developed with Perl using Active-State on Windows for many years, I was keen to learn how to develop Catalyst MVC application utilising the power of modern software technologies and best practises, as well as having a chance to expose myself to the latest offerings of Linux. 
+
+I hope this guide enables others to quickly and easily set up a powerful development environment with as little effort and knowledge as possible, so new developers (especially Windows users), can quickly get the benefits of a powerful Perl environment without the daunting task of having to work out how to do it all themselves.
+
+This is part one of a three part series.
+
+=head1 HARDWARE ENVIRONMENT
+
+I was lucky enough to be given an old server from work which used to run our Windows Small Business Server 2003 environment before we upgraded to SBS2011. It's an HP ML350 G3 with dual Xeon 3.06GHZ, 4GB RAM and 3 x 72GB SCSI running in Raid 5. 
+
+I know you can simply use VM software and run any OS in a virtual environment, but my main Windows desktop PC is an old Q6600 quad core, with 4GB of RAM and u320 SCSI (no raid), so it seemed a better choice to run separate hardware which is nearly as powerful as my current desktop environment, plus it would give me a chance to truly see how Linux compared to Windows, especially as I have first hand experience of this machine, though this did limit me to a 32bit version of Linux. 
+
+=head1 CHOOSING A GNU/LINUX DISTRIBUTION
+
+Now I want to point out, I'm not advocating or recommending what Linux you should use, I am hardly in a position to make any such recommendation, but I can explain what Linux I ended up using and how I came to this decision. 
+
+Obviously there are many distributions to choose from, as is the nature of GNU/Linux and the FSF/Open-Source projects, but the obvious choice it seemed, at least for a Windows user and Linux noob who wants a desktop environment, was Ubuntu so that's where I started.
+
+However, this didn't go smoothly at all, I tried the latest version 13.10, which wouldn't work, so I went for 12.04 LTS, but that wouldn't work either, so I then tried Kubuntu 12.04 LTS, which loaded fine, however, after a couple of days using it, I was a little disappointed by the performance, and felt perhaps I should try other versions and do some more research, so I did.
+
+After reading many "This Linux vs That Linux" type forums threads, I decided I would try a few in a VM environment as it seemed there were many desktop GUI's to choose from as well as distribution, so before I dared to wiped my current Kubuntu install, I set up a few in VMPlayer which gave me a chance to play with the current Kubuntu install as well as trial a few different other versions before I would decide which one I felt like replacing Kubuntu with.
+
+I gave Debian 7 XFCE a go, Red Hat Desktop (but having already gotten used to using .deb Debian packages in Kubuntu, I felt lost again, so decided I would stick with a Debian base), I tried Mint Linux XFCE and downloaded Mint KDE and also Lubuntu as a backup just in case. It seems that apparently the KDE environment is known for performing slower than other distributions, and found Debian 7 XFCE to be quite snappy in the VM environment and thought this might be a good choice.
+
+However, once again I hit installation problems on the physical machine, where it black screened and never provided a GUI install, which from the VM install I knew I should get. I decided I would try Lubuntu as it was the lightest in the Ubuntu family and thought at least it should run pretty fast, but that wouldn't load either. Desperate to give an alternative to the KDE desktop a trial on the physical machine, I installed Mint Linux 13 Maya XFCE, which loaded fine, but during the first software update it crashed, and when I rebooted the machine, it hung with just a flashing cursor and appeared as though the install had been totally corrupted by the update manager! 
+
+Agghh!, bit of a nightmare, but it had given me enough of a chance to get a feel for the XFCE desktop, which I quickly decided, I actually preferred KDE after all, even if XFCE performed faster. In a desperate attempt to not be in a situation of having just simply wiped a working install of Kubuntu and wasted several hours only to end up re-loading the original Kubuntu OS, I thought I would try Mint Linux 13 Maya KDE, still a KDE version, but supposedly more refined and I had hoped faster. The installation went fine and I have stuck with Linux Mint KDE and am happy with my choice. It is still a little slow compared to the original Windows SBS 2003 and XFCE Linux, but it certainly makes a Windows guy feel a little more at home.
+
+I did also replace the on-board video with an old PCI 128MB NVIDIA VGA DVI-D card and was impressed how it just worked, with Linux clearly finding and installing what ever new drivers were required, which has improved the VGA stutter I was experiencing considerably. Personally I do feel that Mint Linux KDE runs a little faster than Kubuntu (though this could be related to the VGA card, as I never ran Kubuntu with the 128MB NVIDIA), and I do prefer some of the Mint Linux KDE interface nuances, like having to double click to open a folder as it is more Windowsesque, though the differences seem few and subtle, such as removing the activities button from the panel (task bar).
+
+My brief experience trying various version of Linux has taught me, there are may flavours to choose from, and the right one is simply the one that works for you and you most easily get along with. After all, if this was a true server environment and not also a development desktop workstation, the GUI wouldn't be a deciding factor, however in this particular instance, I have sacrificed some performance for the desktop GUI I prefer.
+
+=head1 DESIRED IMPLEMENTATION GOALS / TECHNOLOGY PLATFORM
+
+Apart from implementing a Linux environment, I had specific technological goals I wanted to achieve so I could redesign my hobby website within a development environment that mimicked the final envisages target platform I had planned on deploying it to. This also gave me a project to work with to aide in learning this new environment and furthering my Catalyst skills.
+
+Here is my chosen platform...
+
+=over 3
+
+=item *
+
+Mint Linux 13 (Maya) LTS KDE i386 32bit - Operating System
+
+=item *
+
+NGINX - Internet Web Server
+
+=item * 
+
+perlbrew - Perl Distribution Management
+
+=item *
+
+Perl 5.16.0 - Perl Programming Language
+
+=item *
+
+CPAN Minus - CPAN Perl Module Install Helper
+
+=item *
+
+Catalyst MVC Framework - Perl MVC Application Development Environment
+
+=item *
+
+MySQL - Database Back-end 
+
+=item *
+
+PhpMyAdmin - Database Administration
+
+=back
+
+However, when discussing databases in the irc.perl.org #catalyst IRC chat, it was recommended that I move away from MySQL and looked at a more standards compliant database, such as PostGreSQL. This incidentally fitted in with my desire to completely overhaul the back-end design with a new DB schema, having completed a 10 month Open University degree course in Relational Databases : Practice & Theory and wanted to implement the knowledge I had acquired, so I added the following to my development environment...
+
+=over 3
+
+=item *
+
+PostGreSQL - Database Back-end 
+
+=item *
+
+pgAdmin III - Database Administration
+
+=back
+
+I would point out that initially I had gone for PhpPgAdmin, but during my initial installs I had a few issues with connection authentication, I then found through Software Manager that there was a PostGreSQL GUI, so being a Windows guy I jumped at the opportunity to use a fully fledged GUI application to manage my new SQL DB environment that I didn't have the first clue about using!
+
+I will now walk you through the various steps I performed to implement my chosen environment. Although you can install things in an alternate order, I have chosen to start with perlbrew and Catalyst plus your Catalyst application as it helps to ensure you set everything up where possible not using the root account at the start before we move on to needing the root password, plus this means the file system is appropriately structured before implementing the NGINX web-server.
+
+I have assumed you are familiar with firing up a bash/shell/terminal (command-prompt) window and executing commands. The syntax I am using is *Ubuntu style (*Linux Mint is based on Ubuntu), so you may need to alter according for your distribution. I am also using KATE for my text editing, which makes things easier for a Windows guy, but you can use what ever text editor you like. I also use the Dolphin file manager, but this again is just my preference to use a GUI where possible.
+
+Remember to save any edited or newly created files!
+
+=head1 INSTALLING PERLBREW
+
+Firstly you need to get Perl running in your local account, which helps to encapsulate your development environment and enables you to switch between Perl installs very easily without risking corruption of the root OS Perl install.           
+
+=over 3
+
+=item *
+
+sudo apt-get install perlbrew
+
+=back
+
+Once perlbrew is installed (requires your root password), you need to initialise it for the current user.
+
+=over 3
+
+=item *
+
+perlbrew init
+
+=back
+
+You will then see a message telling you to place the following line of code at the bottom of your ~/.bash_profile file.
+
+=over 3
+
+=item *
+
+source ~/perl5/perlbrew/etc/bashrc
+
+=back
+
+However I was unable to find this ~/.bash_profile file! I checked the perlbew website and the installation instructions say to add the line to your 'shell rc file', so I did some surfing and found that some call the command-prompt 'shell' while others call it 'bash', and there is a ~/.bashrc file in my home directory! (remember these are hidden files as they start with a period, so ensure you can see hidden files!)
+
+I did some further digging and found posts from others asking the same question regarding what file they should put this line of code in. Some suggested creating a .bash_profile file in your home directory (~/), while others claim only while the desktop GUI is firing up does a .bash_profile file exist, but once logged in, it becomes your .bashrc file, perhaps this is Ubuntu specific?
+
+In the end I decided to place it in my ~/.bashrc file, and it doesn't seem to have caused any issues and perlbew appears to be running fine, so that's where I will leave it until someone tells me otherwise. If anyone knows 100% where this line of code is meant to go, please feel to free to let me know as there is far too much contradictory and confusing documentation out there already, so a definitive answer is very much welcome!
+
+=head1 INSTALLING YOUR LOCAL PERL VERSION
+
+Now that you have perlbrew installed and initialised, you need to install a local version of Perl to use for your development, I decided to go with version 5.16.0, which you install with perlbrew as follows...
+
+=over 3
+
+=item *
+
+perlbrew install perl-5.16.0
+
+=back
+
+This process takes quite a while and you will receive a message to that effect with instructions on how you can monitor the progress using 'tail', simply execute this command in another command-prompt terminal window.
+
+=over 3
+
+=item *
+
+tail -f ~/perl5/perlbrew/build.log
+
+=back
+
+You will be informed when the process is complete and your cursor will re-appear in the initial install window. Simply close the 'tail' window once finished. You then need to ensure the newly installed version of Perl is the active Perl you will be working with using...
+
+=over 3
+
+=item *
+
+perlbrew switch perl-5.16.0
+
+=back
+
+You should now have a local install of Perl running and be ready to install CPAN Minus. It is worth noting that any Perl scripts / modules etc. you create, you should use the following shebang at the top of your scripts.
+
+=over 3
+
+=item *
+
+#!/usr/bin/env perl
+
+=back
+
+=head1 INSTALLING CPAN MINUS
+
+CPAN Minus is a neat tool that enables you to easily install desired Perl modules from the CPAN repository without having to install and manage the entire CPAN kit and caboodle. Using perlbrew install CPAN Minus (cpanm) as follows...
+
+=over 3
+
+=item *
+
+perlbrew install-cpanm
+
+=back
+
+You should receive a message giving you the path cpanm was just installed to.
+
+    cpanm is installed to
+
+        /home/your_user_name/perl5/perlbrew/bin/cpanm
+
+
+=head1 INSTALLING CATALYST
+
+OK, we have the Perl environment set up for your local user account and CPAN Minus installed, so now let's go get Catalyst...
+
+=over 3
+
+=item *
+
+cpanm Catalyst
+
+=back
+
+Again, this install can take a good few minutes, once finished you should get a message similar to this...
+
+      Successfully installed Catalyst-Runtime-5.90051
+      116 distributions installed
+
+Before we can create your skeleton Catalyst application, we need to install the Catalyst::Helper module and dependencies...
+
+=over 3
+
+=item *
+
+cpanm Catalyst::Helper
+
+=back
+
+This install should be fairly quick and will result in a message similar to this...
+
+      Successfully installed Catalyst-Devel-1.39
+      29 distribution installed
+
+Now we can create your skeleton Catalyst application. Firstly you have to decide where you are going to place your new web application. Personally I like to keep all my sites in a directory 'Websites', and then a sub-folder for each site, so I will use this structure for the rest of this guide, but of course you can alter it accordingly. So let's create this folder!
+
+=over 3
+
+=item *
+
+mkdir Websites
+
+=item *
+
+cd Websites
+
+=back
+
+Now we can use the Catalyst helper to create the skeleton application. I have chosen to name my application 'DMO', short for Dance Music Organisation, but of course replace with an appropriate name for your website application.
+
+=over 3
+
+=item *
+
+Catalyst.pl DMO
+
+=back
+
+Remember to follow the instructions once the skeleton application has been created and change to your application directory and run the Makefile script.
+
+=over 3
+
+=item *
+
+cd DMO
+
+=item *
+
+perl Makefile.PL
+
+=back
+
+You can now test that everything has worked so far by firing up the application development server.
+
+=over 3
+
+=item *
+
+perl script/dmo_server.pl
+
+=back
+
+Remember to replace 'dmo', with your application name! Then open up a web-browser and and try your site with the following URL.
+
+=over 3
+
+=item *
+
+http://localhost:3000
+
+=back
+
+If all went well you will see the Catalyst welcome page!
+
+=head1 SUMMARY
+
+We setup a basic server and got a familar modern Perl development enviroment using Perlbrew.  We also installed L<Catalyst> and got to the basic 'Welcome to Catalyst' screen in a running application.
+
+This ends part one of a three part series.  Stay tuned in tomorrow for the next installment!
+
+=head1 DISCLAIMER!
+
+This guide comes without any warranty! It is simply something I have put together over a week trying to get to grips with setting up a new Linux development environment. I apologise if there are errors, and please do not think this guide is adequate to be used in a live production, public facing web-server environment! This is simply meant to be a rough introduction into creating a local development environment using the latest software technologies for Catalyst application development on a GNU/Linux Debian Ubuntu Mint OS.
+
+I welcome all feedback with corrections, omissions or suggestions to any areas covered.
+
+=head1 CREDITS AND ACKNOWLEDGEMENTS
+
+Here are the main sources I used to crib this article together, to whom I am very grateful.
+
+=over 3
+
+=item *
+
+NGINX / MYSQL / PHP5-FPM : http://michael.lustfield.net/nginx/dummies-guide-to-setting-up-nginx
+
+=item *
+
+NGINX / DAEMON : http://blogs.perl.org/users/davewood/2013/01/nginx-fastcgi-vs-starman-erratum.html
+
+=item *
+
+PERLBREW : http://www.perlbrew.pl
+
+=item *
+
+CPANM / CATALYST : irc.perl.org#catalyst
+
+=item *
+
+POSTGRESQL : http://scratching.psybermonkey.net/2009/06/postgresql-how-to-reset-user-name.html
+
+=item *
+
+THE REST : http://www.bing.com - http://www.stackoverflow.com - various other forums, threads, blogs and how-to's.
+
+=back
+
+=head1 SPECIAL ACKNOWLEDGEMENT
+
+I would like to give a special thank-you to the Catalyst community, for without their help none of this would have been possible.
+
+=head1 AUTHOR
+
+Craig Chant <sspl at stepnstomp.co.uk> | IRC : SSPL
+
+=cut

Added: trunk/examples/CatalystAdvent/root/2013/19.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2013/19.pod	                        (rev 0)
+++ trunk/examples/CatalystAdvent/root/2013/19.pod	2013-12-02 22:19:25 UTC (rev 14474)
@@ -0,0 +1,277 @@
+=head1 A LINUX WEEK IN THE LIFE OF A WINDOWS GUY!
+
+A step by step guide in setting up a complete web-server application development environment utilising GNU/Linux, NGINX, MySQL, PhpMyAdmin, PostGreSQL, pgAdmin III (including php-fpm & Catalyst application Daemon), perlbrew, Perl 5.16.0, CPAN Minus and of course the Catalyst MVC framework.
+
+=head1 OVERVIEW
+
+Having spent a few months getting to grips with Catalyst in an Windows environment and having developed with Perl using Active-State on Windows for many years, I was keen to learn how to develop Catalyst MVC application utilising the power of modern software technologies and best practises, as well as having a chance to expose myself to the latest offerings of Linux. 
+
+I hope this guide enables others to quickly and easily set up a powerful development environment with as little effort and knowledge as possible, so new developers (especially Windows users), can quickly get the benefits of a powerful Perl environment without the daunting task of having to work out how to do it all themselves.
+
+This is part two of a three part series.
+
+=head1 How to install Servers and Manage Perl Dependencies
+
+Before we move on to installing and setting up the other applications such as NGINX web-server and databases, we need to install the Catalyst dependencies required for the Daemon service as we will be running NGINX using FastCGI and unix sockets.
+
+=over 3
+
+=item *
+
+cpanm FCGI
+
+=item *
+
+cpanm FCGI::ProcManager
+
+=item *
+
+cpanm Daemon::Control
+
+=back
+
+At this point I should remind you that each time you add a new dependency to your application (as we just did with the two FCGI modules and Daemon Control), you need to edit your Makefile.PL file and add the new dependencies to it.
+
+	requires 'FCGI';  
+	requires 'FCGI::ProcManager';
+	requires 'Daemon::Control';
+
+It should be obvious where to put these lines of code, just stick them with the other 'requires' dependencies already declared in the script.
+
+B<Note> If you want to be sure that you C<Makefile.PL> tracks required dependencies, you may wish to add the dependency to the C<Makefile.PL> first, and then install directly from that via:
+
+    cpanm --installdeps .
+
+As long as '.' is the directory where your C<Makefile.PL> is located, C<cpanm> will inspect it and install any and all missing dependencies.
+
+=head1 INSTALLING NGINX
+
+OK, now we can move on to installing NGINX web-server.
+
+=over 3
+
+=item *
+
+sudo apt-get install nginx-light
+
+=back
+
+You will need to provide your root password. I have chosen to install the light version of NGINX as this is information I gleaned from another web source (see credits), and it works, so if it ain't broke! 
+
+We now need to configure the website for NGINX to run. Some installations such as NGINX and MySQL are installed as root, unlike Catalyst and Perl, perhaps there is a way to install some of the applications without root, but that is a discussion for another advent, once someone has told me how!
+
+Create a new file in the following location... 
+
+=over 3
+
+=item *
+
+/etc/nginx/sites-available/dance-music.org
+
+=back
+
+...choosing a name that represents your site name, for me I chose my hobby site dance-music.org, simply replace it with your domain choice. I will show you how to edit your hosts file at the end so you don't have to have a DNS server or a purchased domain pointing to a public IP, this way you can run the development environment as if the website was live on the Internet.
+
+(You will need root privileges - I do this by creating a new application menu item that uses the command 'kdesudo kate', which opens my text editor (KATE) with a root permissions password request, and then simply pin it to my panel (task bar).
+
+Your file should look something like this...
+
+      server {
+
+	      listen   80; ## listen for ipv4; this line is default and implied
+
+	      # Make site accessible from http://localhost/
+	      server_name dance-music.org;
+
+	      location / {
+		      include fastcgi_params; 
+		      fastcgi_pass unix:/home/your_user_name/Websites/DMO/DMO.socket;
+	      }
+
+	      location /static {
+		  root /home/your_user_name/Websites/DMO/root;
+	      }
+
+      }
+
+Remember to change 'your_user_name' for your user-name and of course the server_name 'dance-music.org' to your domain. The first location passes the URL to your Catalyst application, the second ensures that all files requested from your 'static' folder are served super-fast by NGINX.
+
+You can prove this is working by removing Static::Simple from the Catalyst application module (in this instance it would be ~/Websites/DMO/lib/DMO.pm). However, we still have a little more to do before we have your Catalyst app running with NGINX.
+
+The next thing you need to do is activate this website NGINX configuration file. The way this is done is by creating a symbolic link from the 'sites-available' folder to the 'sites-enabled' folder...
+
+=over 3
+
+=item *
+
+sudo ln -s /etc/nginx/sites-available/dance-music.org /etc/nginx/sites-enabled/dance-music.org
+
+=back
+
+You should now be able to restart NGINX and check it is running without error.
+
+=over 3
+
+=item *
+
+sudo service nginx restart
+
+=item *
+
+sudo service nginx status
+
+=back
+
+You should get a successful message and if you check the log file (/var/log/nginx/error.log), it should be empty!
+
+Now we will create your Daemon service script for the Catalyst application to listen on.
+
+=head1 CREATING A DAEMON SERVICE FOR CATALYST
+
+Firstly you need to create a file for the Daemon script, I called mine 'cat-dmo' - which will be the Daemon file-name you use for managing the service, create it in the following directory...
+
+=over 3
+
+=item *
+
+/etc/init.d/
+
+=back
+
+The file (cat-dmo) should look like something like this...
+
+      #!/usr/bin/env perl
+      use warnings;
+      use strict;
+      use Daemon::Control;
+
+      my $app_home = '/home/your_user_name/Websites/DMO';
+      my $perl     = '/home/your_user_name/perl5/perlbrew/perls/perl-5.16.0/bin/perl';
+      my $program  = $app_home . '/script/dmo_fastcgi.pl';
+      my $name     = 'DMO';
+      my $workers  = 1;
+      my $pid_file = $app_home . '/DMO.pid';
+
+      my $socket   = $app_home . '/DMO.socket';
+
+      Daemon::Control->new({
+	  name        => $name,
+	  lsb_start   => '$nginx',
+	  lsb_stop    => '$nginx',
+	  lsb_sdesc   => $name,
+	  lsb_desc    => $name,
+	  path        => $app_home . '/dmo.fastcgi.initd',
+
+	  user        => 'www-data',
+	  group       => 'www-data',
+	  directory   => $app_home,
+	  program     => "$perl $program --nproc $workers --listen $socket",
+
+	  pid_file    => $pid_file,
+	  stderr_file => $app_home . '/dmo.out',
+	  stdout_file => $app_home . '/dmo.out',
+
+	  fork        => 2,
+      })->run;
+
+Ensure you carefully check each scalar setting at the top and amend accordingly. I took this code from another source (credits below), So I'm sure it could do with some refinement as Perl is currently hard-coded!
+
+It is also important that you chmod this file as executable (755), or as I do it, use Dolphin and the right click 'properties' context-menu option and the 'permissions' tab.
+
+Now let's start the service, create a hosts file entry and check everything is working.
+
+=over 3
+
+=item *
+
+/etc/init.d/cat-dmo start
+/etc/init.d/cat-dmo status
+
+=back
+
+Your Catalyst Daemon should now be running.
+
+=head1 ADDING A HOSTS FILE ENTRY FOR YOUR DOMAIN
+
+Open up the following file with root permissions...
+
+=over 3
+
+=item *
+
+/etc/hosts
+
+=back
+
+Your file should look something like this after adding your website domain entry...
+
+      127.0.0.1		localhost
+      127.0.1.1		dmo # This will be your computer name
+      127.0.0.1		dance-music.org # Add your domain here for the IP 127.0.0.1
+
+Now open up a web-browser and try to navigate to your website.
+
+=over 3
+
+=item *
+
+http://dance-music.org
+
+=back
+
+Your Catalyst welcome page should be displayed.
+
+
+=head1 SUMMARY
+
+You now have your L<Catalyst> application running under FastCGI and Nginx!
+
+This ends part one of a three part series.  Stay tuned in tomorrow for the next installment!
+
+=head1 DISCLAIMER!
+
+This guide comes without any warranty! It is simply something I have put together over a week trying to get to grips with setting up a new Linux development environment. I apologise if there are errors, and please do not think this guide is adequate to be used in a live production, public facing web-server environment! This is simply meant to be a rough introduction into creating a local development environment using the latest software technologies for Catalyst application development on a GNU/Linux Debian Ubuntu Mint OS.
+
+I welcome all feedback with corrections, omissions or suggestions to any areas covered.
+
+=head1 CREDITS AND ACKNOWLEDGEMENTS
+
+Here are the main sources I used to crib this article together, to whom I am very grateful.
+
+=over 3
+
+=item *
+
+NGINX / MYSQL / PHP5-FPM : http://michael.lustfield.net/nginx/dummies-guide-to-setting-up-nginx
+
+=item *
+
+NGINX / DAEMON : http://blogs.perl.org/users/davewood/2013/01/nginx-fastcgi-vs-starman-erratum.html
+
+=item *
+
+PERLBREW : http://www.perlbrew.pl
+
+=item *
+
+CPANM / CATALYST : irc.perl.org#catalyst
+
+=item *
+
+POSTGRESQL : http://scratching.psybermonkey.net/2009/06/postgresql-how-to-reset-user-name.html
+
+=item *
+
+THE REST : http://www.bing.com - http://www.stackoverflow.com - various other forums, threads, blogs and how-to's.
+
+=back
+
+=head1 SPECIAL ACKNOWLEDGEMENT
+
+I would like to give a special thank-you to the Catalyst community, for without their help none of this would have been possible.
+
+=head1 AUTHOR
+
+Craig Chant <sspl at stepnstomp.co.uk> | IRC : SSPL
+
+=cut

Added: trunk/examples/CatalystAdvent/root/2013/20.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2013/20.pod	                        (rev 0)
+++ trunk/examples/CatalystAdvent/root/2013/20.pod	2013-12-02 22:19:25 UTC (rev 14474)
@@ -0,0 +1,326 @@
+=head1 A LINUX WEEK IN THE LIFE OF A WINDOWS GUY!
+
+A step by step guide in setting up a complete web-server application development environment utilising GNU/Linux, NGINX, MySQL, PhpMyAdmin, PostGreSQL, pgAdmin III (including php-fpm & Catalyst application Daemon), perlbrew, Perl 5.16.0, CPAN Minus and of course the Catalyst MVC framework.
+
+=head1 OVERVIEW
+
+Having spent a few months getting to grips with Catalyst in an Windows environment and having developed with Perl using Active-State on Windows for many years, I was keen to learn how to develop Catalyst MVC application utilising the power of modern software technologies and best practises, as well as having a chance to expose myself to the latest offerings of Linux. 
+
+I hope this guide enables others to quickly and easily set up a powerful development environment with as little effort and knowledge as possible, so new developers (especially Windows users), can quickly get the benefits of a powerful Perl environment without the daunting task of having to work out how to do it all themselves.
+
+This is part three of a three part series.
+
+=head1 INSTALLING MYSQL and Postgreslq
+
+To finish off the series lets install MySQL and some additional tools to help us manage it.  We also install Postgresql so that we can explore this alternative open source database.
+
+To install MySQL use the following...
+
+=over 3
+
+=item *
+
+sudo apt-get install mysql-server
+
+=back
+
+You will need to provide your root password to run the sudo command, but you will also be asked to provide a new password for the MySQL root account (twice), do not forget it!
+
+You now need to add some lines of code to the bottom of your file...
+
+=over 3
+
+=item *
+
+/etc/mysql/my.cnf
+
+=back
+
+      default-storage-engine = innodb
+      innodb_buffer_pool_size = 128M
+      innodb_log_file_size = 10M # May need to purge (rm)
+      /var/lib/mysql/ib_logfile*
+      innodb_flush_method = O_DIRECT
+      innodb_file_per_table = 1
+      innodb_flush_log_at_trx_commit = 2
+      innodb_log_buffer_size = 1M
+      innodb_additional_mem_pool_size = 20M
+      # num cpu's/cores x2 is a good base line for
+      innodb_thread_concurrency
+      innodb_thread_concurrency = 8
+      innodb_open_files = 1024
+      ignore-builtin-innodb
+      innodb_file_per_table
+      plugin-load=innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_lock_waits=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so;innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so
+
+This code was taken from another source (see credits), and it wasn't exactly explained why, so I have included it in a cargo-cult fashion and welcome any feedback.
+
+=head1 INSTALLING MYSQL - PHP COMPONENTS
+
+We now need to install php5-mysql, php5-fpm (FastCGI Process Manager) and php-apc (Alternative PHP Cache)
+
+=over 3
+
+=item *
+
+sudo apt-get install php5-mysql
+
+=item *
+
+sudo apt-get install php5-fpm
+
+=item *
+
+sudo apt-get install php-apc
+
+=back
+
+We now need to edit the following file...
+
+=over 3
+
+=item *
+
+/etc/php5/fpm/pool.d/www.conf
+
+=back
+
+The file should look something like this...
+
+    [www]
+    user = www-data
+    group = www-data
+    listen = /var/run/php5-fpm.socket;
+    listen.owner = www-data
+    listen.group = www-data
+    listen.mode = 0666
+    listen.allowed_clients = 127.0.0.1
+    pm = static
+    pm.max_children = 10
+    pm.start_servers = 4
+    pm.min_spare_servers = 2
+    pm.max_spare_servers = 6
+    pm.max_requests = 1000
+    chdir = /
+    php_admin_value[memory_limit] = 32M
+
+... however, I have removed all the comments and left only those settings which are active to make it easier for you to identify what settings have changed. I recommend you leave your file intact and simply make the necessary changes after making a backup copy of your file. There are a lot of other configuration settings available, with comments, which you may want to change at a later date, especially if you plan on developing with PHP as well!
+
+We now need to edit your NGINX website file...
+
+=over 3
+
+=item *
+
+/etc/nginx/sites-available/dance-music.org
+
+=back
+
+Add the following...
+
+	# PhpMyAdmin
+	location /phpmyadmin {
+		root /home/your_user_name/Websites/DMO/root;
+		index index.php;
+	}
+	
+	location ~ \.php$ {
+		root /home/your_user_name/Websites/DMO/root;
+		fastcgi_pass unix:/var/run/php5-fpm.socket;
+		fastcgi_index index.php;
+		include fastcgi_params;
+	}
+
+=head1 INSTALLING PHPMYADMIN
+
+Now we can install PhpMyAdmin and start the php / MySQL services.
+
+=over 3
+
+=item *
+
+sudo apt-get install phpmyadmin
+
+=back
+
+You will be asked to choose your web-server, simply press escape, you do not want to set up PhpMyAdmin for Apache or lighttpd as we are using NGINX! You also need to say <No> to the option of configuring your database.
+
+We now need to create a symbolic link from the PhpMyAdmin install to your development website...
+
+=over 3
+
+=item *
+
+sudo ln -s /usr/share/phpmyadmin/ ~/Websites/DMO/root/phpmyadmin
+
+=back
+
+Now let's restart the services and check everything is working.
+
+=over 3
+
+=item *
+
+sudo service MySQL restart
+
+=item *
+
+sudo service php5-fpm restart
+
+=item *
+
+sudo service nginx restart
+
+=item *
+
+/etc/init.d/cat-dmo restart
+
+=back
+
+Remember you can use stop / start / restart / status against these service and your own Daemon script at anytime, though do not start your Catalyst Daemon using sudo, it must run under your local account for the correct perl install to be used.
+
+Now open a web-browser and try PhpMyAdmin
+
+=over 3
+
+=item *
+
+http://dance-music.org/phpmyadmin/
+
+=back
+
+You should get the PhpMyAdmin log-in page, where you can use the user-name 'root' and the password you chose when it was installed, that you didn't forget!
+
+OK, if all you want is MySQL and PhpMyAdmin, you can now develop your Catalyst application and manage your MySQL back-end database.
+
+If you want to run PostGreSQL as well, continue with these few extra steps.
+
+=head1 INSTALLING POSTGRESQL AND PGADMIN III
+
+For the rest of this guide I will be using the desktop GUI and built-in applications. One reason is because the PostGreSQL website states to install PostGreSQL use the usual 'sudo apt-get' with version 'postgresql-9.3' for Debian packages, but I received an error when I tried this, saying the package doesn't exist? So I decided to give the GUI desktop apps a go and see what the Software Manager had to offer. You will need to use your root password to install the applications.
+
+I used Kickoff (Start Menu) and Software Manager, then in the top corner use the search box and enter postgresql.
+
+You will see in the search results a package for PostGreSQL and when you double click it, it should show Version '9.1+129ubuntu1', click the install button on the right.
+
+Then use the breadcrumb tabs to go back to your 'Search results' and double click the package for pgAdmin3 and click the install button on the right.
+
+Once installed, close the Software Manager, then use Kickoff and the search box at the top of the menu for pgAdmin3, right click the icon and choose 'add to panel', you now have an elephant icon on your panel (task bar) for easy access.
+
+Before you can connect to the PostGreSQL instance, you need to set a password for the default user-name 'postgres', as it is installed without one, but we need to give ourselves access to connect in order to do so.
+
+Open up the following file...
+
+=over 3
+
+=item *
+
+/etc/postgresql/9.1/main/pg_hba.conf
+
+=back
+
+And change the line...
+
+=over 3
+
+=item *
+
+local   all             postgres                                peer
+
+=item *
+
+to
+
+=item *
+
+local   all             postgres                                trust
+
+=back
+
+Then restart the service...
+
+=over 3
+
+=item *
+
+sudo service postgresql restart
+
+=back
+
+Now let's connect with psql and set the password.
+
+=over 3
+
+=item *
+
+psql -U postgres
+
+=item *
+
+ALTER USER postgres with password 'your_password';
+
+=item *
+
+\q
+
+=back
+
+Do not forget this password either! - Ensure you include the semi-colon, you should receive an ALTER success message.
+
+You also need to re-edit the /etc/postgresql/9.1/main/pg_hba.conf file, replacing 'trust' with 'peer' again, and restarting the PostGreSQL service.
+
+Now use your Elephant icon to fire up pgAdmin3, use the 'plug' connection icon, give the connection a name, use 'localhost' for host, and enter the password you just created, click OK, you should now be connected to your PostGreSQL instance with your pgAdmin3 GUI!
+
+=head1 SUMMARY
+
+This guide should help with setting up a fully integrated Catalyst MVC Perl & PHP5 application development environment running on NGINX with a Daemon Control service and all the tools you need to manage your MySQL & PostGreSQL back-end databases. 
+
+I have not tested database connectivity from Catalyst yet, nor provided any guide for setting up users or permission, this is something you will need to learn yourself, as will I!
+
+=head1 DISCLAIMER!
+
+This guide comes without any warranty! It is simply something I have put together over a week trying to get to grips with setting up a new Linux development environment. I apologise if there are errors, and please do not think this guide is adequate to be used in a live production, public facing web-server environment! This is simply meant to be a rough introduction into creating a local development environment using the latest software technologies for Catalyst application development on a GNU/Linux Debian Ubuntu Mint OS.
+
+I welcome all feedback with corrections, omissions or suggestions to any areas covered.
+
+=head1 CREDITS AND ACKNOWLEDGEMENTS
+
+Here are the main sources I used to crib this article together, to whom I am very grateful.
+
+=over 3
+
+=item *
+
+NGINX / MYSQL / PHP5-FPM : http://michael.lustfield.net/nginx/dummies-guide-to-setting-up-nginx
+
+=item *
+
+NGINX / DAEMON : http://blogs.perl.org/users/davewood/2013/01/nginx-fastcgi-vs-starman-erratum.html
+
+=item *
+
+PERLBREW : http://www.perlbrew.pl
+
+=item *
+
+CPANM / CATALYST : irc.perl.org#catalyst
+
+=item *
+
+POSTGRESQL : http://scratching.psybermonkey.net/2009/06/postgresql-how-to-reset-user-name.html
+
+=item *
+
+THE REST : http://www.bing.com - http://www.stackoverflow.com - various other forums, threads, blogs and how-to's.
+
+=back
+
+=head1 SPECIAL ACKNOWLEDGEMENT
+
+I would like to give a special thank-you to the Catalyst community, for without their help none of this would have been possible.
+
+=head1 AUTHOR
+
+Craig Chant <sspl at stepnstomp.co.uk> | IRC : SSPL
+
+=cut




More information about the Catalyst-commits mailing list