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

No comments:

Post a Comment