How To Get Started With Laravel Framework

Laravel Framework is a popular PHP framework that is taking the web development community by storm. Heck, I never thought I would ever use PHP until I started using Laravel. So what made me give it a shot? I will make this short; we had to take over a laravel project from another guy at work! After a couple of months of using it, I was so impressed that I started using it on my major project that I initially wanted to write in Python. Yeah, so you can take me up on that because it is pretty damn cool. Anyway, in this post, I will just touch on a few things to prepare for further posts where we will create a simple web application using the awesome Laravel framework.

how to get started with laravel framework

Setting Up Your Environment for Laravel Framework

There are several options when it comes to serving applications. You could use remote servers to host your web application as you develop it or setup your own virtual host – you can do that by following my simple tutorial here.

After you have setup your development environment – I am assuming you have PHP, MySQL and Apache installed on your machine or use a remote option. Again, if you are using a local setup, the posts I will be creating will be a little easier to follow along.

Install Composer and Download Laravel Framework

Composer is a dependency manager for PHP heavily inspired by node’s npm and ruby’s bundler. You can install it by following the following instructions on your terminal (Linux users) (The instructions below will install composer globally – I prefer this because then I can invoke composer without php):

On Your Terminal (Ctrl+ALT+T), type and press enter:

For users using other platforms, please click here for instructions on how to install composer on your machine.

Download Laravel and Extract it.

You have a couple of ways to install Laravel.

1) You can use composer by entering this command on your terminal:

This command will download and install a fresh copy of Laravel in a new your-project-name folder within your current directory.

The other alternative – the way I do it really, is to download a zip file from github and extract it myself into a folder I created a head of time. After the extraction is complete, change to that folder and run:

This will download and install laravel’s dependencies.

Permissions & Stuff

After installing Laravel, you may need to grant the web server write permissions to the app/storage directories. Here are the commands you can use to do that on your terminal (you will be doing this to your storage directory):

First command changes owner and group while the second command adds attributes which will keep new files and directories within cake having the same group permissions

If you setup your own virtual host after following my tutorial that I mentioned in the beginning of this post, you can simply access your web application (Laravel) by visiting your site on your browser. That would be something like http://mysite.local – which should show you a welcome screen.

If you do not see a welcome screen and instead see an error page saying it does not exist, check to make sure you have given the web server the permissions it needs (Read + Write) and try again – it should work.

Explore Laravel’s Directory Structure

Laravel’s directory structure is not difficult to understand. Go through the folders and note down what you see. You can even visit the Laravel documentation to familiarize yourself with the framework – there is really no better place than that.

If this is your first time using PHP, you might want to consider going through some PHP tutorials online – you can look at codecademy or other places for that. Oh, I just remembered that I have an introductory PHP tutorial right here.

Again, I assume you know PHP at this point.

Generate Unique Key for your Laravel Application

In your new project, if you look inside the app folder then inside the config> folder, you will see a file called app.php. Inside that file will be an array with key pair values. You need to generate a value for the key property that you see in there. So, to do that, open your terminal and type:

That is all you need for that. Now if you open your app.php file again, you will notice that there is a random value that was generated for your application. Sweet!

Finally, configure your database connection stuff

Assuming you have MySQL installed and you have created a database for your project, open from within that config folder, a file called database.php and select your choice – I use mySQL in my current projects with PhpMyAdmin tool. If you select to go with MySQL, provide your database, username and password. Save and you are done!

I will stop here so that we can pick up from where we left in our next post. I will show you how to create a simple web application using this Laravel Framework so you can see it in action.

Thank you for stopping by and I hope this post peeked your interest and you are ready to try Laravel Framework. If you cannot wait to dive in, check out the very well-written documentation here.

If you have any questions, please ask them in the comments section or shoot me an email through the contact page! Oh, you can even call me through the phone on the right sidebar.

I almost forgot: here is a laravel cheat sheet that you MUST have for reference!

Please consider sharing this post with your friends if you found it helpful to you! Thanks again and I hope to see you soon for more exciting stuff!

Written By Elisha Chirchir

Elisha Chirchir is a software developer. He is also the founder of Simple Developer and co-founder of Instinctive Software Solutions. On any given day, he works on both Android and Web Development. During his 'free time', he offers training to those interested in learning how to code in php, java, python, javaScript etc. You can easily find him on StackOverflow Android chatroom or on Twitter @Eenvincible

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.