Quickstart: Laravel 4

Your mileage may vary with this particular quickstart depending on your host. I am using hostmonster, a fairly poor choice for current web development trends, but we aren’t exactly creating the next InstaBookSpaceGramChat here.

1. Download Composer

In SSH, navigate to  the root of your project folder and run the following to download Composer.

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

2. Create your Laravel project

Before you go all copy-pasta crazy down below, make sure to replace your-project-name with whatever it is you are making.

By default, the command to install Laravel project is:

composer create-project laravel/laravel your-project-name --prefer-dist

For my particular environment, I needed to add php and change composer to composer.phar. Again, this is more than likely due to my shared server environment. The updated command looked something like this:

php composer.phar create-project laravel/laravel your-project-name --prefer-dist

Update 09/10/14: For Dreamhost servers, I ended up installing Composer in ~/bin so my Composer command ended up being php ~/bin/composer.phar. I solved this mess by creating an alias via alias composer='php ~/bin/composer.phar'. This allowed me to run composer all over the place.

3. Make /public directory work properly

At this point, your Laravel app is ready to go. Unfortunately, by default, everything needs to be accessed via /public. So if http://www.instabookspacegramchat.com is pointing to your new Laravel project directory, you would need to go to http://www.instabookspacegramchat.com/public to see your new project at work.

This, to me, is a horrible flaw with the base Laravel install. To get around it you can either a) set your document root to /public for your domain or b) create an .htaccess file in your project root.

For option b, I used the following in my newly created .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

4. Create a view and route

If you open up your /app/routes.php file, you’ll see that your default route is being handled by the hello view. The hello view lives in /app/views as hello.php.

To create a view and route to call your very own, you’ll need to go back to your /app/routes.php file and add the following:

Route::get('/foo', function()
{
return View::make('foo');
});

The parameter of View::make() refers to the view. In our case, foo refers to /app/views/foo.php

Keep in mind this is one of the more basic methods of creating a route.  In your later Laravel travels, your route-fu will be much stronger.

Next we need to make our foo view. Save & close your routes.php and create /app/views/foo.php. Throw whatever HTML you want to in this new view and hop on over to http://[url]/foo.

5. Next Steps

  • Creating Blade templates
  • Advanced routing
  • Creating controllers
  • Creating models

Leave a Reply

Your email address will not be published. Required fields are marked *