5 Things to Know Before/While You Learn Laravel (and try to put it on Windows Azure)

LARAVEL

Laravel –   a clean and classy framework for PHP web development.

Alert (Article meant for Laravel/OO PHP Framework beginners .. advanced code ninja’s may pass).

So I decided to work on a short project that utilizes the client server model, basically an api that publishes data consumed by mobile apps. I’d gotten my Microsoft Bizspark partnership a couple months ago and I decided to try out their Azure cloud computing infrastructure. Azure for Websites. I have done medium-sized projects with PHP and its honestly my favourite web applications development language. For most simple tasks, I have relied on procedural PHP, used a couple of  simple Object Oriented ORM frameworks for PHP and then the usual CMS culprit – wordpress. But I hadnt tried the tough and nicer PHP frameworks that everyone talks about – the likes of CakePHP (I’d tried cake but gave up) , Zend Framework, CodeIgniter, Symfony and Laravel. This time, I decided I’d shirked my responsibility enough and decided to invest time in learning and implementing at least one of these frameworks – my choice being LARAVEL. And it was successful, ‘Id say – after two days of focus, I had my laravel-based api running very smoothly …. and on windows azure . Getting to understand how the framework runs, installing it wasnt the smoothest of things and this blog post is to share some thoughts on the process.
As a bonus, I also built up my experience using GitHub! Great software.

Here are the top 5 things I learned

1.) Installing Laravel – What is Composer, and PHP Framework Dependencies

Tada!!! – It turns out that Laravel NEEDS some other software (composer) in order to get installed 🙂 . For a developer coming from single dev projects, and happy spaghetti coding, its was a little suprising to see a PHP project needed to be “installed” . Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you. Dependencies are external libraries that a project needs to function.  and is large enough to have several other existing PHP libraries integrated into it. An example of a dependency in PHP projects is Monolog – a PHP library that “sends your logs to files, sockets, inboxes, databases and various web services.” . You integrate it into your project, and BAM, you can keep logs like a professional developer!
So, Laravel has several such dependencies and they have been declared such that composer can easily install them before you can use laravel. After you type the magical composer command line statements, these dependencies are then downloaded to your project in a folder called “vendor”.
More about how to perform Laravel Installation  can be found on the Laravel Installation Guide.
I would say the “installation” process was all about getting that vendor folder into your project. Also note that each Laravel project you start needs to be “installed” as the vendor folder is inside your project and is not global.

After I got my laravel installed, I used this tutorial on building RESTful webservices with Laravel to get up to speed. About a days work and I had decent functionality.

2.) Laravel and URL rewriting

URL rewriting allows your web application to handle well structured urls that both look good and can be easily remembered. For example , consider the link

denvycom.com/addnewusere.php?name=jim 

,
Your application can integrate URL rewritting and handle same request as

denvycom.com/add/user/jim 

.
Way tidier and easier to remember.
Most advanced web applications ,especially those that support RESTful webservices implement several forms of URL rewriting.
However, for your application to support URL rewriting, it needs certain permissions on your webserver . For Apache webserver some settings on the httpd.conf and htaccess file need to be done. For IIS webserver you need to include a web.config file (without any .xml extension) in your web project file.

3.) Do I need composer to run laravel on a shared host ?

Now that we’ve seen its a tedious process to install Laravel on our client machine, there is the worry about deployment on shared hosts where there is very limited access to the server. Afterall, many shared hosts do not let you install applications, so how’s the composer magic going to happen. Luckily, you DONT need to install composer on your shared host. Once you have run composer within your Laravel project and it downloads the vendor folder, you can simply FTP the entire project into your webserver and it works. Since the dependencies do not change (except in a new release of Laravel), you only need to run composer once .

4.) Developing a Laravel Application on Windows Azure

After getting my Laravel application running, next step was deploying it on windows azure. I used Github for windows on my local machine to make my project folder into a repository. Next, I connected the windows azure dashboard to the Github repository for automatic deployment. This means that whenever I make changes on my local PC, I just need  to commit it to the Github repository and it gets to my azure server. Sweet! However, I was still unable to see the default Laravel installation homepage and my api’s were not working. Then I noticed there was a gitignore on the vendor folder and thus Github did NOT sync the vendor folder to my server. The solution was to FTP the vendor folder to the azure server, and finally the home page was running! I did try to remove the gitignore directive on the vendor folder, but my Github for windows app just kept crashing hence the FTP route. Great so far! But my URLs were not returning any content (api/v1/getcontent) . Setting up the web.config file to enable URL rewriting solved that problem  .

5.) A few other things

I noticed the Windows Azure FTP connection  was VERY fast – and that was refreshing compared to my experience with regular shared hosting servers. I also noticed during testing that the MYSQL instance provided with Azure via clearDB failed once (mysql has gone away) meaning developers should take this into consideration when performing database queries . Design your application for retries and graceful degradation when no data is returned.

Ofcourse, I absolutely recommend laravel, and best wishes with your Laravel journeys!

About Vykthur

Mobile and Web App Developer and Researcher. Passionate about learning, teaching, and recently - writing.
This entry was posted in Developer Tips, PHP, Programming and tagged , , , , . Bookmark the permalink.
  • mysterioux

    i totally agree with you on this… i myself is shy when it comes to CMF (Content Management Framework)… but after reading this, i think i will invest quality time to understand laravel as it gives so much promises…nice write up Vic…(I see progress)

  • I share similar feeling with the writer on how PHP project has to be “install”. Laravel is totally new to me and their new release version 5 makes me want to learn the organization of structure