Sunday 30 June 2013

Starting php with Laravel4 : Getting Started

It is been a long time since i last used php. If i remember correctly, I used php around 2 year and 6 months back. Since them am fiddling with RoR and java with struts, hibernate , and scala with play.

It's a reminiscence for me.

Ok, lets start with php5 with laravel.

Setup:
  1. Install apache
    1. create config file
    2. enable rewrite module, if not
 Installing apache and php5

sudo apt-get install apache2 php5

Once, apache2 is installed, move to next step of creating a site.
Here is the template of site look like:

<VirtualHost *:80>
    # Host that will serve this project.
    ServerName app.dev
    # The location of our projects public directory.
    DocumentRoot /path/to/our/public
    # Useful logs for debug.
    CustomLog /path/to/access.log common
    ErrorLog /path/to/error.log
    # Rewrites for pretty URLs, better not to rely on .htaccess.
    <Directory /path/to/our/public>
        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
        </IfModule>
    </Directory>
</VirtualHost>
Edit it to suit laravel project directory. Replace "/path/to/our/public" with the path to public folder inside laravel project dir.
Now, put this site inside /etc/apach2/site-available
Enable site:
a2ensite site_name
 Enable rewrite module
a2enmod rewrite
Reload apache2
sudo service apache2 reload
Restart apache2
sudo service apache2 restart
Now, you may see your site at following destination

http://localhost

 Now,  lets edit /app/routes.php file and add our "hello world" route

Route::get('/hello', function() {
     return 'Hello world!';
});



Point your browser to :  http://localhost/hello

 


happy coding.. ;)
==============================

Issue:
   Routes not working?
   Solution:  Please verify you have 'rewrite' module enable.  If it's enabled then verify you have write permission to laravel project dir and it's subfolder.
If it's still not working, then google is your friend. 


Reference:
  1.  laravel site config: https://github.com/daylerees/laravel-website-configs 
  2. Routes not working? http://stackoverflow.com/questions/12045881/php-laravel-routing-issue

Wednesday 26 June 2013

openSSH, generating passwd file

First generate Group:
On local system:
            mkgroup -l >> ..\etc\group

On system with user organized in domains
            mkgroup -d >> ..\etc\group

And then password:
                On local:
            mkpasswd -l -u username >> ..\etc\passwd
NOTE: the username specified above must be an existing windows login account.
               
                On system with many domains:
            mkpasswd -u smm08030 -d mycorp >> >> ..\etc\group




NOTE:
If your computer sees multiple domains, you may have to specify the domain
name that the user "qhander" is part of to mkpasswd after the -d flag
(i.e., run "mkpasswd -u YourUser -d YourDomain >> /etc/passwd").
You also need to run "mkgroup -d >> /etc/group" (and, apparently,
"mkgroup -d YourDomain >> /etc/group")...  Also, you most likely have
*two* users with the name "qhander": one local to your machine (with a
small user id), and one in the domain (with UID 18544) -- you log in as
the domain one, but your /etc/passwd contains the local one (with the
wrong SID and UID).  Once you update /etc/passwd with your domain user
information, change the name of the local user to something else (e.g.,

"qhander_local").

Tuesday 11 June 2013

When to use try{}Catch{}?

A system that swallows and masks exceptions isn’t a healthy system.

I'll remember this line whenever i need to put try/catch block in my line as a thumb rule . :)