Installing Laravel4 in Mac OSX with MAMP

Standard

Re-cap:
In the past and first tutorial of this series we learned how to create a virtual host with MAMP. In this second tutorial, we will install laravel4 PHP framework and will go another step toward developing a full laravel4 application series.

Precautions:

  • Make sure your installed PHP version is greater or equal to 5.3.7
  • Also make sure the MCrypt PHP extension is enabled
  • For pretty URL the mod_rewrite module is enabled on Apache

1. Install Composer Globally:

The following command will just check a few PHP settings and then download composer.phar

$ curl -sS https://getcomposer.org/installer | php

You can run these commands to easily access composer from anywhere on your system

$ sudo mv composer.phar /usr/local/bin/composer

2. Create a laravel project named “thisdayinbangladesh” inside our MAMP’s “htdocs” directory:

Going inside the “htdocs” directory

$ cd /Applications/MAMP/htdocs

Creating the project there

$ composer create-project laravel/laravel thisdayinbangladesh --prefer-dist

3. A small permission issue:

Lets enter into our project directory

$ cd thisdayinbangladesh/

Change the permission of the storage folder to writable

$ sudo chmod -R 0777 app/storage/

4. Basic Configuration:

Update line number 29 of the “app/config/app.php” file to

$ 'url' => 'http://thisdayinbangladesh.dev/',

and line 42 to

$ 'timezone' => 'Asia/Dhaka',

5. Database configuration:
Though configuring database is not necessary to have a first run but lets complete this step as we will not do any editing on the config files later.


'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'thisdayinbangladesh',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
 ),

6. Lets have a test run:

Open the URL of your laravel application as we created earlier using virtual host; on the browser. That is http://thisdayinbangladesh.dev/
You should arrive!

Get Google News as JSON by Parsing rss feed

Standard

Google-News-Nuhil
As you know already that, Google News search API has been deprecated few years ago. Still developers need to have Google news as an usable format like JSON for different purpose & development platforms.

Google still provides the news service but in rss format. So, we can have those data for using just by parsing and reformatting them. I wrote a very small php class which will first search  news on Google by specific keywords and load the XML. Then it will parse the XML carefully to dissect parts of news & finally will provide a formatted JSON data set.

As of JSON, all knows that how universal this data format is to implement on several software development platforms. Hope this tiny class help some one 🙂

The class file:

<?php
 **
 * Google-News feed parser and JSON provider Class
 *
 * @package None
 * @author Nuhil Mehdy <nuhil@nuhil.net>
 */
class GoogleNews {

    public $searchQuery = 'Good News';

    public function __construct ($searchQuery) {
            if(!empty($searchQuery)) {
                    $this->searchQuery = $searchQuery;
            }

            $this->numberOfNews = 5;
    }

    public function __toString() {
            return $this->getNews();
    }

    public function setSearchQuery($searchQuery) {
            if(!empty($searchQuery)) {
                    $this->searchQuery = $searchQuery;
            }
    }

    public function setNumberOfNews ($numberOfNews) {
            if(!empty($numberOfNews)) {
                    $this->numberOfNews = (int) $numberOfNews;
            }
    }

    public function getNews () {
            return $this->processNews();
    }

    private function processNews() {
            $loadXml = simplexml_load_file(urlencode('http://news.google.com/news?q='.$this->searchQuery.'&num='.$this->numberOfNews.'&output=rss'));

            $news = array();

            $i = 0;
            foreach ($loadXml->channel->item as $item)
            {
                preg_match('@src="([^"]+)"@', $item->description, $match);
                $newsSections = explode('</pre>
', $item->description);

 $news[$i]['title'] = (string) $item->title;
 $news[$i]['image'] = $match[1];
 $news[$i]['link'] = (string) $item->link;
 $news[$i]['news_source'] = strip_tags($newsSections[1]);
 $news[$i]['short_story'] = strip_tags($newsSections[2]);

 $i++;
 }

 $result = array('news' => $news, 'status' => '200', 'message' => 'OK');

 return json_encode($result);
 }

}
?>

Example usage:

<?php
include('news.php'); 
$news = new GoogleNews(); 
$news->setSearchQuery('Bangladesh');
$news->setNumberOfNews('10');
echo $news->getNews();
?>

You will find this source code on github also. Feel free to use and or fork.

Setup a custom domain for your appfog application

Standard

www
On a previous post we saw how to deploy a PHP application in appfog using appfog CLI. appfog gives you a domain for your newly created aaplication which is not so beautiful at all. Such as (http://YOUR-APP-NAME.aws.af.cm/) or something like that according to your choosen region/infrastructure while creating the app.

Today we will point a godaddy domain to a appfog application. For this you will have to first go to your app under your appfog account. Then select the Domain Names from left navigation. Here you can see the domain name already assigned to your application and few more blank fields for domain names to be added.

Also you can see the DNS instructions for custom domains” below that form. Here it will show what “A” record and CNAME record you should add on your own domain control panel.

Screen Shot 2013-02-14 at 7.24.46 PM

I have added http://www.nuhil.net as the second domain name. Then I added a “A” record and a “CNAME” record under my godaddy domain management panel using the DNS manager.

godaddyIf you wait few hours after changing the records in your domain end, then this will point the full domain for example http://www.nuhil.net to the appfog application but if you type the naked one like, http://nuhil.net then it will show a 404 not found appfog message. For the solution I did a forwarding under my godaddy account using the “forwarding domain tool” to forward the naked domain to full domain.

Screen Shot 2013-02-14 at 7.39.38 PM

This forwarding may cause a change on your “A” record you just created manually according to appfog’s suggestion. But no need to worry. The “CNAME” can take care of all the rest.

Deploy Application in Amazon Beanstalk inside free EC2 Instance with RDS

Standard

aws-beanstalk
Amazon has virtual cloud server (instance) and many other web services. They offers a 1 year free micro tier to be used by anyone who own an international currency Debit/Credit card like Payoneer debit master card. There are several services included with the free tier that can be used along with the EC2 instance without any extra charge. Beanstalk deployment framework is one of the free services you are eligible for.

For no additional charge, AWS Elastic Beanstalk allows you quickly and easily deploy your Java, PHP, Python, Ruby, and .NET applications using many of the services offered in the free usage tier.” -Amazon. Beanstalk is similar to other deployment frameworks like appfog, pagodabox etc. Moreover if you use Beanstalk then you will still have access to your virtual cloud server in which the deployment will be running. “Behind the scenes, Elastic Beanstalk handles the provisioning of a load balancer and Amazon EC2 resources.” -Amazon. Thats why I prefere Beanstalk than others who are in my knowledge.

In this post we will cover the steps of creating an account for Amazon EC2 free tier, configuring local machine for Amazon CLI tools, creating a sample app locally, creating an elastic beanstalk php environment, deploying a sample php app, creating an Amazon RDS and connecting to it via PHP and mySQL workbench, git version controlling of the deployed app, setting up a custom classified domain to our newly deployed app environment. Tired to read these ? I am sure you will feel best after having this journey 🙂

1. Create an account for Amazon web service from here . You can see the service list that will be included with your free tier for your further using. Note that, the sign up process is simple and you will be asked to provide your card detail on the second step and finally you will have to verify your phone number. You will have to put your phone number then to click “call now” button then a 4 digit pin number will be appeared on your browser. After that an automated call will reach your phone. You should either speak the pin number slowly or input the pin number in your mobile keypad if it supports touchtone functionality. I always spoke the pin after listening the bot girl’s voice 🙂 Continue reading

Deploy apps on pagodabox with git version controlling

Standard

In the very last two posts we saw how to deploy apps in appfog. Today we will see how to deploy such apps in pagodabox. pagodabox is another deployment platform/framework like appfog. I found something good feature here such as you can have a free SSL certificate for your instance under the free scheme and you can see all your git commits under you app’s dashboard and simply deploy any version from your commit history just by clicking a button. Their punch line is “An Object Oriented Hosting Framework”

To start deploying your app on the cloud, just sign up in pagodabox obviously without any requirement of valid payment method as like appfog 🙂

Step A: You need to install the pagodabox command line tool just like you did for appfog according to the last post. For this, type the following command on Mac terminal:

sudo gem install pagoda

Ruby and RubyGems come pre-installed on Mac OSX. As long as you are running v10.6 or later. For windows or any other issue you can check here. Also you should add an SSH key of your local machine to your pagodabox account. Just follow this simple process. Continue reading

How to host/deploy a PHP app from local machine to appfog

Standard

On the previous post we deployed a wordpress site along with a mySQL service by appfog’s built-in installation process in a very fast way. In this post we will describe the process of deploying again a wordpress site but from our local machine like as our own custom PHP app.

Step A: Sign up in appfog and it will show no app under your account. Just leave the browser. Nothing to to do there now. We will use appfog command line tool to both create and upload the files to appfog.
For that, enter the following command in your Mac OSX terminal

gem install af

After successful installation of “af” you can write the following command and provide your appfog account detail to login to the service.

af login

Note: “af” requires Ruby 1.8.7 or newer. You should Ruby installed already in your Mac 10.6+ . If any problem occurs or you are using Windows then follow this link to resolve. Continue reading